Skip to content

Commit a4a71f8

Browse files
committed
CLN: PEP8 cleanup
1 parent 4718ffe commit a4a71f8

33 files changed

+1743
-1185
lines changed

pandas/compat/__init__.py

+63-60
Large diffs are not rendered by default.

pandas/compat/pickle_compat.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pandas.core.series import Series, TimeSeries
1010
from pandas.sparse.series import SparseSeries, SparseTimeSeries
1111

12+
1213
def load_reduce(self):
1314
stack = self.stack
1415
args = stack.pop()
@@ -18,7 +19,8 @@ def load_reduce(self):
1819
if n == u('DeprecatedSeries') or n == u('DeprecatedTimeSeries'):
1920
stack[-1] = object.__new__(Series)
2021
return
21-
elif n == u('DeprecatedSparseSeries') or n == u('DeprecatedSparseTimeSeries'):
22+
elif (n == u('DeprecatedSparseSeries') or
23+
n == u('DeprecatedSparseTimeSeries')):
2224
stack[-1] = object.__new__(SparseSeries)
2325
return
2426

@@ -28,7 +30,9 @@ def load_reduce(self):
2830

2931
# try to reencode the arguments
3032
if self.encoding is not None:
31-
args = tuple([ arg.encode(self.encoding) if isinstance(arg, string_types) else arg for arg in args ])
33+
args = tuple([arg.encode(self.encoding)
34+
if isinstance(arg, string_types)
35+
else arg for arg in args])
3236
try:
3337
stack[-1] = func(*args)
3438
return
@@ -51,9 +55,9 @@ class Unpickler(pkl.Unpickler):
5155

5256
Unpickler.dispatch[pkl.REDUCE[0]] = load_reduce
5357

58+
5459
def load(fh, encoding=None, compat=False, is_verbose=False):
55-
"""
56-
load a pickle, with a provided encoding
60+
"""load a pickle, with a provided encoding
5761
5862
if compat is True:
5963
fake the old class hierarchy
@@ -90,14 +94,18 @@ def load(fh, encoding=None, compat=False, is_verbose=False):
9094
pandas.sparse.series.SparseSeries = SparseSeries
9195
pandas.sparse.series.SparseTimeSeries = SparseTimeSeries
9296

97+
9398
class DeprecatedSeries(np.ndarray, Series):
9499
pass
95100

101+
96102
class DeprecatedTimeSeries(DeprecatedSeries):
97103
pass
98104

105+
99106
class DeprecatedSparseSeries(DeprecatedSeries):
100107
pass
101108

109+
102110
class DeprecatedSparseTimeSeries(DeprecatedSparseSeries):
103111
pass

pandas/compat/scipy.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88

99
def scoreatpercentile(a, per, limit=(), interpolation_method='fraction'):
10-
"""
11-
Calculate the score at the given `per` percentile of the sequence `a`.
10+
"""Calculate the score at the given `per` percentile of the sequence `a`.
1211
1312
For example, the score at `per=50` is the median. If the desired quantile
1413
lies between two data points, we interpolate between them, according to
@@ -65,7 +64,7 @@ def scoreatpercentile(a, per, limit=(), interpolation_method='fraction'):
6564
values = values[(limit[0] <= values) & (values <= limit[1])]
6665

6766
idx = per / 100. * (values.shape[0] - 1)
68-
if (idx % 1 == 0):
67+
if idx % 1 == 0:
6968
score = values[idx]
7069
else:
7170
if interpolation_method == 'fraction':
@@ -153,8 +152,7 @@ def fastsort(a):
153152

154153

