Skip to content

Commit 52c547a

Browse files
committed
STYLE: final flake8 fixes, add back check for travis-ci
closes pandas-dev#11928 closes pandas-dev#12208
1 parent 63abbe4 commit 52c547a

32 files changed

+127
-153
lines changed

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,10 @@ script:
164164
- echo "script"
165165
- ci/run_build_docs.sh
166166
- ci/script.sh
167+
- ci/lint.sh
167168
# nothing here, or failed tests won't fail travis
168169

169170
after_script:
170171
- ci/install_test.sh
171172
- source activate pandas && ci/print_versions.py
172173
- ci/print_skipped.py /tmp/nosetests.xml
173-
- ci/lint.sh
174-
- ci/lint_ok_for_now.sh

ci/lint.sh

+7-10
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@ echo "inside $0"
44

55
source activate pandas
66

7-
for path in 'core'
7+
RET=0
8+
for path in 'core' 'io' 'stats' 'compat' 'sparse' 'tools' 'tseries' 'tests' 'computation' 'util'
89
do
910
echo "linting -> pandas/$path"
10-
flake8 pandas/$path --filename '*.py' --statistics -q
11+
flake8 pandas/$path --filename '*.py'
12+
if [ $? -ne "0" ]; then
13+
RET=1
14+
fi
1115
done
1216

13-
RET="$?"
14-
15-
# we are disabling the return code for now
16-
# to have Travis-CI pass. When the code
17-
# passes linting, re-enable
18-
#exit "$RET"
19-
20-
exit 0
17+
exit $RET

ci/lint_ok_for_now.sh

-20
This file was deleted.

pandas/compat/numpy_compat.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
_np_version_under1p11 = LooseVersion(_np_version) < '1.11'
2020

2121
if LooseVersion(_np_version) < '1.7.0':
22-
raise ImportError('this version of pandas is incompatible with numpy < 1.7.0\n'
22+
raise ImportError('this version of pandas is incompatible with '
23+
'numpy < 1.7.0\n'
2324
'your numpy version is {0}.\n'
2425
'Please upgrade numpy to >= 1.7.0 to use '
2526
'this pandas version'.format(_np_version))
@@ -61,7 +62,7 @@ def np_array_datetime64_compat(arr, *args, **kwargs):
6162
isinstance(arr, string_and_binary_types):
6263
arr = [tz_replacer(s) for s in arr]
6364
else:
64-
arr = tz_replacer(s)
65+
arr = tz_replacer(arr)
6566

6667
return np.array(arr, *args, **kwargs)
6768

pandas/core/frame.py

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
from pandas.tseries.index import DatetimeIndex
5252
from pandas.tseries.tdi import TimedeltaIndex
5353

54-
import pandas.core.algorithms as algos
5554
import pandas.core.base as base
5655
import pandas.core.common as com
5756
import pandas.core.format as fmt

pandas/core/groupby.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -2310,10 +2310,9 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True):
23102310
except Exception:
23112311
all_in_columns = False
23122312

2313-
if (not any_callable and not all_in_columns
2314-
and not any_arraylike and not any_groupers
2315-
and match_axis_length
2316-
and level is None):
2313+
if not any_callable and not all_in_columns and \
2314+
not any_arraylike and not any_groupers and \
2315+
match_axis_length and level is None:
23172316
keys = [com._asarray_tuplesafe(keys)]
23182317

23192318
if isinstance(level, (tuple, list)):
@@ -3695,7 +3694,7 @@ def count(self):
36953694
return self._wrap_agged_blocks(data.items, list(blk))
36963695

36973696

3698-
from pandas.tools.plotting import boxplot_frame_groupby
3697+
from pandas.tools.plotting import boxplot_frame_groupby # noqa
36993698
DataFrameGroupBy.boxplot = boxplot_frame_groupby
37003699

37013700

pandas/core/internals.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3981,7 +3981,7 @@ def form_blocks(arrays, names, axes):
39813981
klass=DatetimeTZBlock,
39823982
fastpath=True,
39833983
placement=[i], )
3984-
for i, names, array in datetime_tz_items]
3984+
for i, _, array in datetime_tz_items]
39853985
blocks.extend(dttz_blocks)
39863986

39873987
if len(bool_items):
@@ -3999,7 +3999,7 @@ def form_blocks(arrays, names, axes):
39993999
if len(cat_items) > 0:
40004000
cat_blocks = [make_block(array, klass=CategoricalBlock, fastpath=True,
40014001
placement=[i])
4002-
for i, names, array in cat_items]
4002+
for i, _, array in cat_items]
40034003
blocks.extend(cat_blocks)
40044004

