Skip to content

Commit a44ac34

Browse files
authored
TST: Added regression test (#31538)
1 parent 4521308 commit a44ac34

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

pandas/tests/arithmetic/test_datetime64.py

+57-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Arithmetic tests for DataFrame/Series/Index/Array classes that should
22
# behave identically.
33
# Specifically for datetime64 and datetime64tz dtypes
4-
from datetime import datetime, timedelta
4+
from datetime import datetime, time, timedelta
55
from itertools import product, starmap
66
import operator
77
import warnings
@@ -1032,6 +1032,8 @@ def test_dt64arr_add_timestamp_raises(self, box_with_array):
10321032
np.array([2.0, 3.0]),
10331033
# GH#13078 datetime +/- Period is invalid
10341034
pd.Period("2011-01-01", freq="D"),
1035+
# https://github.com/pandas-dev/pandas/issues/10329
1036+
time(1, 2, 3),
10351037
],
10361038
)
10371039
@pytest.mark.parametrize("dti_freq", [None, "D"])
@@ -1069,6 +1071,60 @@ def test_dt64arr_add_sub_parr(
10691071
)
10701072
assert_invalid_addsub_type(dtarr, parr, msg)
10711073

1074+
def test_dt64arr_addsub_time_objects_raises(self, box_with_array, tz_naive_fixture):
1075+
# https://github.com/pandas-dev/pandas/issues/10329
1076+
1077+
tz = tz_naive_fixture
1078+
1079+
obj1 = pd.date_range("2012-01-01", periods=3, tz=tz)
1080+
obj2 = [time(i, i, i) for i in range(3)]
1081+
1082+
obj1 = tm.box_expected(obj1, box_with_array)
1083+
obj2 = tm.box_expected(obj2, box_with_array)
1084+
1085+
with warnings.catch_warnings(record=True):
1086+
# pandas.errors.PerformanceWarning: Non-vectorized DateOffset being
1087+
# applied to Series or DatetimeIndex
1088+
# we aren't testing that here, so ignore.
1089+
warnings.simplefilter("ignore", PerformanceWarning)
1090+
1091+
# If `x + y` raises, then `y + x` should raise here as well
1092+
1093+
msg = (
1094+
r"unsupported operand type\(s\) for -: "
1095+
"'(Timestamp|DatetimeArray)' and 'datetime.time'"
1096+
)
1097+
with pytest.raises(TypeError, match=msg):
1098+
obj1 - obj2
1099+
1100+
msg = "|".join(
1101+
[
1102+
"cannot subtract DatetimeArray from ndarray",
1103+
"ufunc (subtract|'subtract') cannot use operands with types "
1104+
r"dtype\('O'\) and dtype\('<M8\[ns\]'\)",
1105+
]
1106+
)
1107+
with pytest.raises(TypeError, match=msg):
1108+
obj2 - obj1
1109+
1110+
msg = (
1111+
r"unsupported operand type\(s\) for \+: "
1112+
"'(Timestamp|DatetimeArray)' and 'datetime.time'"
1113+
)
1114+
with pytest.raises(TypeError, match=msg):
1115+
obj1 + obj2
1116+
1117+
msg = "|".join(
1118+
[
1119+
r"unsupported operand type\(s\) for \+: "
1120+
"'(Timestamp|DatetimeArray)' and 'datetime.time'",
1121+
"ufunc (add|'add') cannot use operands with types "
1122+
r"dtype\('O'\) and dtype\('<M8\[ns\]'\)",
1123+
]
1124+
)
1125+
with pytest.raises(TypeError, match=msg):
1126+
obj2 + obj1
1127+
10721128

10731129
class TestDatetime64DateOffsetArithmetic:
10741130

0 commit comments

Comments
 (0)