Skip to content

Commit 67cc021

Browse files
gfyoungjreback
authored andcommitted
CLN: Remove "flake8: noqa" from more files
Another round of house-cleaning that builds off #15842. xref <a href="https://github.com/pandas- dev/pandas/issues/12066#issuecomment-172285473">#12066 (comment)</a> : the issue remains unresolved, but it does not seem entirely necessary to disable style-checking on the entire file for that IMO. Author: gfyoung <[email protected]> Closes #15867 from gfyoung/flake8-noqa-clean and squashes the following commits: 0c84926 [gfyoung] CLN: Make tseries/common.py flake8-able 7a799ff [gfyoung] CLN: Make _version.py flake8-able 7087b64 [gfyoung] CLN: Make test_categorical.py flake8-able 5d5abf8 [gfyoung] CLN: Make test_categorical.py flake8-able 6ace90b [gfyoung] CLN: Make test_eval.py flake8-able
1 parent a293d22 commit 67cc021

File tree

5 files changed

+134
-149
lines changed

5 files changed

+134
-149
lines changed

pandas/_version.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# This file helps to compute a version number in source trees obtained from
32
# git-archive tarball (such as those provided by githubs download-from-tag
43
# feature). Distribution tarballs (built by setup.py sdist) and build
@@ -8,8 +7,6 @@
87
# This file is released into the public domain. Generated by
98
# versioneer-0.15 (https://github.com/warner/python-versioneer)
109

11-
# flake8: noqa
12-
1310
import errno
1411
import os
1512
import re

pandas/tests/computation/test_eval.py

+47-48
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
2-
# flake8: noqa
3-
41
import warnings
52
import operator
63
from itertools import product
7-
from distutils.version import LooseVersion
84

95
import pytest
106

@@ -28,12 +24,11 @@
2824

2925
import pandas.computation.expr as expr
3026
import pandas.util.testing as tm
31-
import pandas._libs.lib as lib
3227
from pandas.util.testing import (assert_frame_equal, randbool,
3328
assertRaisesRegexp, assert_numpy_array_equal,
3429
assert_produces_warning, assert_series_equal,
3530
slow)
36-
from pandas.compat import PY3, u, reduce
31+
from pandas.compat import PY3, reduce
3732

3833
_series_frame_incompatible = _bool_ops_syms
3934
_scalar_skip = 'in', 'not in'
@@ -43,9 +38,9 @@
4338
pytest.mark.skipif(engine == 'numexpr' and not _USE_NUMEXPR,
4439
reason='numexpr enabled->{enabled}, '
4540
'installed->{installed}'.format(
46-
enabled=_USE_NUMEXPR,
47-
installed=_NUMEXPR_INSTALLED))(engine)
48-
for engine in _engines
41+
enabled=_USE_NUMEXPR,
42+
installed=_NUMEXPR_INSTALLED))(engine)
43+
for engine in _engines # noqa
4944
))
5045
def engine(request):
5146
return request.param
@@ -66,22 +61,23 @@ def _eval_single_bin(lhs, cmp1, rhs, engine):
6661
try:
6762
return c(lhs, rhs)
6863
except ValueError as e:
69-
if str(e).startswith('negative number cannot be raised to a fractional power'):
64+
if str(e).startswith('negative number cannot be '
65+
'raised to a fractional power'):
7066
return np.nan
7167
raise
7268
return c(lhs, rhs)
7369

7470

7571
def _series_and_2d_ndarray(lhs, rhs):
7672
return ((isinstance(lhs, Series) and
77-
isinstance(rhs, np.ndarray) and rhs.ndim > 1)
78-
or (isinstance(rhs, Series) and
79-
isinstance(lhs, np.ndarray) and lhs.ndim > 1))
73+
isinstance(rhs, np.ndarray) and rhs.ndim > 1) or
74+
(isinstance(rhs, Series) and
75+
isinstance(lhs, np.ndarray) and lhs.ndim > 1))
8076

8177

8278
def _series_and_frame(lhs, rhs):
83-
return ((isinstance(lhs, Series) and isinstance(rhs, DataFrame))
84-
or (isinstance(rhs, Series) and isinstance(lhs, DataFrame)))
79+
return ((isinstance(lhs, Series) and isinstance(rhs, DataFrame)) or
80+
(isinstance(rhs, Series) and isinstance(lhs, DataFrame)))
8581

8682

