Skip to content

Commit d3e65a4

Browse files
jbrockmendeljreback
authored andcommitted
small cleanups aggregated (#19328)
1 parent 1245f06 commit d3e65a4

File tree

3 files changed

+17
-48
lines changed

3 files changed

+17
-48
lines changed

pandas/core/indexes/base.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66
from pandas._libs import (lib, index as libindex, tslib as libts,
77
algos as libalgos, join as libjoin,
8-
Timestamp, Timedelta, )
8+
Timestamp)
99
from pandas._libs.lib import is_datetime_array
1010

1111
from pandas.compat import range, u, set_function_name
@@ -3979,7 +3979,7 @@ def _validate_for_numeric_binop(self, other, op, opstr):
39793979
internal method called by ops
39803980
"""
39813981
# if we are an inheritor of numeric,
3982-
# but not actually numeric (e.g. DatetimeIndex/PeriodInde)
3982+
# but not actually numeric (e.g. DatetimeIndex/PeriodIndex)
39833983
if not self._is_numeric_dtype:
39843984
raise TypeError("cannot evaluate a numeric op {opstr} "
39853985
"for type: {typ}".format(
@@ -4006,7 +4006,7 @@ def _validate_for_numeric_binop(self, other, op, opstr):
40064006
raise TypeError("cannot evaluate a numeric op "
40074007
"with a non-numeric dtype")
40084008
elif isinstance(other, (ABCDateOffset, np.timedelta64,
4009-
Timedelta, datetime.timedelta)):
4009+
datetime.timedelta)):
40104010
# higher up to handle
40114011
pass
40124012
elif isinstance(other, (Timestamp, np.datetime64)):
@@ -4031,13 +4031,13 @@ def _evaluate_numeric_binop(self, other):
40314031

40324032
# handle time-based others
40334033
if isinstance(other, (ABCDateOffset, np.timedelta64,
4034-
Timedelta, datetime.timedelta)):
4034+
datetime.timedelta)):
40354035
return self._evaluate_with_timedelta_like(other, op, opstr,
40364036
reversed)
40374037
elif isinstance(other, (Timestamp, np.datetime64)):
40384038
return self._evaluate_with_datetime_like(other, op, opstr)
40394039

4040-
# if we are a reversed non-communative op
4040+
# if we are a reversed non-commutative op
40414041
values = self.values
40424042
if reversed:
40434043
values, other = other, values
@@ -4081,11 +4081,8 @@ def _evaluate_numeric_binop(self, other):
40814081
cls.__divmod__ = _make_evaluate_binop(
40824082
divmod,
40834083
'__divmod__',
4084-
constructor=lambda result, **attrs: (
4085-
Index(result[0], **attrs),
4086-
Index(result[1], **attrs),
4087-
),
4088-
)
4084+
constructor=lambda result, **attrs: (Index(result[0], **attrs),
4085+
Index(result[1], **attrs)))
40894086

40904087
@classmethod
40914088
def _add_numeric_methods_unary(cls):
@@ -4275,8 +4272,7 @@ def _ensure_index(index_like, copy=False):
42754272
def _get_na_value(dtype):
42764273
if is_datetime64_any_dtype(dtype) or is_timedelta64_dtype(dtype):
42774274
return libts.NaT
4278-
return {np.datetime64: libts.NaT,
4279-
np.timedelta64: libts.NaT}.get(dtype, np.nan)
4275+
return np.nan
42804276

42814277

42824278
def _ensure_has_len(seq):

pandas/core/indexes/range.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ def _evaluate_numeric_binop(self, other):
595595
self, other = other, self
596596

597597
try:
598-
# alppy if we have an override
598+
# apply if we have an override
599599
if step:
600600
with np.errstate(all='ignore'):
601601
rstep = step(self._step, other)

pandas/core/ops.py

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,7 @@ def names(x):
150150
return new_methods
151151

152152

153-
def add_methods(cls, new_methods, force, select, exclude):
154-
if select and exclude:
155-
raise TypeError("May only pass either select or exclude")
156-
157-
if select:
158-
select = set(select)
159-
methods = {}
160-
for key, method in new_methods.items():
161-
if key in select:
162-
methods[key] = method
163-
new_methods = methods
164-
165-
if exclude:
166-
for k in exclude:
167-
new_methods.pop(k, None)
168-
153+
def add_methods(cls, new_methods, force):
169154
for name, method in new_methods.items():
170155
if force or name not in cls.__dict__:
171156
bind_method(cls, name, method)
@@ -175,8 +160,8 @@ def add_methods(cls, new_methods, force, select, exclude):
175160
# Arithmetic
176161
def add_special_arithmetic_methods(cls, arith_method=None,
177162
comp_method=None, bool_method=None,
178-
use_numexpr=True, force=False, select=None,
179-
exclude=None, have_divmod=False):
163+
use_numexpr=True, force=False,
164+
have_divmod=False):
180165
"""
181166
Adds the full suite of special arithmetic methods (``__add__``,
182167
``__sub__``, etc.) to the class.
@@ -195,10 +180,6 @@ def add_special_arithmetic_methods(cls, arith_method=None,
195180
force : bool, default False
196181
if False, checks whether function is defined **on ``cls.__dict__``**
197182
before defining if True, always defines functions on class base
198-
select : iterable of strings (optional)
199-
if passed, only sets functions with names in select
200-
exclude : iterable of strings (optional)
201-
if passed, will not set functions with names in exclude
202183
have_divmod : bool, (optional)
203184
should a divmod method be added? this method is special because it
204185
returns a tuple of cls instead of a single element of type cls
@@ -247,14 +228,12 @@ def f(self, other):
247228
__ior__=_wrap_inplace_method(new_methods["__or__"]),
248229
__ixor__=_wrap_inplace_method(new_methods["__xor__"])))
249230