155154
def percentileofscore(a, score, kind='rank'):
156-
'''
157-
The percentile rank of a score relative to a list of scores.
155+
"""The percentile rank of a score relative to a list of scores.
158156
159157
A `percentileofscore` of, for example, 80% means that 80% of the
160158
scores in `a` are below the given score. In the case of gaps or
@@ -217,7 +215,7 @@ def percentileofscore(a, score, kind='rank'):
217215
>>> percentileofscore([1, 2, 3, 3, 4], 3, kind='mean')
218216
60.0
219217
220-
'''
218+
"""
221219
a = np.array(a)
222220
n = len(a)
223221

pandas/computation/align.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def wrapper(terms):
101101

102102
@_filter_special_cases
103103
def _align_core(terms):
104-
term_index = [i for i, term in enumerate(terms) if hasattr(term.value,
105-
'axes')]
104+
term_index = [i for i, term in enumerate(terms)
105+
if hasattr(term.value, 'axes')]
106106
term_dims = [terms[i].value.ndim for i in term_index]
107107
ndims = pd.Series(dict(zip(term_index, term_dims)))
108108

@@ -139,10 +139,10 @@ def _align_core(terms):
139139

140140
ordm = np.log10(abs(reindexer_size - term_axis_size))
141141
if ordm >= 1 and reindexer_size >= 10000:
142-
warnings.warn("Alignment difference on axis {0} is larger"
143-
" than an order of magnitude on term {1!r}, "
144-
"by more than {2:.4g}; performance may suffer"
145-
"".format(axis, terms[i].name, ordm),
142+
warnings.warn('Alignment difference on axis {0} is larger '
143+
'than an order of magnitude on term {1!r}, '
144+
'by more than {2:.4g}; performance may '
145+
'suffer'.format(axis, terms[i].name, ordm),
146146
category=pd.io.common.PerformanceWarning)
147147

148148
if transpose:
@@ -237,7 +237,7 @@ def _reconstruct_object(typ, obj, axes, dtype):
237237
res_t = dtype
238238

239239
if (not isinstance(typ, partial) and
240-
issubclass(typ, pd.core.generic.PandasObject)):
240+
issubclass(typ, pd.core.generic.PandasObject)):
241241
return typ(obj, dtype=res_t, **axes)
242242

243243
# special case for pathological things like ~True/~False

pandas/computation/expr.py

+19-17
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ class Scope(StringMixin):
9191
__slots__ = ('globals', 'locals', 'resolvers', '_global_resolvers',
9292
'resolver_keys', '_resolver', 'level', 'ntemps', 'target')
9393

94-
def __init__(self, gbls=None, lcls=None, level=1, resolvers=None, target=None):
94+
def __init__(self, gbls=None, lcls=None, level=1, resolvers=None,
95+
target=None):
9596
self.level = level
9697
self.resolvers = tuple(resolvers or [])
9798
self.globals = dict()
@@ -133,11 +134,12 @@ def __init__(self, gbls=None, lcls=None, level=1, resolvers=None, target=None):
133134
self.resolver_dict.update(dict(o))
134135

135136
def __unicode__(self):
136-
return com.pprint_thing("locals: {0}\nglobals: {0}\nresolvers: "
137-
"{0}\ntarget: {0}".format(list(self.locals.keys()),
138-
list(self.globals.keys()),
139-
list(self.resolver_keys),
140-
self.target))
137+
return com.pprint_thing(
138+
'locals: {0}\nglobals: {0}\nresolvers: '
139+
'{0}\ntarget: {0}'.format(list(self.locals.keys()),
140+
list(self.globals.keys()),
141+
list(self.resolver_keys),
142+
self.target))
141143

142144
def __getitem__(self, key):
143145
return self.resolve(key, globally=False)
@@ -499,9 +501,8 @@ def _possibly_evaluate_binop(self, op, op_class, lhs, rhs,
499501
maybe_eval_in_python=('==', '!=')):
500502
res = op(lhs, rhs)
501503

502-
if (res.op in _cmp_ops_syms and
503-
lhs.is_datetime or rhs.is_datetime and
504-
self.engine != 'pytables'):
504+
if (res.op in _cmp_ops_syms and lhs.is_datetime or rhs.is_datetime and
505+
self.engine != 'pytables'):
505506
# all date ops must be done in python bc numexpr doesn't work well
506507
# with NaT
507508
return self._possibly_eval(res, self.binary_ops)
@@ -594,18 +595,20 @@ def visit_Assign(self, node, **kwargs):
594595
if len(node.targets) != 1:
595596
raise SyntaxError('can only assign a single expression')
596597
if not isinstance(node.targets[0], ast.Name):
597-
raise SyntaxError('left hand side of an assignment must be a single name')
598+
raise SyntaxError('left hand side of an assignment must be a '
599+
'single name')
598600
if self.env.target is None:
599601
raise ValueError('cannot assign without a target object')
600602

601603
try:
602604
assigner = self.visit(node.targets[0], **kwargs)
603-
except (UndefinedVariableError):
605+
except UndefinedVariableError:
604606
assigner = node.targets[0].id
605607

606-
self.assigner = getattr(assigner,'name',assigner)
608+
self.assigner = getattr(assigner, 'name', assigner)
607609
if self.assigner is None:
608-
raise SyntaxError('left hand side of an assignment must be a single resolvable name')
610+
raise SyntaxError('left hand side of an assignment must be a '
611+
'single resolvable name')
609612

610613
return self.visit(node.value, **kwargs)
611614

@@ -622,7 +625,7 @@ def visit_Attribute(self, node, **kwargs):
622625
name = self.env.add_tmp(v)
623626
return self.term_type(name, self.env)
624627
except AttributeError:
625-
# something like datetime.datetime where scope is overriden
628+
# something like datetime.datetime where scope is overridden
626629
if isinstance(value, ast.Name) and value.id == attr:
627630
return resolved
628631

@@ -699,8 +702,7 @@ def visitor(x, y):
699702
return reduce(visitor, operands)
700703

701704

702-
_python_not_supported = frozenset(['Dict', 'Call', 'BoolOp',
703-
'In', 'NotIn'])
705+
_python_not_supported = frozenset(['Dict', 'Call', 'BoolOp', 'In', 'NotIn'])
704706
_numexpr_supported_calls = frozenset(_reductions + _mathops)
705707

706708

@@ -744,7 +746,7 @@ def __init__(self, expr, engine='numexpr', parser='pandas', env=None,
744746

745747
@property
746748
def assigner(self):
747-
return getattr(self._visitor,'assigner',None)
749+
return getattr(self._visitor, 'assigner', None)
748750

749751
def __call__(self):
750752
self.env.locals['truediv'] = self.truediv

pandas/computation/expressions.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Expressions
33
-----------
44
5-
Offer fast expression evaluation thru numexpr
5+
Offer fast expression evaluation through numexpr
66
77
"""
88

