Skip to content

Commit db0094d

Browse files
wesmjreback
authored andcommitted
CLN: grab bag of flake8 fixes
Author: Wes McKinney <[email protected]> Closes #12115 from wesm/style/flake8-misc and squashes the following commits: 017ca16 [Wes McKinney] CLN: grab bag of flake8 fixes
1 parent 2842a43 commit db0094d

24 files changed

+144
-86
lines changed

pandas/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pylint: disable-msg=W0614,W0401,W0611,W0622
22

3+
# flake8: noqa
34

45
__docformat__ = 'restructuredtext'
56

pandas/_version.py

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# This file is released into the public domain. Generated by
99
# versioneer-0.15 (https://github.com/warner/python-versioneer)
1010

11+
# flake8: noqa
12+
1113
import errno
1214
import os
1315
import re

pandas/compat/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
* platform checker
2626
"""
2727
# pylint disable=W0611
28+
# flake8: noqa
29+
2830
import functools
2931
import itertools
3032
from distutils.version import LooseVersion

pandas/compat/chainmap_impl.py

+22-8
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,19 @@ def __missing__(self, key):
5858
def __getitem__(self, key):
5959
for mapping in self.maps:
6060
try:
61-
return mapping[key] # can't use 'key in mapping' with defaultdict
61+
# can't use 'key in mapping' with defaultdict
62+
return mapping[key]
6263
except KeyError:
6364
pass
64-
return self.__missing__(key) # support subclasses that define __missing__
65+
# support subclasses that define __missing__
66+
return self.__missing__(key)
6567

6668
def get(self, key, default=None):
6769
return self[key] if key in self else default
6870

6971
def __len__(self):
70-
return len(set().union(*self.maps)) # reuses stored hash values if possible
72+
# reuses stored hash values if possible
73+
return len(set().union(*self.maps))
7174

7275
def __iter__(self):
7376
return iter(set().union(*self.maps))
@@ -89,7 +92,10 @@ def fromkeys(cls, iterable, *args):
8992
return cls(dict.fromkeys(iterable, *args))
9093

9194
def copy(self):
92-
'New ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]'
95+
"""
96+
New ChainMap or subclass with a new copy of maps[0] and refs to
97+
maps[1:]
98+
"""
9399
return self.__class__(self.maps[0].copy(), *self.maps[1:])
94100

95101
__copy__ = copy
@@ -115,21 +121,29 @@ def __delitem__(self, key):
115121
try:
116122
del self.maps[0][key]
117123
except KeyError:
118-
raise KeyError('Key not found in the first mapping: {!r}'.format(key))
124+
raise KeyError('Key not found in the first mapping: {!r}'
125+
.format(key))
119126

120127
def popitem(self):
121-
'Remove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.'
128+
"""
129+
Remove and return an item pair from maps[0]. Raise KeyError is maps[0]
130+
is empty.
131+
"""
122132
try:
123133
return self.maps[0].popitem()
124134
except KeyError:
125135
raise KeyError('No keys found in the first mapping.')
126136

127137
def pop(self, key, *args):
128-
'Remove *key* from maps[0] and return its value. Raise KeyError if *key* not in maps[0].'
138+
"""
139+
Remove *key* from maps[0] and return its value. Raise KeyError if
140+
*key* not in maps[0].
141+
"""
129142
try:
130143
return self.maps[0].pop(key, *args)
131144
except KeyError:
132-
raise KeyError('Key not found in the first mapping: {!r}'.format(key))
145+
raise KeyError('Key not found in the first mapping: {!r}'
146+
.format(key))
133147

134148
def clear(self):
135149
'Clear maps[0], leaving maps[1:] intact.'

pandas/compat/openpyxl_compat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ def is_compat(major_ver=1):
3232
return LooseVersion(stop_ver) <= ver
3333
else:
3434
raise ValueError('cannot test for openpyxl compatibility with ver {0}'
35-
.format(major_ver))
35+
.format(major_ver))

pandas/compat/pickle_compat.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
""" support pre 0.12 series pickle compatibility """
22

3+
# flake8: noqa
4+
35
import sys
46
import numpy as np
57
import pandas

pandas/computation/align.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ def _reconstruct_object(typ, obj, axes, dtype):
173173
ret_value = res_t.type(obj)
174174
else:
175175
ret_value = typ(obj).astype(res_t)
176-
# The condition is to distinguish 0-dim array (returned in case of scalar)
177-
# and 1 element array
176+
# The condition is to distinguish 0-dim array (returned in case of
177+
# scalar) and 1 element array
178178
# e.g. np.array(0) and np.array([0])
179179
if len(obj.shape) == 1 and len(obj) == 1:
180180
if not isinstance(ret_value, np.ndarray):

pandas/computation/api.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
# flake8: noqa
2+
13
from pandas.computation.eval import eval
24
from pandas.computation.expr import Expr

pandas/computation/engines.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
"""Engine classes for :func:`~pandas.eval`
22
"""
33

4+
# flake8: noqa
5+
46
import abc
57

68
from pandas import compat
79
from pandas.compat import DeepChainMap, map
810
from pandas.core import common as com
911
from pandas.computation.align import _align, _reconstruct_object
10-
from pandas.computation.ops import UndefinedVariableError, _mathops, _reductions
12+
from pandas.computation.ops import (UndefinedVariableError,
13+
_mathops, _reductions)
1114

1215

1316
_ne_builtins = frozenset(_mathops + _reductions)
@@ -30,8 +33,8 @@ def _check_ne_builtin_clash(expr):
3033

3134
if overlap:
3235
s = ', '.join(map(repr, overlap))
33-
raise NumExprClobberingError('Variables in expression "%s" overlap with '
34-
'numexpr builtins: (%s)' % (expr, s))
36+
raise NumExprClobberingError('Variables in expression "%s" '
37+
'overlap with builtins: (%s)' % (expr, s))
3538

3639

3740
class AbstractEngine(object):

pandas/computation/expr.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
"""
33