250-
add_methods(cls, new_methods=new_methods, force=force, select=select,
251-
exclude=exclude)
231+
add_methods(cls, new_methods=new_methods, force=force)
252232

253233

254234
def add_flex_arithmetic_methods(cls, flex_arith_method,
255235
flex_comp_method=None, flex_bool_method=None,
256-
use_numexpr=True, force=False, select=None,
257-
exclude=None):
236+
use_numexpr=True, force=False):
258237
"""
259238
Adds the full suite of flex arithmetic methods (``pow``, ``mul``, ``add``)
260239
to the class.
@@ -271,10 +250,6 @@ def add_flex_arithmetic_methods(cls, flex_arith_method,
271250
force : bool, default False
272251
if False, checks whether function is defined **on ``cls.__dict__``**
273252
before defining if True, always defines functions on class base
274-
select : iterable of strings (optional)
275-
if passed, only sets functions with names in select
276-
exclude : iterable of strings (optional)
277-
if passed, will not set functions with names in exclude
278253
"""
279254
# in frame, default axis is 'columns', doesn't matter for series and panel
280255
new_methods = _create_methods(flex_arith_method,
@@ -289,8 +264,7 @@ def add_flex_arithmetic_methods(cls, flex_arith_method,
289264
if k in new_methods:
290265
new_methods.pop(k)
291266

292-
add_methods(cls, new_methods=new_methods, force=force, select=select,
293-
exclude=exclude)
267+
add_methods(cls, new_methods=new_methods, force=force)
294268

295269

296270
def _align_method_SERIES(left, right, align_asobject=False):
@@ -389,16 +363,16 @@ def wrapper(left, right, name=name, na_op=na_op):
389363
return NotImplemented
390364

391365
left, right = _align_method_SERIES(left, right)
366+
res_name = _get_series_op_result_name(left, right)
367+
392368
if is_datetime64_dtype(left) or is_datetime64tz_dtype(left):
393369
result = dispatch_to_index_op(op, left, right, pd.DatetimeIndex)
394-
res_name = _get_series_op_result_name(left, right)
395370
return construct_result(left, result,
396371
index=left.index, name=res_name,
397372
dtype=result.dtype)
398373

399374
elif is_timedelta64_dtype(left):
400375
result = dispatch_to_index_op(op, left, right, pd.TimedeltaIndex)
401-
res_name = _get_series_op_result_name(left, right)
402376
return construct_result(left, result,
403377
index=left.index, name=res_name,
404378
dtype=result.dtype)
@@ -409,7 +383,6 @@ def wrapper(left, right, name=name, na_op=na_op):
409383
rvalues = getattr(rvalues, 'values', rvalues)
410384

411385
result = safe_na_op(lvalues, rvalues)
412-
res_name = _get_series_op_result_name(left, right)
413386
return construct_result(left, result,
414387
index=left.index, name=res_name, dtype=None)
415388

0 commit comments

Comments
 (0)