Skip to content

Commit cda117d

Browse files
jbrockmendeljreback
authored andcommitted
REF: standardize usage with _make_wrapped_arith_op (#30623)
1 parent f501fda commit cda117d

File tree

4 files changed

+4
-36
lines changed

4 files changed

+4
-36
lines changed

pandas/core/indexes/datetimelike.py

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -512,39 +512,10 @@ def _convert_scalar_indexer(self, key, kind=None):
512512

513513
return super()._convert_scalar_indexer(key, kind=kind)
514514

515-
@classmethod
516-
def _add_datetimelike_methods(cls):
517-
"""
518-
Add in the datetimelike methods (as we may have to override the
519-
superclass).
520-
"""
521-
522-
def __add__(self, other):
523-
# dispatch to ExtensionArray implementation
524-
result = self._data.__add__(maybe_unwrap_index(other))
525-
return wrap_arithmetic_op(self, other, result)
526-
527-
cls.__add__ = __add__
528-
529-
def __radd__(self, other):
530-
# alias for __add__
531-
return self.__add__(other)
532-
533-
cls.__radd__ = __radd__
534-
535-
def __sub__(self, other):
536-
# dispatch to ExtensionArray implementation
537-
result = self._data.__sub__(maybe_unwrap_index(other))
538-
return wrap_arithmetic_op(self, other, result)
539-
540-
cls.__sub__ = __sub__
541-
542-
def __rsub__(self, other):
543-
result = self._data.__rsub__(maybe_unwrap_index(other))
544-
return wrap_arithmetic_op(self, other, result)
545-
546-
cls.__rsub__ = __rsub__
547-
515+
__add__ = _make_wrapped_arith_op("__add__")
516+
__radd__ = _make_wrapped_arith_op("__radd__")
517+
__sub__ = _make_wrapped_arith_op("__sub__")
518+
__rsub__ = _make_wrapped_arith_op("__rsub__")
548519
__pow__ = _make_wrapped_arith_op("__pow__")
549520
__rpow__ = _make_wrapped_arith_op("__rpow__")
550521
__mul__ = _make_wrapped_arith_op("__mul__")

pandas/core/indexes/datetimes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,6 @@ def indexer_between_time(
11651165
DatetimeIndex._add_comparison_ops()
11661166
DatetimeIndex._add_numeric_methods_disabled()
11671167
DatetimeIndex._add_logical_methods_disabled()
1168-
DatetimeIndex._add_datetimelike_methods()
11691168

11701169

11711170
def date_range(

pandas/core/indexes/period.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,6 @@ def memory_usage(self, deep=False):
845845
PeriodIndex._add_comparison_ops()
846846
PeriodIndex._add_numeric_methods_disabled()
847847
PeriodIndex._add_logical_methods_disabled()
848-
PeriodIndex._add_datetimelike_methods()
849848

850849

851850
def period_range(

pandas/core/indexes/timedeltas.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ def delete(self, loc):
507507

508508
TimedeltaIndex._add_comparison_ops()
509509
TimedeltaIndex._add_logical_methods_disabled()
510-
TimedeltaIndex._add_datetimelike_methods()
511510

512511

513512
def timedelta_range(

0 commit comments

Comments
 (0)