Skip to content

REF: de-duplicate/parametrize arithmetic tests #30438

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 10 commits into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 8 additions & 27 deletions pandas/tests/arithmetic/test_datetime64.py
Original file line number Diff line number Diff line change
Expand Up @@ -1890,13 +1890,10 @@ def test_dti_addsub_int(self, tz_naive_fixture, one):

with pytest.raises(TypeError, match=msg):
rng + one

with pytest.raises(TypeError, match=msg):
rng += one

with pytest.raises(TypeError, match=msg):
rng - one

with pytest.raises(TypeError, match=msg):
rng -= one

Expand All @@ -1910,13 +1907,8 @@ def test_dti_add_intarray_tick(self, int_holder, freq):
dti = pd.date_range("2016-01-01", periods=2, freq=freq)
other = int_holder([4, -1])

msg = "Addition/subtraction of integers"

with pytest.raises(TypeError, match=msg):
dti + other

with pytest.raises(TypeError, match=msg):
other + dti
msg = "Addition/subtraction of integers|cannot subtract DatetimeArray from"
assert_invalid_addsub_type(dti, other, msg)

@pytest.mark.parametrize("freq", ["W", "M", "MS", "Q"])
@pytest.mark.parametrize("int_holder", [np.array, pd.Index])
Expand All @@ -1925,29 +1917,18 @@ def test_dti_add_intarray_non_tick(self, int_holder, freq):
dti = pd.date_range("2016-01-01", periods=2, freq=freq)
other = int_holder([4, -1])

msg = "Addition/subtraction of integers"

with pytest.raises(TypeError, match=msg):
dti + other

with pytest.raises(TypeError, match=msg):
other + dti
msg = "Addition/subtraction of integers|cannot subtract DatetimeArray from"
assert_invalid_addsub_type(dti, other, msg)

@pytest.mark.parametrize("int_holder", [np.array, pd.Index])
def test_dti_add_intarray_no_freq(self, int_holder):
# GH#19959
dti = pd.DatetimeIndex(["2016-01-01", "NaT", "2017-04-05 06:07:08"])
other = int_holder([9, 4, -1])
tmsg = "cannot subtract DatetimeArray from"
msg = "Addition/subtraction of integers"
with pytest.raises(TypeError, match=msg):
dti + other
with pytest.raises(TypeError, match=msg):
other + dti
with pytest.raises(TypeError, match=msg):
dti - other
with pytest.raises(TypeError, match=tmsg):
other - dti
msg = "|".join(
["cannot subtract DatetimeArray from", "Addition/subtraction of integers"]
)
assert_invalid_addsub_type(dti, other, msg)

# -------------------------------------------------------------
# Binary operations DatetimeIndex and TimedeltaIndex/array
Expand Down
Loading