Skip to content

Commit 2e041b9

Browse files
committed
raise TypeError when "-" is used between DateTimeArray
1 parent e5b75f0 commit 2e041b9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pandas/core/arrays/datetimelike.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import warnings
1919

2020
import numpy as np
21+
import pandas
2122

2223
from pandas._config import using_string_dtype
2324
from pandas._config.config import get_option
@@ -1488,7 +1489,11 @@ def __rsub__(self, other):
14881489
return (-self) + other
14891490

14901491
# We get here with e.g. datetime objects
1491-
return -(self - other)
1492+
datetime_result = self - other
1493+
if isinstance(datetime_result, pandas.core.arrays.datetimes.DatetimeArray):
1494+
raise TypeError("TypeError: unsupported operand type(s) for -: "
1495+
f"'{type(self).__name__}' and '{type(other).__name__}'")
1496+
return -(datetime_result)
14921497

14931498
def __iadd__(self, other) -> Self:
14941499
result = self + other

0 commit comments

Comments
 (0)