|
33 | 33 | is_unsigned_integer_dtype,
|
34 | 34 | pandas_dtype,
|
35 | 35 | )
|
36 |
| -from pandas.core.dtypes.generic import ( |
37 |
| - ABCDataFrame, |
38 |
| - ABCIndexClass, |
39 |
| - ABCPeriodArray, |
40 |
| - ABCSeries, |
41 |
| -) |
| 36 | +from pandas.core.dtypes.generic import ABCIndexClass, ABCPeriodArray, ABCSeries |
42 | 37 | from pandas.core.dtypes.inference import is_array_like
|
43 | 38 | from pandas.core.dtypes.missing import is_valid_nat_for_dtype, isna
|
44 | 39 |
|
45 | 40 | from pandas._typing import DatetimeLikeScalar
|
46 | 41 | from pandas.core import missing, nanops
|
47 | 42 | from pandas.core.algorithms import checked_add_with_arr, take, unique1d, value_counts
|
48 | 43 | import pandas.core.common as com
|
| 44 | +from pandas.core.ops.common import unpack_zerodim_and_defer |
49 | 45 | from pandas.core.ops.invalid import make_invalid_op
|
50 | 46 |
|
51 | 47 | from pandas.tseries import frequencies
|
@@ -1194,13 +1190,11 @@ def _time_shift(self, periods, freq=None):
|
1194 | 1190 | # to be passed explicitly.
|
1195 | 1191 | return self._generate_range(start=start, end=end, periods=None, freq=self.freq)
|
1196 | 1192 |
|
| 1193 | + @unpack_zerodim_and_defer("__add__") |
1197 | 1194 | def __add__(self, other):
|
1198 |
| - other = lib.item_from_zerodim(other) |
1199 |
| - if isinstance(other, (ABCSeries, ABCDataFrame, ABCIndexClass)): |
1200 |
| - return NotImplemented |
1201 | 1195 |
|
1202 | 1196 | # scalar others
|
1203 |
| - elif other is NaT: |
| 1197 | + if other is NaT: |
1204 | 1198 | result = self._add_nat()
|
1205 | 1199 | elif isinstance(other, (Tick, timedelta, np.timedelta64)):
|
1206 | 1200 | result = self._add_delta(other)
|
@@ -1248,13 +1242,11 @@ def __radd__(self, other):
|
1248 | 1242 | # alias for __add__
|
1249 | 1243 | return self.__add__(other)
|
1250 | 1244 |
|
| 1245 | + @unpack_zerodim_and_defer("__sub__") |
1251 | 1246 | def __sub__(self, other):
|
1252 |
| - other = lib.item_from_zerodim(other) |
1253 |
| - if isinstance(other, (ABCSeries, ABCDataFrame, ABCIndexClass)): |
1254 |
| - return NotImplemented |
1255 | 1247 |
|
1256 | 1248 | # scalar others
|
1257 |
| - elif other is NaT: |
| 1249 | + if other is NaT: |
1258 | 1250 | result = self._sub_nat()
|
1259 | 1251 | elif isinstance(other, (Tick, timedelta, np.timedelta64)):
|
1260 | 1252 | result = self._add_delta(-other)
|
@@ -1343,11 +1335,11 @@ def __rsub__(self, other):
|
1343 | 1335 | return -(self - other)
|
1344 | 1336 |
|
1345 | 1337 | # FIXME: DTA/TDA/PA inplace methods should actually be inplace, GH#24115
|
1346 |
| - def __iadd__(self, other): |
| 1338 | + def __iadd__(self, other): # type: ignore |
1347 | 1339 | # alias for __add__
|
1348 | 1340 | return self.__add__(other)
|
1349 | 1341 |
|
1350 |
| - def __isub__(self, other): |
| 1342 | + def __isub__(self, other): # type: ignore |
1351 | 1343 | # alias for __sub__
|
1352 | 1344 | return self.__sub__(other)
|
1353 | 1345 |
|
|
0 commit comments