Skip to content

Commit d444188

Browse files
committed
linted updates for flake8
1 parent 4fd4aa3 commit d444188

File tree

5 files changed

+58
-74
lines changed

5 files changed

+58
-74
lines changed

pandas/tests/indexes/multi/test_analytics.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
import pandas as pd
55
import pandas.util.testing as tm
66
import pytest
7-
from pandas import (DatetimeIndex, Float64Index, Index, Int64Index, MultiIndex,
8-
PeriodIndex, TimedeltaIndex, UInt64Index, date_range,
7+
from pandas import (DatetimeIndex, Index, MultiIndex,
8+
PeriodIndex, TimedeltaIndex, date_range,
99
period_range)
1010
from pandas.compat import lrange, range
1111
from pandas.core.dtypes.dtypes import CategoricalDtype
12-
from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin
13-
from pandas.util.testing import assert_copy
1412

1513

1614
def test_shift(idx):
@@ -20,11 +18,6 @@ def test_shift(idx):
2018
pytest.raises(NotImplementedError, idx.shift, 1, 2)
2119

2220

23-
24-
def check_level_names(index, names):
25-
assert [level.name for level in index.levels] == list(names)
26-
27-
2821
def test_insert(idx):
2922
# key contained in all levels
3023
new_index = idx.insert(0, ('bar', 'two'))
@@ -385,6 +378,7 @@ def test_map_dictlike(idx, mapper):
385378
result = idx.map(mapper(expected, idx))
386379
tm.assert_index_equal(result, expected)
387380

381+
388382
@pytest.mark.parametrize('func', [
389383
np.exp, np.exp2, np.expm1, np.log, np.log2, np.log10,
390384
np.log1p, np.sqrt, np.sin, np.cos, np.tan, np.arcsin,
@@ -400,13 +394,13 @@ def test_numpy_ufuncs(func):
400394
# for unicode input depending on numpy version
401395

402396
# copy and paste from idx fixture as pytest doesn't support
403-
# parameters and fixtures at the same time.
397+
# parameters and fixtures at the same time.
404398
major_axis = Index(['foo', 'bar', 'baz', 'qux'])
405399
minor_axis = Index(['one', 'two'])
406400
major_labels = np.array([0, 0, 1, 2, 3, 3])
407401
minor_labels = np.array([0, 1, 0, 1, 0, 1])
408402
index_names = ['first', 'second']
409-
403+
410404
idx = MultiIndex(
411405
levels=[major_axis, minor_axis],
412406
labels=[major_labels, minor_labels],
@@ -425,13 +419,13 @@ def test_numpy_ufuncs(func):
425419
def test_numpy_type_funcs(func):
426420
# for func in [np.isfinite, np.isinf, np.isnan, np.signbit]:
427421
# copy and paste from idx fixture as pytest doesn't support
428-
# parameters and fixtures at the same time.
422+
# parameters and fixtures at the same time.
429423
major_axis = Index(['foo', 'bar', 'baz', 'qux'])
430424
minor_axis = Index(['one', 'two'])
431425
major_labels = np.array([0, 0, 1, 2, 3, 3])
432426
minor_labels = np.array([0, 1, 0, 1, 0, 1])
433427
index_names = ['first', 'second']
434-
428+
435429
idx = MultiIndex(
436430
levels=[major_axis, minor_axis],
437431
labels=[major_labels, minor_labels],
+1-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
import numpy as np
4-
import pandas as pd
54
import pandas.util.testing as tm
6-
import pytest
7-
from pandas import (DatetimeIndex, Float64Index, Index, Int64Index, MultiIndex,
8-
PeriodIndex, TimedeltaIndex, UInt64Index, date_range,
9-
period_range)
10-
from pandas.compat import lrange, range
11-
from pandas.core.dtypes.dtypes import CategoricalDtype
12-
from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin
135
from pandas.util.testing import assert_copy
146

157

@@ -18,7 +10,7 @@ def test_astype(idx):
1810
actual = idx.astype('O')
1911
assert_copy(actual.levels, expected.levels)
2012
assert_copy(actual.labels, expected.labels)
21-
check_level_names(actual, expected.names)
13+
assert [level.name for level in actual.levels] == list(expected.names)
2214

2315
with tm.assert_raises_regex(TypeError, "^Setting.*dtype.*object"):
2416
idx.astype(np.dtype(int))

pandas/tests/indexes/multi/test_constructor.py

+26-26
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,16 @@ def test_from_arrays_empty():
234234
tm.assert_index_equal(result, expected)
235235

236236

237-
@pytest.mark.parametrize('invalid_array',[
238-
pytest.param(1),
239-
pytest.param([1]),
240-
pytest.param([1, 2]),
241-
pytest.param([[1], 2]),
242-
pytest.param('a'),
243-
pytest.param(['a']),
244-
pytest.param(['a', 'b']),
245-
pytest.param([['a'], 'b']),
246-
]
237+
@pytest.mark.parametrize('invalid_array', [
238+
pytest.param(1),
239+
pytest.param([1]),
240+
pytest.param([1, 2]),
241+
pytest.param([[1], 2]),
242+
pytest.param('a'),
243+
pytest.param(['a']),
244+
pytest.param(['a', 'b']),
245+
pytest.param([['a'], 'b']),
246+
]
247247
)
248248
def test_from_arrays_invalid_input(invalid_array):
249249
invalid_inputs = [1, [1], [1, 2], [[1], 2],
@@ -252,11 +252,11 @@ def test_from_arrays_invalid_input(invalid_array):
252252
pytest.raises(TypeError, MultiIndex.from_arrays, arrays=i)
253253

254254

255-
@pytest.mark.parametrize('idx1, idx2',[
256-
pytest.param([1, 2, 3], ['a', 'b']),
257-
pytest.param([], ['a', 'b']),
258-
pytest.param([1, 2, 3], [])
259-
]
255+
@pytest.mark.parametrize('idx1, idx2', [
256+
pytest.param([1, 2, 3], ['a', 'b']),
257+
pytest.param([], ['a', 'b']),
258+
pytest.param([1, 2, 3], [])
259+
]
260260
)
261261
def test_from_arrays_different_lengths(idx1, idx2):
262262
# see gh-13599
@@ -321,16 +321,16 @@ def test_from_product_empty_one_level():
321321
tm.assert_index_equal(result.levels[0], expected)
322322

323323

324-
@pytest.mark.parametrize('first, second',[
325-
([],[]),
324+
@pytest.mark.parametrize('first, second', [
325+
([], []),
326326
(['foo', 'bar', 'baz'], []),
327327
([], ['a', 'b', 'c']),
328328
])
329329
def test_from_product_empty_two_levels(first, second):
330330
names = ['A', 'B']
331331
result = MultiIndex.from_product([first, second], names=names)
332332
expected = MultiIndex(levels=[first, second],
333-
labels=[[], []], names=names)
333+
labels=[[], []], names=names)
334334
tm.assert_index_equal(result, expected)
335335

336336

@@ -341,7 +341,7 @@ def test_from_product_empty_three_levels(N):
341341
lvl2 = lrange(N)
342342
result = MultiIndex.from_product([[], lvl2, []], names=names)
343343
expected = MultiIndex(levels=[[], lvl2, []],
344-
labels=[[], [], []], names=names)
344+
labels=[[], [], []], names=names)
345345
tm.assert_index_equal(result, expected)
346346

347347

@@ -370,12 +370,12 @@ def test_from_product_datetimeindex():
370370
def test_from_product_index_series_categorical(ordered, f):
371371
# GH13743
372372
first = ['foo', 'bar']
373-
373+
374374
idx = pd.CategoricalIndex(list("abcaab"), categories=list("bac"),
375-
ordered=ordered)
375+
ordered=ordered)
376376
expected = pd.CategoricalIndex(list("abcaab") + list("abcaab"),
377-
categories=list("bac"),
378-
ordered=ordered)
377+
categories=list("bac"),
378+
ordered=ordered)
379379

380380
result = pd.MultiIndex.from_product([first, f(idx)])
381381
tm.assert_index_equal(result.get_level_values(1), expected)
@@ -437,13 +437,13 @@ def test_create_index_existing_name(idx):
437437
result = pd.Index(index, names=['A', 'B'])
438438
expected = Index(
439439
Index([
440-
('foo', 'one'), ('foo', 'two'),
441-
('bar', 'one'), ('baz', 'two'),
440+
('foo', 'one'), ('foo', 'two'),
441+
('bar', 'one'), ('baz', 'two'),
442442
('qux', 'one'), ('qux', 'two')],
443443
dtype='object'
444444
),
445445
names=['A', 'B']
446-
)
446+
)
447447
tm.assert_index_equal(result, expected)
448448

449449

pandas/tests/indexes/multi/test_copy.py

+13-15
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
from copy import copy, deepcopy
44

5-
import numpy as np
65
import pandas.util.testing as tm
76
import pytest
8-
from pandas import (CategoricalIndex, IntervalIndex, MultiIndex, PeriodIndex,
9-
RangeIndex, Series, compat)
10-
from pandas.core.indexes.frozen import FrozenList
7+
from pandas import MultiIndex
8+
119

1210
def assert_multiindex_copied(copy, original):
1311
# Levels should be (at least, shallow copied)
@@ -45,10 +43,10 @@ def test_view(idx):
4543

4644
@pytest.mark.parametrize('func', [copy, deepcopy])
4745
def test_copy_and_deepcopy(func):
48-
46+
4947
idx = MultiIndex(
50-
levels=[['foo', 'bar'],['fizz', 'buzz']],
51-
labels=[[0, 0, 0, 1],[0, 0, 1, 1]],
48+
levels=[['foo', 'bar'], ['fizz', 'buzz']],
49+
labels=[[0, 0, 0, 1], [0, 0, 1, 1]],
5250
names=['first', 'second']
5351
)
5452
idx_copy = func(idx)
@@ -59,29 +57,29 @@ def test_copy_and_deepcopy(func):
5957
@pytest.mark.parametrize('deep', [True, False])
6058
def test_copy_method(deep):
6159
idx = MultiIndex(
62-
levels=[['foo', 'bar'],['fizz', 'buzz']],
63-
labels=[[0, 0, 0, 1],[0, 0, 1, 1]],
60+
levels=[['foo', 'bar'], ['fizz', 'buzz']],
61+
labels=[[0, 0, 0, 1], [0, 0, 1, 1]],
6462
names=['first', 'second']
65-
)
63+
)
6664
idx_copy = idx.copy(deep=deep)
6765
assert idx_copy.equals(idx)
6866

6967

7068
# TODO: dtypes?
7169
@pytest.mark.parametrize('deep', [True, False])
72-
@pytest.mark.parametrize('kwarg, value',[
70+
@pytest.mark.parametrize('kwarg, value', [
7371
('names', ['thrid', 'fourth']),
74-
('levels', [['foo2', 'bar2'],['fizz2', 'buzz2']]),
72+
('levels', [['foo2', 'bar2'], ['fizz2', 'buzz2']]),
7573
('labels', [[1, 0, 0, 0], [1, 1, 0, 0]])
7674
])
7775
def test_copy_method_kwargs(deep, kwarg, value):
7876
# gh-12309: Check that the "name" argument as well other kwargs
7977
idx = MultiIndex(
80-
levels=[['foo', 'bar'],['fizz', 'buzz']],
81-
labels=[[0, 0, 0, 1],[0, 0, 1, 1]],
78+
levels=[['foo', 'bar'], ['fizz', 'buzz']],
79+
labels=[[0, 0, 0, 1], [0, 0, 1, 1]],
8280
names=['first', 'second']
8381
)
84-
82+
8583
idx_copy = idx.copy(**{kwarg: value}, deep=deep)
8684
if kwarg == 'names':
8785
getattr(idx_copy, kwarg) == value

pandas/tests/indexes/multi/test_get_set.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111

1212
def assert_matching(actual, expected, check_dtype=False):
13-
# avoid specifying internal representation
14-
# as much as possible
15-
assert len(actual) == len(expected)
16-
for act, exp in zip(actual, expected):
17-
act = np.asarray(act)
18-
exp = np.asarray(exp)
19-
tm.assert_numpy_array_equal(act, exp, check_dtype=check_dtype)
13+
# avoid specifying internal representation
14+
# as much as possible
15+
assert len(actual) == len(expected)
16+
for act, exp in zip(actual, expected):
17+
act = np.asarray(act)
18+
exp = np.asarray(exp)
19+
tm.assert_numpy_array_equal(act, exp, check_dtype=check_dtype)
2020

2121

2222
def test_get_level_number_integer(idx):
@@ -172,7 +172,7 @@ def test_set_levels(idx):
172172
# side note - you probably wouldn't want to use levels and labels
173173
# directly like this - but it is possible.
174174
levels = idx.levels
175-
new_levels = [[lev + 'a' for lev in level] for level in levels]
175+
new_levels = [[lev + 'a' for lev in level] for level in levels]
176176

177177
# level changing [w/o mutation]
178178
ind2 = idx.set_levels(new_levels)
@@ -255,7 +255,6 @@ def test_set_labels(idx):
255255
minor_labels = [(x + 1) % 1 for x in minor_labels]
256256
new_labels = [major_labels, minor_labels]
257257

258-
259258
# label changing [w/o mutation]
260259
ind2 = idx.set_labels(new_labels)
261260
assert_matching(ind2.labels, new_labels)
@@ -381,15 +380,16 @@ def test_set_names_with_nlevel_1(inplace):
381380

382381
tm.assert_index_equal(result, expected)
383382

383+
384384
@pytest.mark.parametrize('ordered', [True, False])
385385
def test_set_levels_categorical(ordered):
386386
# GH13854
387387
index = MultiIndex.from_arrays([list("xyzx"), [0, 1, 2, 3]])
388-
388+
389389
cidx = CategoricalIndex(list("bac"), ordered=ordered)
390390
result = index.set_levels(cidx, 0)
391391
expected = MultiIndex(levels=[cidx, [0, 1, 2, 3]],
392-
labels=index.labels)
392+
labels=index.labels)
393393
tm.assert_index_equal(result, expected)
394394

395395
result_lvl = result.get_level_values(0)

0 commit comments

Comments
 (0)