8783
def _bool_and_frame(lhs, rhs):
@@ -228,27 +224,29 @@ def check_complex_cmp_op(self, lhs, cmp1, rhs, binop, cmp2):
228224
else:
229225
lhs_new = _eval_single_bin(lhs, cmp1, rhs, self.engine)
230226
rhs_new = _eval_single_bin(lhs, cmp2, rhs, self.engine)
231-
if (isinstance(lhs_new, Series) and isinstance(rhs_new, DataFrame)
232-
and binop in _series_frame_incompatible):
227+
if (isinstance(lhs_new, Series) and
228+
isinstance(rhs_new, DataFrame) and
229+
binop in _series_frame_incompatible):
233230
pass
234231
# TODO: the code below should be added back when left and right
235232
# hand side bool ops are fixed.
236-
233+
#
237234
# try:
238-
# self.assertRaises(Exception, pd.eval, ex,
239-
#local_dict={'lhs': lhs, 'rhs': rhs},
240-
# engine=self.engine, parser=self.parser)
235+
# self.assertRaises(Exception, pd.eval, ex,
236+
# local_dict={'lhs': lhs, 'rhs': rhs},
237+
# engine=self.engine, parser=self.parser)
241238
# except AssertionError:
242-
#import ipdb; ipdb.set_trace()
243-
# raise
239+
# import ipdb
240+
#
241+
# ipdb.set_trace()
242+
# raise
244243
else:
245244
expected = _eval_single_bin(
246245
lhs_new, binop, rhs_new, self.engine)
247246
result = pd.eval(ex, engine=self.engine, parser=self.parser)
248247
self.check_equal(result, expected)
249248

250249
def check_chained_cmp_op(self, lhs, cmp1, mid, cmp2, rhs):
251-
skip_these = _scalar_skip
252250

253251
def check_operands(left, right, cmp_op):
254252
return _eval_single_bin(left, cmp_op, right, self.engine)
@@ -334,7 +332,8 @@ def get_expected_pow_result(self, lhs, rhs):
334332
try:
335333
expected = _eval_single_bin(lhs, '**', rhs, self.engine)
336334
except ValueError as e:
337-
if str(e).startswith('negative number cannot be raised to a fractional power'):
335+
if str(e).startswith('negative number cannot be '
336+
'raised to a fractional power'):
338337
if self.engine == 'python':
339338
pytest.skip(str(e))
340339
else:
@@ -650,7 +649,7 @@ def test_disallow_scalar_bool_ops(self):
650649
exprs += '2 * x > 2 or 1 and 2',
651650
exprs += '2 * df > 3 and 1 or a',
652651

653-
x, a, b, df = np.random.randn(3), 1, 2, DataFrame(randn(3, 2))
652+
x, a, b, df = np.random.randn(3), 1, 2, DataFrame(randn(3, 2)) # noqa
654653
for ex in exprs:
655654
with tm.assertRaises(NotImplementedError):
656655
pd.eval(ex, engine=self.engine, parser=self.parser)
@@ -682,7 +681,7 @@ def test_identical(self):
682681
tm.assert_numpy_array_equal(result, np.array([1.5]))
683682
self.assertEqual(result.shape, (1, ))
684683

685-
x = np.array([False])
684+
x = np.array([False]) # noqa
686685
result = pd.eval('x', engine=self.engine, parser=self.parser)
687686
tm.assert_numpy_array_equal(result, np.array([False]))
688687
self.assertEqual(result.shape, (1, ))
@@ -792,9 +791,8 @@ def check_chained_cmp_op(self, lhs, cmp1, mid, cmp2, rhs):
792791
f = lambda *args, **kwargs: np.random.randn()
793792

794793

795-
#-------------------------------------
796-
# typecasting rules consistency with python
797-
# issue #12388
794+
# -------------------------------------
795+
# gh-12388: Typecasting rules consistency with python
798796

799797

800798
class TestTypeCasting(object):
@@ -817,8 +815,8 @@ def test_binop_typecasting(self, engine, parser, op, dt):
817815
assert_frame_equal(res, eval(s))
818816

819817

820-
#-------------------------------------
821-
# basic and complex alignment
818+
# -------------------------------------
819+
# Basic and complex alignment
822820

823821
def _is_datetime(x):
824822
return issubclass(x.dtype.type, np.datetime64)
@@ -1064,8 +1062,8 @@ def test_performance_warning_for_poor_alignment(self, engine, parser):
10641062
tm.assert_equal(msg, expected)
10651063

10661064

1067-
#------------------------------------
1068-
# slightly more complex ops
1065+
# ------------------------------------
1066+
# Slightly more complex ops
10691067

10701068
class TestOperationsNumExprPandas(tm.TestCase):
10711069

