-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TST: Added regression test #31538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TST: Added regression test #31538
Changes from all commits
aa5dc3b
270dfee
5691066
2cf0756
33e24a3
bc75e25
20ba781
94cedb9
1cafb66
a5608eb
fd04076
1d17645
c454822
faf90e1
5cdd1d1
6fef7f8
799ae78
54ea5a0
808599b
0db9073
d62cad3
1449d8c
c5dc76c
6d2e72f
5742c46
951074f
fbce136
5954709
f51559f
e183a23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Arithmetic tests for DataFrame/Series/Index/Array classes that should | ||
# behave identically. | ||
# Specifically for datetime64 and datetime64tz dtypes | ||
from datetime import datetime, timedelta | ||
from datetime import datetime, time, timedelta | ||
from itertools import product, starmap | ||
import operator | ||
import warnings | ||
|
@@ -1032,6 +1032,8 @@ def test_dt64arr_add_timestamp_raises(self, box_with_array): | |
np.array([2.0, 3.0]), | ||
# GH#13078 datetime +/- Period is invalid | ||
pd.Period("2011-01-01", freq="D"), | ||
# https://github.com/pandas-dev/pandas/issues/10329 | ||
time(1, 2, 3), | ||
], | ||
) | ||
@pytest.mark.parametrize("dti_freq", [None, "D"]) | ||
|
@@ -1069,6 +1071,60 @@ def test_dt64arr_add_sub_parr( | |
) | ||
assert_invalid_addsub_type(dtarr, parr, msg) | ||
|
||
def test_dt64arr_addsub_time_objects_raises(self, box_with_array, tz_naive_fixture): | ||
# https://github.com/pandas-dev/pandas/issues/10329 | ||
|
||
tz = tz_naive_fixture | ||
|
||
obj1 = pd.date_range("2012-01-01", periods=3, tz=tz) | ||
obj2 = [time(i, i, i) for i in range(3)] | ||
|
||
obj1 = tm.box_expected(obj1, box_with_array) | ||
obj2 = tm.box_expected(obj2, box_with_array) | ||
|
||
with warnings.catch_warnings(record=True): | ||
jbrockmendel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# pandas.errors.PerformanceWarning: Non-vectorized DateOffset being | ||
# applied to Series or DatetimeIndex | ||
# we aren't testing that here, so ignore. | ||
warnings.simplefilter("ignore", PerformanceWarning) | ||
|
||
# If `x + y` raises, then `y + x` should raise here as well | ||
|
||
msg = ( | ||
r"unsupported operand type\(s\) for -: " | ||
"'(Timestamp|DatetimeArray)' and 'datetime.time'" | ||
) | ||
with pytest.raises(TypeError, match=msg): | ||
obj1 - obj2 | ||
|
||
msg = "|".join( | ||
[ | ||
"cannot subtract DatetimeArray from ndarray", | ||
"ufunc (subtract|'subtract') cannot use operands with types " | ||
r"dtype\('O'\) and dtype\('<M8\[ns\]'\)", | ||
] | ||
) | ||
with pytest.raises(TypeError, match=msg): | ||
obj2 - obj1 | ||
|
||
msg = ( | ||
r"unsupported operand type\(s\) for \+: " | ||
"'(Timestamp|DatetimeArray)' and 'datetime.time'" | ||
) | ||
with pytest.raises(TypeError, match=msg): | ||
obj1 + obj2 | ||
|
||
msg = "|".join( | ||
[ | ||
r"unsupported operand type\(s\) for \+: " | ||
"'(Timestamp|DatetimeArray)' and 'datetime.time'", | ||
"ufunc (add|'add') cannot use operands with types " | ||
r"dtype\('O'\) and dtype\('<M8\[ns\]'\)", | ||
] | ||
) | ||
with pytest.raises(TypeError, match=msg): | ||
obj2 + obj1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we be testing that all four of these ops raise TypeError? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea this isn't very clear as is whether one or all of these raise a TypeError - can these be split into different contexts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or alternately you can parametrize add, radd, sub, rsub There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I can do that, is that's the preferred way? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dealer's choice. i tend not to parametrize over add/radd/sub/rsub since it repeats all the setup code for for what i see as little gain, but on a case-by-case basis if it improves clarity, go for it. |
||
|
||
|
||
class TestDatetime64DateOffsetArithmetic: | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.