40054005
if len(extra_locs):

pandas/core/reshape.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def _unstack_multiple(data, clocs):
282282
for i in range(len(clocs)):
283283
val = clocs[i]
284284
result = result.unstack(val)
285-
clocs = [val if i > val else val - 1 for val in clocs]
285+
clocs = [v if i > v else v - 1 for v in clocs]
286286

287287
return result
288288

pandas/sparse/panel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,10 @@ def _convert_frames(frames, index, columns, fill_value=np.nan, kind='block'):
520520
output[item] = df
521521

522522
if index is None:
523-
all_indexes = [df.index for df in output.values()]
523+
all_indexes = [x.index for x in output.values()]
524524
index = _get_combined_index(all_indexes)
525525
if columns is None:
526-
all_columns = [df.columns for df in output.values()]
526+
all_columns = [x.columns for x in output.values()]
527527
columns = _get_combined_index(all_columns)
528528

529529
index = _ensure_index(index)

pandas/tests/frame/test_apply.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ def transform(row):
262262
return row
263263

264264
def transform2(row):
265-
if (notnull(row['C']) and row['C'].startswith('shin')
266-
and row['A'] == 'foo'):
265+
if (notnull(row['C']) and row['C'].startswith('shin') and
266+
row['A'] == 'foo'):
267267
row['D'] = 7
268268
return row
269269

pandas/tests/frame/test_indexing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2178,8 +2178,8 @@ def test_where(self):
21782178
def _safe_add(df):
21792179
# only add to the numeric items
21802180
def is_ok(s):
2181-
return (issubclass(s.dtype.type, (np.integer, np.floating))
2182-
and s.dtype != 'uint8')
2181+
return (issubclass(s.dtype.type, (np.integer, np.floating)) and
2182+
s.dtype != 'uint8')
21832183

21842184
return DataFrame(dict([(c, s + 1) if is_ok(s) else (c, s)
21852185
for c, s in compat.iteritems(df)]))

pandas/tests/frame/test_query_eval.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,7 @@ def test_chained_cmp_and_in(self):
581581
df = DataFrame(randn(100, len(cols)), columns=cols)
582582
res = df.query('a < b < c and a not in b not in c', engine=engine,
583583
parser=parser)
584-
ind = ((df.a < df.b) & (df.b < df.c) & ~df.b.isin(df.a) &
585-
~df.c.isin(df.b))
584+
ind = (df.a < df.b) & (df.b < df.c) & ~df.b.isin(df.a) & ~df.c.isin(df.b) # noqa
586585
expec = df[ind]
587586
assert_frame_equal(res, expec)
588587

pandas/tests/frame/test_repr_info.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,13 @@ def test_info_memory_usage(self):
328328
res = buf.getvalue().splitlines()
329329
self.assertTrue(re.match(r"memory usage: [^+]+$", res[-1]))
330330

331-
self.assertTrue(df_with_object_index.memory_usage(index=True,
332-
deep=True).sum()
333-
> df_with_object_index.memory_usage(index=True).sum())
331+
self.assertGreater(df_with_object_index.memory_usage(index=True,
332+
deep=True).sum(),
333+
df_with_object_index.memory_usage(index=True).sum())
334334

335335
df_object = pd.DataFrame({'a': ['a']})
336-
self.assertTrue(df_object.memory_usage(deep=True).sum()
337-
> df_object.memory_usage().sum())
336+
self.assertGreater(df_object.memory_usage(deep=True).sum(),
337+
df_object.memory_usage().sum())
338338

339339
# Test a DataFrame with duplicate columns
340340
dtypes = ['int64', 'int64', 'int64', 'float64']

pandas/tests/frame/test_reshape.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import numpy as np
1111

1212
from pandas.compat import u
13-
from pandas import DataFrame, Index, Series, MultiIndex, date_range, Timedelta, Period
13+
from pandas import (DataFrame, Index, Series, MultiIndex, date_range,
14+
Timedelta, Period)
1415
import pandas as pd
1516

1617
from pandas.util.testing import (assert_series_equal,

pandas/tests/test_base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def test_none_comparison(self):
332332
self.assertTrue(result.iat[0])
333333
self.assertTrue(result.iat[1])
334334

335-
result = None == o
335+
result = None == o # noqa
336336
self.assertFalse(result.iat[0])
337337
self.assertFalse(result.iat[1])
338338

pandas/tests/test_groupby.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -3858,8 +3858,8 @@ def test_groupby_categorical(self):
38583858
np.arange(4).repeat(8), levels, ordered=True)
38593859
exp = CategoricalIndex(expc)
38603860
self.assert_index_equal(desc_result.index.get_level_values(0), exp)
3861-
exp = Index(['count', 'mean', 'std', 'min', '25%', '50%', '75%', 'max']
3862-
* 4)
3861+
exp = Index(['count', 'mean', 'std', 'min', '25%', '50%',
3862+
'75%', 'max'] * 4)
38633863
self.assert_index_equal(desc_result.index.get_level_values(1), exp)
38643864