@@ -1156,7 +1154,7 @@ def test_single_variable(self):
11561154
def test_truediv(self):
11571155
s = np.array([1])
11581156
ex = 's / 1'
1159-
d = {'s': s}
1157+
d = {'s': s} # noqa
11601158

11611159
if PY3:
11621160
res = self.eval(ex, truediv=False)
@@ -1204,7 +1202,7 @@ def test_truediv(self):
12041202
self.assertEqual(res, expec)
12051203

12061204
def test_failing_subscript_with_name_error(self):
1207-
df = DataFrame(np.random.randn(5, 3))
1205+
df = DataFrame(np.random.randn(5, 3)) # noqa
12081206
with tm.assertRaises(NameError):
12091207
self.eval('df[x > 2] > 2')
12101208

@@ -1501,7 +1499,7 @@ def setUpClass(cls):
15011499
cls.arith_ops)
15021500

15031501
def test_check_many_exprs(self):
1504-
a = 1
1502+
a = 1 # noqa
15051503
expr = ' * '.join('a' * 33)
15061504
expected = 1
15071505
res = pd.eval(expr, engine=self.engine, parser=self.parser)
@@ -1526,13 +1524,13 @@ def test_fails_not(self):
15261524
engine=self.engine)
15271525

15281526
def test_fails_ampersand(self):
1529-
df = DataFrame(np.random.randn(5, 3))
1527+
df = DataFrame(np.random.randn(5, 3)) # noqa
15301528
ex = '(df + 2)[df > 1] > 0 & (df > 0)'
15311529
with tm.assertRaises(NotImplementedError):
15321530
pd.eval(ex, parser=self.parser, engine=self.engine)
15331531

15341532
def test_fails_pipe(self):
1535-
df = DataFrame(np.random.randn(5, 3))
1533+
df = DataFrame(np.random.randn(5, 3)) # noqa
15361534
ex = '(df + 2)[df > 1] > 0 | (df > 0)'
15371535
with tm.assertRaises(NotImplementedError):
15381536
pd.eval(ex, parser=self.parser, engine=self.engine)
@@ -1728,15 +1726,15 @@ def test_global_scope(self, engine, parser):
17281726
parser=parser))
17291727

17301728
def test_no_new_locals(self, engine, parser):
1731-
x = 1
1729+
x = 1 # noqa
17321730
lcls = locals().copy()
17331731
pd.eval('x + 1', local_dict=lcls, engine=engine, parser=parser)
17341732
lcls2 = locals().copy()
17351733
lcls2.pop('lcls')
17361734
tm.assert_equal(lcls, lcls2)
17371735

17381736
def test_no_new_globals(self, engine, parser):
1739-
x = 1
1737+
x = 1 # noqa
17401738
gbls = globals().copy()
17411739
pd.eval('x + 1', engine=engine, parser=parser)
17421740
gbls2 = globals().copy()
@@ -1787,15 +1785,16 @@ def test_name_error_exprs(engine, parser):
17871785

17881786

17891787
def test_invalid_local_variable_reference(engine, parser):
1790-
a, b = 1, 2
1788+
a, b = 1, 2 # noqa
17911789
exprs = 'a + @b', '@a + b', '@a + @b'
1792-
for expr in exprs:
1790+
1791+
for _expr in exprs:
17931792
if parser != 'pandas':
17941793
with tm.assertRaisesRegexp(SyntaxError, "The '@' prefix is only"):
1795-
pd.eval(exprs, engine=engine, parser=parser)
1794+
pd.eval(_expr, engine=engine, parser=parser)
17961795
else:
17971796
with tm.assertRaisesRegexp(SyntaxError, "The '@' prefix is not"):
1798-
pd.eval(exprs, engine=engine, parser=parser)
1797+
pd.eval(_expr, engine=engine, parser=parser)
17991798

18001799

18011800
def test_numexpr_builtin_raises(engine, parser):
@@ -1834,9 +1833,9 @@ def test_more_than_one_expression_raises(engine, parser):
18341833
def test_bool_ops_fails_on_scalars(lhs, cmp, rhs, engine, parser):
18351834
gen = {int: lambda: np.random.randint(10), float: np.random.randn}
18361835

1837-
mid = gen[lhs]()
1838-
lhs = gen[lhs]()
1839-
rhs = gen[rhs]()
1836+
mid = gen[lhs]() # noqa
1837+
lhs = gen[lhs]() # noqa
1838+
rhs = gen[rhs]() # noqa
18401839

18411840
ex1 = 'lhs {0} mid {1} rhs'.format(cmp, cmp)
18421841
ex2 = 'lhs {0} mid and mid {1} rhs'.format(cmp, cmp)

0 commit comments

Comments
 (0)