8000 fixed code style errors raised by flake8 · larray-project/larray@7fc6420 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7fc6420

Browse files
committed
fixed code style errors raised by flake8
1 parent 26d63b7 commit 7fc6420

File tree

16 files changed

+53
-51
lines changed

16 files changed

+53
-51
lines changed

larray/core/array.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# * use larray "utils" in LIAM2 (to avoid duplicated code)
2727

2828
from collections import OrderedDict
29-
from itertools import product, chain, groupby, islice, repeat
29+
from itertools import product, chain, groupby
3030
from collections.abc import Iterable, Sequence
3131
import builtins
3232
import os
@@ -53,7 +53,7 @@
5353
from larray.core.expr import ExprNode
5454
from larray.core.group import (Group, IGroup, LGroup, remove_nested_groups, _to_key, _to_keys,
5555
_translate_sheet_name, _translate_group_key_hdf)
56-
from larray.core.axis import Axis, AxisReference, AxisCollection, X, _make_axis
56+
from larray.core.axis import Axis, AxisReference, AxisCollection, X, _make_axis # noqa: F401
5757
from larray.util.misc import (table2str, size2str, ReprString,
5858
float_error_handler_factory, light_product, common_type,
5959
renamed_to, deprecate_kwarg, LHDFStore, lazy_attribute, unique_multi, SequenceZip,
@@ -3567,7 +3567,7 @@ def unique(self, axes=None, sort=False, sep='_'):
35673567
for labels, value in self.items(axes):
35683568
hashable_value = value.data.tobytes() if isinstance(value, Array) else value
35693569
if hashable_value not in seen:
3570-
list_append((sep_join(str(l) for l in labels), value))
3570+
list_append((sep_join(str(label) for label in labels), value))
35713571
seen_add(hashable_value)
35723572
res_arr = stack(unq_list, axis_name)
35733573
# transpose the combined axis at the position where the first of the combined axes was
@@ -8689,6 +8689,7 @@ def array_or_full(a, axis, initial):
86898689
res[axis.i[1:]] = ((1 - cum_mult) / (1 - mult)) * inc + initial * cum_mult
86908690
return res
86918691

8692+
86928693
create_sequential = renamed_to(sequence, 'create_sequential')
86938694

86948695

larray/core/axis.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from larray.core.expr import ExprNode
1212
from larray.core.group import (Group, LGroup, IGroup, IGroupMaker, _to_tick, _to_ticks, _to_key, _seq_summary,
1313
_idx_seq_to_slice, _seq_group_to_name, _translate_group_key_hdf, remove_nested_groups)
14-
from larray.util.oset import *
14+
from larray.util.oset import OrderedSet
1515
from larray.util.misc import (duplicates, array_lookup2, ReprString, index_by_id, renamed_to, common_type, LHDFStore,
16-
lazy_attribute, _isnoneslice, unique_multi, Product)
16+
lazy_attribute, _isnoneslice, unique_list, unique_multi, Product)
1717

1818

1919
np_frompyfunc = np.frompyfunc
@@ -321,7 +321,7 @@ def split(self, sep='_', names=None, regex=None, return_labels=False):
321321
split_labels = np.char.split(labels, sep)
322322
else:
323323
match = re.compile(regex).match
324-
split_labels = [match(l).groups() for l in self.labels]
324+
split_labels = [match(label).groups() for label in self.labels]
325325
if names is None:
326326
names = [None] * len(split_labels)
327327
indexing_labels = zip(*split_labels)
@@ -1183,7 +1183,7 @@ def intersection(self, other):
11831183
if isinstance(other, Axis):
11841184
other = other.labels
11851185
to_keep = set(other)
1186-
return Axis([l for l in self.labels if l in to_keep], self.name)
1186+
return Axis([label for label in self.labels if label in to_keep], self.name)
11871187