@@ -22,9 +22,10 @@
2222
_where = None
2323

2424
# the set of dtypes that we will allow pass to numexpr
25-
_ALLOWED_DTYPES = dict(
26-
evaluate=set(['int64', 'int32', 'float64', 'float32', 'bool']),
27-
where=set(['int64', 'float64', 'bool']))
25+
_ALLOWED_DTYPES = {
26+
'evaluate': set(['int64', 'int32', 'float64', 'float32', 'bool']),
27+
'where': set(['int64', 'float64', 'bool'])
28+
}
2829

2930
# the minimum prod shape that we will use numexpr
3031
_MIN_ELEMENTS = 10000
@@ -100,10 +101,10 @@ def _evaluate_numexpr(op, op_str, a, b, raise_on_error=False, truediv=True,
100101
'b_value': b_value},
101102
casting='safe', truediv=truediv,
102103
**eval_kwargs)
103-
except (ValueError) as detail:
104+
except ValueError as detail:
104105
if 'unknown type object' in str(detail):
105106
pass
106-
except (Exception) as detail:
107+
except Exception as detail:
107108
if raise_on_error:
108109
raise
109110

@@ -135,10 +136,10 @@ def _where_numexpr(cond, a, b, raise_on_error=False):
135136
'a_value': a_value,
136137
'b_value': b_value},
137138
casting='safe')
138-
except (ValueError) as detail:
139+
except ValueError as detail:
139140
if 'unknown type object' in str(detail):
140141
pass
141-
except (Exception) as detail:
142+
except Exception as detail:
142143
if raise_on_error:
143144
raise TypeError(str(detail))
144145

pandas/computation/ops.py

-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ def name(self):
207207
return self.value
208208

209209

210-
211210
_bool_op_map = {'not': '~', 'and': '&', 'or': '|'}
212211

213212

0 commit comments

Comments
 (0)