38653865
def test_groupby_datetime_categorical(self):
@@ -3899,8 +3899,8 @@ def test_groupby_datetime_categorical(self):
38993899
np.arange(4).repeat(8), levels, ordered=True)
39003900
exp = CategoricalIndex(expc)
39013901
self.assert_index_equal(desc_result.index.get_level_values(0), exp)
3902-
exp = Index(['count', 'mean', 'std', 'min', '25%', '50%', '75%', 'max']
3903-
* 4)
3902+
exp = Index(['count', 'mean', 'std', 'min', '25%', '50%',
3903+
'75%', 'max'] * 4)
39043904
self.assert_index_equal(desc_result.index.get_level_values(1), exp)
39053905

39063906
def test_groupby_categorical_index(self):

pandas/tests/test_multilevel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def test_append_index(self):
105105
expected = Index._simple_new(
106106
np.array([(1.1, datetime.datetime(2011, 1, 1, tzinfo=tz), 'A'),
107107
(1.2, datetime.datetime(2011, 1, 2, tzinfo=tz), 'B'),
108-
(1.3, datetime.datetime(2011, 1, 3, tzinfo=tz), 'C')]
109-
+ expected_tuples), None)
108+
(1.3, datetime.datetime(2011, 1, 3, tzinfo=tz), 'C')] +
109+
expected_tuples), None)
110110
self.assertTrue(result.equals(expected))
111111

112112
def test_dataframe_constructor(self):

pandas/tests/test_style.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import os
22
from nose import SkipTest
33

4+
import copy
5+
import numpy as np
6+
import pandas as pd
7+
from pandas import DataFrame
8+
from pandas.util.testing import TestCase
9+
import pandas.util.testing as tm
10+
411
# this is a mess. Getting failures on a python 2.7 build with
512
# whenever we try to import jinja, whether it's installed or not.
613
# so we're explicitly skipping that one *before* we try to import
@@ -14,14 +21,6 @@
1421
except ImportError:
1522
raise SkipTest("No Jinja2")
1623

17-
import copy
18-
19-
import numpy as np
20-
import pandas as pd
21-
from pandas import DataFrame
22-
from pandas.util.testing import TestCase
23-
import pandas.util.testing as tm
24-
2524

2625
class TestStyler(TestCase):
2726

@@ -196,8 +195,8 @@ def test_apply_subset(self):
196195
expected = dict(((r, c), ['color: baz'])
197196
for r, row in enumerate(self.df.index)
198197
for c, col in enumerate(self.df.columns)
199-
if row in self.df.loc[slice_].index
200-
and col in self.df.loc[slice_].columns)
198+
if row in self.df.loc[slice_].index and
199+
col in self.df.loc[slice_].columns)
201200
self.assertEqual(result, expected)
202201

203202
def test_applymap_subset(self):
@@ -213,8 +212,8 @@ def f(x):
213212
expected = dict(((r, c), ['foo: bar'])
214213
for r, row in enumerate(self.df.index)
215214
for c, col in enumerate(self.df.columns)
216-
if row in self.df.loc[slice_].index
217-
and col in self.df.loc[slice_].columns)
215+
if row in self.df.loc[slice_].index and
216+
col in self.df.loc[slice_].columns)
218217
self.assertEqual(result, expected)
219218

220219
def test_empty(self):

pandas/tests/test_window.py

+25-26
Original file line numberDiff line numberDiff line change
@@ -1002,32 +1002,31 @@ def simple_wma(s, w):
10021002
return (s.multiply(w).cumsum() / w.cumsum()).fillna(method='ffill')
10031003