11881188
def difference(self, other):
11891189
r"""Returns axis with the (set) difference of this axis labels and other labels.
@@ -1220,7 +1220,7 @@ def difference(self, other):
12201220
if isinstance(other, Axis):
12211221
other = other.labels
12221222
to_drop = set(other)
1223-
return Axis([l for l in self.labels if l not in to_drop], self.name)
1223+
return Axis([label for label in self.labels if label not in to_drop], self.name)
12241224

12251225
def align(self, other, join='outer'):
12261226
r"""Align axis with other object using specified join method.
@@ -3186,7 +3186,7 @@ def combine_axes(self, axes=None, sep='_', wildcard=False, front_if_spread=False
31863186
combined_labels = _axes[0].labels
31873187
else:
31883188
sepjoin = sep.join
3189-
axes_labels = [np.array(l, np.str, copy=False) for l in _axes.labels]
3189+
axes_labels = [np.array(label, np.str, copy=False) for label in _axes.labels]
31903190
combined_labels = [sepjoin(p) for p in product(*axes_labels)]
31913191
combined_axis = Axis(combined_labels, combined_name)
31923192
new_axes = new_axes - _axes

larray/core/group.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pandas as pd
99

1010
from larray.core.abstractbases import ABCAxis, ABCAxisReference, ABCArray
11-
from larray.util.oset import *
11+
from larray.util.oset import OrderedSet
1212
from larray.util.misc import (unique, find_closing_chr, _parse_bound, _seq_summary, _isintstring, renamed_to, LHDFStore)
1313

1414

@@ -867,7 +867,7 @@ def __len__(self):
867867
if hasattr(value, '__len__'):
868868
return len(value)
869869
elif isinstance(value, slice):
870-
start, stop, key_step = value.start, value.stop, value.step
870+
start, stop = value.start, value.stop
871871
# not using stop - start because that does not work for string bounds
872872
# (and it is different for LGroup & IGroup)
873873
start_pos = self.translate(start)
@@ -1715,4 +1715,5 @@ def eval(self):
17151715
def __hash__(self):
17161716
return hash(('IGroup', _to_tick(self.key)))
17171717

1718+
17181719
PGroup = renamed_to(IGroup, 'PGroup')

larray/core/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from larray.core.group import Group
1313
from larray.core.axis import Axis
1414
from larray.core.constants import nan
15-
from larray.core.array import Array, get_axes, ndtest, zeros, zeros_like, sequence, asarray
15+
from larray.core.array import Array, get_axes, ndtest, zeros, zeros_like, sequence # noqa: F401
1616
from larray.util.misc import float_error_handler_factory, is_interactive_interpreter, renamed_to, inverseop
1717
from larray.inout.session import ext_default_engine, get_file_handler
1818

larray/inout/csv.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import csv
33
import warnings
44
from glob import glob
5-
from collections import OrderedDict
65

76
import pandas as pd
87
import numpy as np
@@ -14,7 +13,7 @@
1413
from larray.inout.session import register_file_handler
1514
from larray.inout.common import _get_index_col, FileHandler
1615
from larray.inout.pandas import df_asarray
17-
from larray.example import get_example_filepath
16+
from larray.example import get_example_filepath # noqa: F401
1817

1918

2019
@deprecate_kwarg('nb_index', 'nb_axes', arg_converter=lambda x: x + 1)

larray/inout/excel.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import os
21
import warnings
3-
from collections import OrderedDict
42

53
import numpy as np
64
import pandas as pd
@@ -10,16 +8,15 @@
108
xw = None
119

1210
from larray.core.array import Array, asarray
13-
from larray.core.axis import Axis
1411
from larray.core.constants import nan
15-
from larray.core.group import Group, _translate_sheet_name
12+
from larray.core.group import _translate_sheet_name
1613
from larray.core.metadata import Metadata
1714from larray.util.misc import deprecate_kwarg
1815
from larray.inout.session import register_file_handler
1916
from larray.inout.common import _get_index_col, FileHandler
2017
from larray.inout.pandas import df_asarray
2118
from larray.inout.xw_excel import open_excel
22-
from larray.example import get_example_filepath
19+
from larray.example import get_example_filepath # noqa: F401
2320

2421

2522
__all__ = ['read_excel']

larray/inout/hdf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from larray.inout.session import register_file_handler
1414
from larray.inout.common import FileHandler, _supported_typenames, _supported_scalars_types
1515
from larray.inout.pandas import df_asarray
16-
from larray.example import get_example_filepath
16+
from larray.example import get_example_filepath # noqa: F401
1717

1818

1919
# for backward compatibility (larray < 0.29) but any object read from an hdf file should have
@@ -103,7 +103,7 @@ def read_hdf(filepath_or_buffer, key, fill_value=nan, na=nan, sort_rows=False, s
103103
# np.char.decode does not work
104104
# this is at least the case for Python2 + Pandas 0.24.2 combination
105105
if labels.dtype.kind == 'O':
106-
labels = np.array([l.decode('utf-8') for l in labels], dtype='U')
106+
labels = np.array([label.decode('utf-8') for label in labels], dtype='U')
107107
else:
108108
labels = np.char.decode(labels, 'utf-8')
109109
res = Axis(labels=labels, name=name)

larray/inout/pandas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def index_to_labels(idx, sort=True):
4848
if sort:
4949
return list(idx.levels)
5050
else:
51-
return [list(unique(idx.get_level_values(l))) for l in range(idx.nlevels)]
51+
return [list(unique(idx.get_level_values(label))) for label in range(idx.nlevels)]
5252
else:
5353
assert isinstance(idx, pd.Index)
5454
labels = list(idx.values)

larray/inout/xw_excel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
except ImportError:
88
xw = None
99

10-
from larray.core.array import Array, ndtest
10+
from larray.core.array import Array, ndtest # noqa: F401
1111
from larray.core.axis import Axis
1212
from larray.core.constants import nan
1313
from larray.core.group import _translate_sheet_name

larray/random.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2626
import numpy as np
2727

28-
from larray.core.axis import Axis, AxisCollection
28+
from larray.core.axis import Axis, AxisCollection # noqa: F401
2929
from larray.core.array import Array, asarray
3030
from larray.core.array import raw_broadcastable
31-
import larray as la
31+
import larray as la # noqa: F401
3232

3333

3434
__all__ = ['randint', 'normal', 'uniform', 'permutation', 'choice']

larray/tests/test_array.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from io import StringIO
1010
from collections import OrderedDict
1111

12-
from larray.tests.common import (inputpath, tmp_path, meta,
12+
from larray.tests.common import meta # noqa: F401
13+
from larray.tests.common import (inputpath, tmp_path,
10000
1314
assert_array_equal, assert_array_nan_equal, assert_larray_equiv, assert_larray_equal,
1415
needs_xlwings, needs_pytables, needs_xlsxwriter, needs_xlrd,
1516
needs_python37)
@@ -246,9 +247,9 @@ def test_bool():
246247

247248

248249
def test_iter(small_array):
249-
l = list(small_array)
250-
assert_array_equal(l[0], small_array['M'])
251-
assert_array_equal(l[1], small_array['F'])
250+
list_ = list(small_array)
251+
assert_array_equal(list_[0], small_array['M'])
252+
assert_array_equal(list_[1], small_array['F'])
252253

253254

254255
def test_keys():
@@ -1859,8 +1860,6 @@ def test_group_agg_guess_axis(array):
18591860
res = array.sum('M >> men;M,F >> all')
18601861
assert res.shape == (116, 44, 2, 15)
18611862
assert 'sex' in res.axes
1862-
men = sex['M'].named('men')
1863-
all_ = sex['M,F'].named('all')
18641863
assert_array_equal(res.axes.sex.labels, ['men', 'all'])
18651864
assert_array_equal(res['men'], raw[:, :, 0, :])
18661865
assert_array_equal(res['all'], raw.sum(2))
@@ -2655,8 +2654,8 @@ def test_binary_ops(small_array):
26552654
def test_binary_ops_no_name_axes(small_array):
26562655
raw = small_array.data
26572656
raw2 = small_array.data + 1
2658-
la = ndtest([Axis(l) for l in small_array.shape])
2659-
la2 = ndtest([Axis(l) for l in small_array.shape]) + 1
2657+
la = ndtest([Axis(label) for label in small_array.shape])
2658+
la2 = ndtest([Axis(label) for label in small_array.shape]) + 1
26602659

26612660
assert_array_equal(la + la2, raw + raw2)
26622661
assert_array_equal(la + 1, raw + 1)
@@ -2802,7 +2801,7 @@ def test_set_labels(small_array):
28022801

28032802

28042803
def test_set_axes(small_array):
2805-
lipro2 = Axis([l.replace('P', 'Q') for l in lipro.labels], 'lipro2')
2804+
lipro2 = Axis([label.replace('P', 'Q') for label in lipro.labels], 'lipro2')
28062805
sex2 = Axis(['Man', 'Woman'], 'sex2')
28072806

28082807
la = Array(small_array.data, axes=(sex, lipro2))

larray/tests/test_axiscollection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,15 @@ def test_index(col):
230230
assert col.index(-2) == -2
231231
assert col.index(-3) == -3
232232
with pytest.raises(ValueError):
233-
col.index(3)
233+
col.index(3)
234234

235235
# objects actually in col
236236
assert col.index(lipro) == 0
237237
assert col.index(sex) == 1
238238
assert col.index(age) == 2
239239
assert col.index(sex2) == 1
240240
with pytest.raises(ValueError):
241-
col.index(geo)
241+
col.index(geo)
242242
with pytest.raises(ValueError):
243243
col.index(value)
244244

@@ -250,7 +250,7 @@ def test_index(col):
250250
assert col.index(anon2) == 3
251251
anon3 = Axis([0, 2])
252252
with pytest.raises(ValueError):
253-
col.index(anon3)
253+
col.index(anon3)
254254

255255

256256
def test_get(col):

larray/tests/test_excel.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,6 @@ def test_asarray(self):
219219
assert np.array_equal(res1, arr1.data)
220220
assert res1.dtype == arr1.dtype
221221

222-
def test_asarray(self):
223-
with open_excel(visible=False) as wb:
224-
sheet = wb[0]
225-
226222
arr1 = ndtest([Axis(2), Axis(3)])
227223
# no header so that we have an uniform dtype for the whole sheet
228224
sheet['A1'] = arr1
@@ -299,12 +295,12 @@ def test_excel_report_setting_template():
299295
def test_excel_report_sheets():
300296
report = ExcelReport()
301297
# test adding new sheets
302-
sheet_population = report.new_sheet('Population')
303-
sheet_births = report.new_sheet('Births')
304-
sheet_deaths = report.new_sheet('Deaths')
298+
report.new_sheet('Population')
299+
report.new_sheet('Births')
300+
report.new_sheet('Deaths')
305301
# test warning if sheet already exists
306302
with pytest.warns(UserWarning) as caught_warnings:
307-
sheet_population2 = report.new_sheet('Population')
303+
sheet_population2 = report.new_sheet('Population') # noqa: F841
308304
assert len(caught_warnings) == 1
309305
warn_msg = "Sheet 'Population' already exists in the report and will be reset"
310306
assert caught_warnings[0].message.args[0] == warn_msg

larray/tests/test_group.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,5 +497,6 @@ def test_h5_io_igroup(tmpdir):
497497
named2 = read_hdf(fpath, key=named_axis_not_in_file.name)
498498
assert all(named_axis_not_in_file == named2)
499499

500+
500501
if __name__ == "__main__":
501502
pytest.main()

larray/tests/test_session.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import pandas as pd
88
import pytest
99

10-
from larray.tests.common import (assert_array_nan_equal, inputpath, tmp_path, meta,
10+
from larray.tests.common import meta # noqa: F401
11+
from larray.tests.common import (assert_array_nan_equal, inputpath, tmp_path,
1112
needs_xlwings, needs_pytables, needs_xlrd)
1213
from larray.inout.common import _supported_scalars_types
1314
from larray import (Session, Axis, Array, Group, isnan, zeros_like, ndtest, ones_like, ones, full,
@@ -276,7 +277,7 @@ def test_csv_io(tmpdir, session, meta):
276277
f.write(',",')
277278

278279
# try loading the directory with the invalid file
279-
with pytest.raises(pd.errors.ParserError) as e_info:
280+
with pytest.raises(pd.errors.ParserError):
280281
s = Session(pattern)
281282

282283
# test loading a pattern, ignoring invalid/unsupported files

setup.cfg

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,23 @@ addopts = -v --doctest-modules
1414
--flake8
1515
#--cov
1616
--disable-warnings
17+
# F401: imported item not used
18+
# F811: redefinition of unused variable
19+
# F841: local variable is assigned to but never used
1720
# E122: continuation line missing indentation or outdented
1821
# E127: check indents
1922
# E201: whitespace after '['
2023
# E202: whitespace before ']'
2124
# E241: multiple spaces after ','
25+
# E301: expected 1 blank line, found 0
2226
# E303: too many blank lines
23-
# E402 module level import not at top of file
27+
# E402: module level import not at top of file
2428
# E712: comparison to True should be 'if cond is True:' or 'if cond:'
29+
# E722: do not use bare 'except'
30+
# W504: line break after binary operator
2531
flake8-ignore =
26-
__init__.py E402
27-
xw_excel.py E303
28-
test_*.py E127 E122 E201 E202 E241 E712
32+
*.py E722 W504
33+
__init__.py E402 F401
34+
xw_excel.py E301 E303
35+
test_*.py E127 E122 E201 E202 E241 E712 F811 F841
2936
flake8-max-line-length = 120

0 commit comments

Comments
 (0)
0