|
9 | 9 | from pandas._libs import algos as libalgos, index as libindex, lib
|
10 | 10 | import pandas._libs.join as libjoin
|
11 | 11 | from pandas._libs.lib import is_datetime_array
|
12 |
| -from pandas._libs.tslibs import OutOfBoundsDatetime, Timedelta, Timestamp |
| 12 | +from pandas._libs.tslibs import OutOfBoundsDatetime, Timestamp |
13 | 13 | from pandas._libs.tslibs.timezones import tz_compare
|
14 | 14 | from pandas.compat import set_function_name
|
15 | 15 | from pandas.compat.numpy import function as nv
|
|
55 | 55 | ABCPandasArray,
|
56 | 56 | ABCPeriodIndex,
|
57 | 57 | ABCSeries,
|
58 |
| - ABCTimedeltaArray, |
59 | 58 | ABCTimedeltaIndex,
|
60 | 59 | )
|
61 | 60 | from pandas.core.dtypes.missing import array_equivalent, isna
|
@@ -126,28 +125,8 @@ def cmp_method(self, other):
|
126 | 125 |
|
127 | 126 | def _make_arithmetic_op(op, cls):
|
128 | 127 | def index_arithmetic_method(self, other):
|
129 |
| - if isinstance(other, (ABCSeries, ABCDataFrame)): |
130 |
| - return NotImplemented |
131 |
| - elif isinstance(other, ABCTimedeltaIndex): |
132 |
| - # Defer to subclass implementation |
| 128 | + if isinstance(other, (ABCSeries, ABCDataFrame, ABCTimedeltaIndex)): |
133 | 129 | return NotImplemented
|
134 |
| - elif isinstance( |
135 |
| - other, (np.ndarray, ABCTimedeltaArray) |
136 |
| - ) and is_timedelta64_dtype(other): |
137 |
| - # GH#22390; wrap in Series for op, this will in turn wrap in |
138 |
| - # TimedeltaIndex, but will correctly raise TypeError instead of |
139 |
| - # NullFrequencyError for add/sub ops |
140 |
| - from pandas import Series |
141 |
| - |
142 |
| - other = Series(other) |
143 |
| - out = op(self, other) |
144 |
| - return Index(out, name=self.name) |
145 |
| - |
146 |
| - # handle time-based others |
147 |
| - if isinstance(other, (ABCDateOffset, np.timedelta64, timedelta)): |
148 |
| - return self._evaluate_with_timedelta_like(other, op) |
149 |
| - |
150 |
| - other = self._validate_for_numeric_binop(other, op) |
151 | 130 |
|
152 | 131 | from pandas import Series
|
153 | 132 |
|
@@ -5332,32 +5311,6 @@ def drop(self, labels, errors="raise"):
|
5332 | 5311 | # --------------------------------------------------------------------
|
5333 | 5312 | # Generated Arithmetic, Comparison, and Unary Methods
|
5334 | 5313 |
|
5335 |
| - def _evaluate_with_timedelta_like(self, other, op): |
5336 |
| - # Timedelta knows how to operate with np.array, so dispatch to that |
5337 |
| - # operation and then wrap the results |
5338 |
| - if self._is_numeric_dtype and op.__name__ in ["add", "sub", "radd", "rsub"]: |
5339 |
| - raise TypeError( |
5340 |
| - "Operation {opname} between {cls} and {other} " |
5341 |
| - "is invalid".format( |
5342 |
| - opname=op.__name__, cls=self.dtype, other=type(other).__name__ |
5343 |
| - ) |
5344 |
| - ) |
5345 |
| - |
5346 |
| - other = Timedelta(other) |
5347 |
| - values = self.values |
5348 |
| - |
5349 |
| - with np.errstate(all="ignore"): |
5350 |
| - result = op(values, other) |
5351 |
| - |
5352 |
| - attrs = self._get_attributes_dict() |
5353 |
| - attrs = self._maybe_update_attributes(attrs) |
5354 |
| - if op == divmod: |
5355 |
| - return Index(result[0], **attrs), Index(result[1], **attrs) |
5356 |
| - return Index(result, **attrs) |
5357 |
| - |
5358 |
| - def _evaluate_with_datetime_like(self, other, op): |
5359 |
| - raise TypeError("can only perform ops with datetime like values") |
5360 |
| - |
5361 | 5314 | @classmethod
|
5362 | 5315 | def _add_comparison_methods(cls):
|
5363 | 5316 | """
|
|
0 commit comments