Skip to content

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

Merged
merged 30 commits into from
Apr 3, 2020
Merged
Changes from 19 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
aa5dc3b
TST: Added regression test
Feb 1, 2020
270dfee
Flake8 issues
Feb 1, 2020
5691066
Update pandas/tests/frame/test_timeseries.py
ShaharNaveh Feb 7, 2020
2cf0756
Moved the test case
Feb 7, 2020
33e24a3
Refactored the test case to use 'box_with_array'
Feb 14, 2020
bc75e25
Changed test name
Feb 22, 2020
20ba781
Merge remote-tracking branch 'upstream/master' into TST-reg-datetime
Feb 22, 2020
94cedb9
Added the add operations
Feb 22, 2020
1cafb66
Added time scalar to "other"
Feb 22, 2020
a5608eb
Lint
Feb 22, 2020
fd04076
Ignoring warnings, that we are not checking for this specific test case
Feb 22, 2020
1d17645
Merge remote-tracking branch 'upstream/master' into TST-reg-datetime
Feb 28, 2020
c454822
Merge remote-tracking branch 'upstream/master' into TST-reg-datetime
Mar 5, 2020
faf90e1
Renamed test case
Mar 5, 2020
5cdd1d1
Added comment pointing to the appropiate issue
Mar 5, 2020
6fef7f8
Added tz_naive_fixture
Mar 5, 2020
799ae78
Putting each expression in its own `pytest.raises`
Mar 13, 2020
54ea5a0
Fixed tests to pass
Mar 13, 2020
808599b
Merge remote-tracking branch 'upstream/master' into TST-reg-datetime
Mar 13, 2020
0db9073
Removed unneeded comments
Mar 13, 2020
d62cad3
Merge remote-tracking branch 'upstream/master' into TST-reg-datetime
Mar 13, 2020
1449d8c
Renamed test case
Mar 18, 2020
c5dc76c
Merge remote-tracking branch 'upstream/master' into TST-reg-datetime
Mar 18, 2020
6d2e72f
Merge remote-tracking branch 'upstream/master' into TST-reg-datetime
Mar 20, 2020
5742c46
Merge remote-tracking branch 'upstream/master' into TST-reg-datetime
Mar 23, 2020
951074f
Merge remote-tracking branch 'upstream/master' into TST-reg-datetime
Mar 26, 2020
fbce136
Merge remote-tracking branch 'upstream/master' into TST-reg-datetime
Mar 29, 2020
5954709
Fixed error message
Mar 29, 2020
f51559f
Fixed error message
Mar 29, 2020
e183a23
Merge remote-tracking branch 'upstream/master' into TST-reg-datetime
Apr 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion pandas/tests/arithmetic/test_datetime64.py
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
Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -1069,6 +1071,64 @@ def test_dt64arr_add_sub_parr(
)
assert_invalid_addsub_type(dtarr, parr, msg)

def test_dt64arr_addsub_time_object_raises(self, box_with_array, tz_naive_fixture):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: time_object -> time_objects. otherwise i think this is ready

# 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):
# 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):
# sub
obj1 - obj2

msg = "|".join(
[
"cannot subtract DatetimeArray from ndarray",
"ufunc 'subtract' cannot use operands with types "
r"dtype\('O'\) and dtype\('<M8\[ns\]'\)",
]
)
with pytest.raises(TypeError, match=msg):
# sub
obj2 - obj1

msg = (
r"unsupported operand type\(s\) for \+: "
"'(Timestamp|DatetimeArray)' and 'datetime.time'"
)
with pytest.raises(TypeError, match=msg):
# add
obj1 + obj2

msg = "|".join(
[
r"unsupported operand type\(s\) for \+: "
"'(Timestamp|DatetimeArray)' and 'datetime.time'",
"ufunc 'add' cannot use operands with types "
r"dtype\('O'\) and dtype\('<M8\[ns\]'\)",
]
)
with pytest.raises(TypeError, match=msg):
# add
obj2 + obj1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we be testing that all four of these ops raise TypeError?

Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or alternately you can parametrize add, radd, sub, rsub

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or alternately you can parametrize add, radd, sub, rsub

I can do that, is that's the preferred way?

Copy link
Member

Choose a reason for hiding this comment

The 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:

Expand Down