44
import ast
5-
import operator
6-
import sys
7-
import inspect
85
import tokenize
9-
import datetime
106

117
from functools import partial
128

@@ -21,7 +17,7 @@
2117
from pandas.computation.ops import _reductions, _mathops, _LOCAL_TAG
2218
from pandas.computation.ops import Op, BinOp, UnaryOp, Term, Constant, Div
2319
from pandas.computation.ops import UndefinedVariableError, FuncNode
24-
from pandas.computation.scope import Scope, _ensure_scope
20+
from pandas.computation.scope import Scope
2521

2622

2723
def tokenize_string(source):
@@ -381,9 +377,9 @@ def _possibly_evaluate_binop(self, op, op_class, lhs, rhs,
381377
rhs.type))
382378

383379
if self.engine != 'pytables':
384-
if (res.op in _cmp_ops_syms
385-
and getattr(lhs, 'is_datetime', False)
386-
or getattr(rhs, 'is_datetime', False)):
380+
if (res.op in _cmp_ops_syms and
381+
getattr(lhs, 'is_datetime', False) or
382+
getattr(rhs, 'is_datetime', False)):
387383
# all date ops must be done in python bc numexpr doesn't work
388384
# well with NaT
389385
return self._possibly_eval(res, self.binary_ops)
@@ -392,8 +388,8 @@ def _possibly_evaluate_binop(self, op, op_class, lhs, rhs,
392388
# "in"/"not in" ops are always evaluated in python
393389
return self._possibly_eval(res, eval_in_python)
394390
elif self.engine != 'pytables':
395-
if (getattr(lhs, 'return_type', None) == object
396-
or getattr(rhs, 'return_type', None) == object):
391+
if (getattr(lhs, 'return_type', None) == object or
392+
getattr(rhs, 'return_type', None) == object):
397393
# evaluate "==" and "!=" in python if either of our operands
398394
# has an object return type
399395
return self._possibly_eval(res, eval_in_python +
@@ -517,7 +513,8 @@ def visit_Attribute(self, node, **kwargs):
517513
raise ValueError("Invalid Attribute context {0}".format(ctx.__name__))
518514

519515
def visit_Call_35(self, node, side=None, **kwargs):
520-
""" in 3.5 the starargs attribute was changed to be more flexible, #11097 """
516+
""" in 3.5 the starargs attribute was changed to be more flexible,
517+
#11097 """
521518

522519
if isinstance(node.func, ast.Attribute):
523520
res = self.visit_Attribute(node.func)
@@ -541,7 +538,7 @@ def visit_Call_35(self, node, side=None, **kwargs):
541538

542539
if isinstance(res, FuncNode):
543540

544-
new_args = [ self.visit(arg) for arg in node.args ]
541+
new_args = [self.visit(arg) for arg in node.args]
545542

546543
if node.keywords:
547544
raise TypeError("Function \"{0}\" does not support keyword "
@@ -551,15 +548,17 @@ def visit_Call_35(self, node, side=None, **kwargs):
551548

552549
else:
553550

554-
new_args = [ self.visit(arg).value for arg in node.args ]
551+
new_args = [self.visit(arg).value for arg in node.args]
555552

556553
for key in node.keywords:
557554
if not isinstance(key, ast.keyword):
558555
raise ValueError("keyword error in function call "
559556
"'{0}'".format(node.func.id))
560557

561558
if key.arg:
562-
kwargs.append(ast.keyword(keyword.arg, self.visit(keyword.value)))
559+
# TODO: bug?
560+
kwargs.append(ast.keyword(
561+
keyword.arg, self.visit(keyword.value))) # noqa
563562

564563
return self.const_type(res(*new_args, **kwargs), self.env)
565564

pandas/computation/expressions.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
ver = ne.__version__
1717
_NUMEXPR_INSTALLED = ver >= LooseVersion('2.1')
1818
if not _NUMEXPR_INSTALLED:
19-
warnings.warn("The installed version of numexpr {ver} is not supported "
20-
"in pandas and will be not be used\nThe minimum supported "
21-
"version is 2.1\n".format(ver=ver), UserWarning)
19+
warnings.warn(
20+
"The installed version of numexpr {ver} is not supported "
21+
"in pandas and will be not be used\nThe minimum supported "
22+
"version is 2.1\n".format(ver=ver), UserWarning)
2223

2324
except ImportError: # pragma: no cover
2425
_NUMEXPR_INSTALLED = False
@@ -96,8 +97,8 @@ def _can_use_numexpr(op, op_str, a, b, dtype_check):
9697
return False
9798

9899

99-
def _evaluate_numexpr(op, op_str, a, b, raise_on_error=False, truediv=True, reversed=False,
100-
**eval_kwargs):
100+
def _evaluate_numexpr(op, op_str, a, b, raise_on_error=False, truediv=True,
101+
reversed=False, **eval_kwargs):
101102
result = None
102103

103104
if _can_use_numexpr(op, op_str, a, b, 'evaluate'):
@@ -106,7 +107,7 @@ def _evaluate_numexpr(op, op_str, a, b, raise_on_error=False, truediv=True, reve
106107
# we were originally called by a reversed op
107108
# method
108109
if reversed:
109-
a,b = b,a
110+
a, b = b, a
110111

111112
a_value = getattr(a, "values", a)
112113
b_value = getattr(b, "values", b)

pandas/computation/ops.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -498,12 +498,13 @@ def return_type(self):
498498
if operand.return_type == np.dtype('bool'):
499499
return np.dtype('bool')
500500
if (isinstance(operand, Op) and
501-
(operand.op in _cmp_ops_dict or operand.op in _bool_ops_dict)):
501+
(operand.op in _cmp_ops_dict or operand.op in _bool_ops_dict)):
502502
return np.dtype('bool')
503503
return np.dtype('int')
504504

505505

506506
class MathCall(Op):
507+
507508
def __init__(self, func, args):
508509
super(MathCall, self).__init__(func.name, args)
509510
self.func = func
@@ -518,9 +519,11 @@ def __unicode__(self):
518519

519520

520521
class FuncNode(object):
522+
521523
def __init__(self, name):
522524
if name not in _mathops:
523-
raise ValueError("\"{0}\" is not a supported function".format(name))
525+
raise ValueError(
526+
"\"{0}\" is not a supported function".format(name))
524527
self.name = name
525528
self.func = getattr(np, name)
526529

pandas/computation/pytables.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
from datetime import datetime, timedelta
88
import numpy as np
99
import pandas as pd
10-
from pandas.compat import u, string_types, PY3, DeepChainMap
10+
from pandas.compat import u, string_types, DeepChainMap
1111
from pandas.core.base import StringMixin
1212
import pandas.core.common as com
1313
from pandas.computation import expr, ops
1414
from pandas.computation.ops import is_term, UndefinedVariableError
15-
from pandas.computation.scope import _ensure_scope
1615
from pandas.computation.expr import BaseExprVisitor
1716
from pandas.computation.common import _ensure_decoded
1817
from pandas.tseries.timedeltas import _coerce_scalar_to_timedelta_type
@@ -147,17 +146,17 @@ def is_in_table(self):
147146
@property
148147
def kind(self):
149148
""" the kind of my field """
150-
return getattr(self.queryables.get(self.lhs),'kind',None)
149+
return getattr(self.queryables.get(self.lhs), 'kind', None)
151150

152151
@property
153152
def meta(self):
154153
""" the meta of my field """
155-
return getattr(self.queryables.get(self.lhs),'meta',None)
154+
return getattr(self.queryables.get(self.lhs), 'meta', None)
156155

157156
@property
158157
def metadata(self):
159158
""" the metadata of my field """
160-
return getattr(self.queryables.get(self.lhs),'metadata',None)
159+
return getattr(self.queryables.get(self.lhs), 'metadata', None)
161160

162161
def generate(self, v):
163162
""" create and return the op string for this TermValue """
@@ -195,7 +194,7 @@ def stringify(value):
195194
return TermValue(int(v), v, kind)
196195
elif meta == u('category'):
197196
metadata = com._values_from_object(self.metadata)
198-
result = metadata.searchsorted(v,side='left')
197+
result = metadata.searchsorted(v, side='left')
199198
return TermValue(result, result, u('integer'))
200199
elif kind == u('integer'):
201200
v = int(float(v))
@@ -504,7 +503,7 @@ def __init__(self, where, op=None, value=None, queryables=None,
504503
else:
505504
w = self.parse_back_compat(w)
506505
where[idx] = w
507-
where = ' & ' .join(["(%s)" % w for w in where])
506+
where = ' & ' .join(["(%s)" % w for w in where]) # noqa
508507

509508
self.expr = where
510509
self.env = Scope(scope_level + 1, local_dict=local_dict)
@@ -551,12 +550,14 @@ def parse_back_compat(self, w, op=None, value=None):
551550

552551
# stringify with quotes these values
553552
def convert(v):
554-
if isinstance(v, (datetime,np.datetime64,timedelta,np.timedelta64)) or hasattr(v, 'timetuple'):
553+
if (isinstance(v, (datetime, np.datetime64,
554+
timedelta, np.timedelta64)) or
555+
hasattr(v, 'timetuple')):
555556
return "'{0}'".format(v)
556557
return v
557558

558-
if isinstance(value, (list,tuple)):
559-
value = [ convert(v) for v in value ]
559+
if isinstance(value, (list, tuple)):
560+
value = [convert(v) for v in value]
560561
else:
561562
value = convert(value)
562563

0 commit comments

Comments
 (0)