|
22 | 22 | is_datetime64tz_dtype,
|
23 | 23 | is_datetime_or_timedelta_dtype,
|
24 | 24 | is_dtype_equal,
|
25 |
| - is_extension_array_dtype, |
26 | 25 | is_float_dtype,
|
27 | 26 | is_integer_dtype,
|
28 | 27 | is_list_like,
|
@@ -1230,29 +1229,17 @@ def __add__(self, other):
|
1230 | 1229 | if not is_period_dtype(self):
|
1231 | 1230 | maybe_integer_op_deprecated(self)
|
1232 | 1231 | result = self._addsub_int_array(other, operator.add)
|
1233 |
| - elif is_float_dtype(other): |
1234 |
| - # Explicitly catch invalid dtypes |
1235 |
| - raise TypeError( |
1236 |
| - "cannot add {dtype}-dtype to {cls}".format( |
1237 |
| - dtype=other.dtype, cls=type(self).__name__ |
1238 |
| - ) |
1239 |
| - ) |
1240 |
| - elif is_period_dtype(other): |
1241 |
| - # if self is a TimedeltaArray and other is a PeriodArray with |
1242 |
| - # a timedelta-like (i.e. Tick) freq, this operation is valid. |
1243 |
| - # Defer to the PeriodArray implementation. |
1244 |
| - # In remaining cases, this will end up raising TypeError. |
1245 |
| - return NotImplemented |
1246 |
| - elif is_extension_array_dtype(other): |
1247 |
| - # Categorical op will raise; defer explicitly |
1248 |
| - return NotImplemented |
1249 |
| - else: # pragma: no cover |
| 1232 | + else: |
| 1233 | + # Includes Categorical, other ExtensionArrays |
| 1234 | + # For PeriodDtype, if self is a TimedeltaArray and other is a |
| 1235 | + # PeriodArray with a timedelta-like (i.e. Tick) freq, this |
| 1236 | + # operation is valid. Defer to the PeriodArray implementation. |
| 1237 | + # In remaining cases, this will end up raising TypeError. |
1250 | 1238 | return NotImplemented
|
1251 | 1239 |
|
1252 | 1240 | if is_timedelta64_dtype(result) and isinstance(result, np.ndarray):
|
1253 | 1241 | from pandas.core.arrays import TimedeltaArray
|
1254 | 1242 |
|
1255 |
| - # TODO: infer freq? |
1256 | 1243 | return TimedeltaArray(result)
|
1257 | 1244 | return result
|
1258 | 1245 |
|
@@ -1302,29 +1289,13 @@ def __sub__(self, other):
|
1302 | 1289 | if not is_period_dtype(self):
|
1303 | 1290 | maybe_integer_op_deprecated(self)
|
1304 | 1291 | result = self._addsub_int_array(other, operator.sub)
|
1305 |
| - elif isinstance(other, ABCIndexClass): |
1306 |
| - raise TypeError( |
1307 |
| - "cannot subtract {cls} and {typ}".format( |
1308 |
| - cls=type(self).__name__, typ=type(other).__name__ |
1309 |
| - ) |
1310 |
| - ) |
1311 |
| - elif is_float_dtype(other): |
1312 |
| - # Explicitly catch invalid dtypes |
1313 |
| - raise TypeError( |
1314 |
| - "cannot subtract {dtype}-dtype from {cls}".format( |
1315 |
| - dtype=other.dtype, cls=type(self).__name__ |
1316 |
| - ) |
1317 |
| - ) |
1318 |
| - elif is_extension_array_dtype(other): |
1319 |
| - # Categorical op will raise; defer explicitly |
1320 |
| - return NotImplemented |
1321 |
| - else: # pragma: no cover |
| 1292 | + else: |
| 1293 | + # Includes ExtensionArrays, float_dtype |
1322 | 1294 | return NotImplemented
|
1323 | 1295 |
|
1324 | 1296 | if is_timedelta64_dtype(result) and isinstance(result, np.ndarray):
|
1325 | 1297 | from pandas.core.arrays import TimedeltaArray
|
1326 | 1298 |
|
1327 |
| - # TODO: infer freq? |
1328 | 1299 | return TimedeltaArray(result)
|
1329 | 1300 | return result
|
1330 | 1301 |
|
|
0 commit comments