10041004
for (s, adjust, ignore_na, w) in [
1005-
(s0, True, False, [np.nan, (1. - alpha), 1.]),
1006-
(s0, True, True, [np.nan, (1. - alpha), 1.]),
1007-
(s0, False, False, [np.nan, (1. - alpha), alpha]),
1008-
(s0, False, True, [np.nan, (1. - alpha), alpha]),
1009-
(s1, True, False, [(1. - alpha) ** 2, np.nan, 1.]),
1010-
(s1, True, True, [(1. - alpha), np.nan, 1.]),
1011-
(s1, False, False, [(1. - alpha) ** 2, np.nan, alpha]),
1012-
(s1, False, True, [(1. - alpha), np.nan, alpha]),
1013-
(s2, True, False, [np.nan, (1. - alpha)
1014-
** 3, np.nan, np.nan, 1., np.nan]),
1015-
(s2, True, True, [np.nan, (1. - alpha),
1016-
np.nan, np.nan, 1., np.nan]),
1017-
(s2, False, False, [np.nan, (1. - alpha)
1018-
** 3, np.nan, np.nan, alpha, np.nan]),
1019-
(s2, False, True, [np.nan, (1. - alpha),
1020-
np.nan, np.nan, alpha, np.nan]),
1021-
(s3, True, False, [(1. - alpha)
1022-
** 3, np.nan, (1. - alpha), 1.]),
1023-
(s3, True, True, [(1. - alpha) **
1024-
2, np.nan, (1. - alpha), 1.]),
1025-
(s3, False, False, [(1. - alpha) ** 3, np.nan,
1026-
(1. - alpha) * alpha,
1027-
alpha * ((1. - alpha) ** 2 + alpha)]),
1028-
(s3, False, True, [(1. - alpha) ** 2,
1029-
np.nan, (1. - alpha) * alpha, alpha]),
1030-
]:
1005+
(s0, True, False, [np.nan, (1. - alpha), 1.]),
1006+
(s0, True, True, [np.nan, (1. - alpha), 1.]),
1007+
(s0, False, False, [np.nan, (1. - alpha), alpha]),
1008+
(s0, False, True, [np.nan, (1. - alpha), alpha]),
1009+
(s1, True, False, [(1. - alpha) ** 2, np.nan, 1.]),
1010+
(s1, True, True, [(1. - alpha), np.nan, 1.]),
1011+
(s1, False, False, [(1. - alpha) ** 2, np.nan, alpha]),
1012+
(s1, False, True, [(1. - alpha), np.nan, alpha]),
1013+
(s2, True, False, [np.nan, (1. - alpha) **
1014+
3, np.nan, np.nan, 1., np.nan]),
1015+
(s2, True, True, [np.nan, (1. - alpha),
1016+
np.nan, np.nan, 1., np.nan]),
1017+
(s2, False, False, [np.nan, (1. - alpha) **
1018+
3, np.nan, np.nan, alpha, np.nan]),
1019+
(s2, False, True, [np.nan, (1. - alpha),
1020+
np.nan, np.nan, alpha, np.nan]),
1021+
(s3, True, False, [(1. - alpha) **
1022+
3, np.nan, (1. - alpha), 1.]),
1023+
(s3, True, True, [(1. - alpha) **
1024+
2, np.nan, (1. - alpha), 1.]),
1025+
(s3, False, False, [(1. - alpha) ** 3, np.nan,
1026+
(1. - alpha) * alpha,
1027+
alpha * ((1. - alpha) ** 2 + alpha)]),
1028+
(s3, False, True, [(1. - alpha) ** 2,
1029+
np.nan, (1. - alpha) * alpha, alpha])]:
10311030
expected = simple_wma(s, Series(w))
10321031
result = s.ewm(com=com, adjust=adjust, ignore_na=ignore_na).mean()
10331032

pandas/tools/merge.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,7 @@ def _get_merge_keys(self):
470470

471471
def _validate_specification(self):
472472
# Hm, any way to make this logic less complicated??
473-
if (self.on is None and self.left_on is None
474-
and self.right_on is None):
473+
if self.on is None and self.left_on is None and self.right_on is None:
475474

476475
if self.left_index and self.right_index:
477476
self.left_on, self.right_on = (), ()
@@ -1185,7 +1184,7 @@ def _make_concat_multiindex(indexes, keys, levels=None, names=None):
11851184
names = list(names)
11861185
else:
11871186
# make sure that all of the passed indices have the same nlevels
1188-
if not len(set([i.nlevels for i in indexes])) == 1:
1187+
if not len(set([idx.nlevels for idx in indexes])) == 1:
11891188
raise AssertionError("Cannot concat indices that do"
11901189
" not have the same number of levels")
11911190

pandas/tools/pivot.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ def _convert_by(by):
357357
if by is None:
358358
by = []
359359
elif (np.isscalar(by) or isinstance(by, (np.ndarray, Index,
360-
Series, Grouper))
361-
or hasattr(by, '__call__')):
360+
Series, Grouper)) or
361+
hasattr(by, '__call__')):
362362
by = [by]
363363
else:
364364
by = list(by)

0 commit comments

Comments
 (0)