|
1 | 1 | # Arithmetic tests for DataFrame/Series/Index/Array classes that should
|
2 | 2 | # behave identically.
|
3 | 3 | # Specifically for datetime64 and datetime64tz dtypes
|
4 |
| -from datetime import datetime, timedelta |
| 4 | +from datetime import datetime, time, timedelta |
5 | 5 | from itertools import product, starmap
|
6 | 6 | import operator
|
7 | 7 | import warnings
|
@@ -1032,6 +1032,8 @@ def test_dt64arr_add_timestamp_raises(self, box_with_array):
|
1032 | 1032 | np.array([2.0, 3.0]),
|
1033 | 1033 | # GH#13078 datetime +/- Period is invalid
|
1034 | 1034 | pd.Period("2011-01-01", freq="D"),
|
| 1035 | + # https://github.com/pandas-dev/pandas/issues/10329 |
| 1036 | + time(1, 2, 3), |
1035 | 1037 | ],
|
1036 | 1038 | )
|
1037 | 1039 | @pytest.mark.parametrize("dti_freq", [None, "D"])
|
@@ -1069,6 +1071,60 @@ def test_dt64arr_add_sub_parr(
|
1069 | 1071 | )
|
1070 | 1072 | assert_invalid_addsub_type(dtarr, parr, msg)
|
1071 | 1073 |
|
| 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 | + |
1072 | 1128 |
|
1073 | 1129 | class TestDatetime64DateOffsetArithmetic:
|
1074 | 1130 |
|
|
0 commit comments