Skip to content

Commit ed85c4f

Browse files
jbrockmendeljreback
authored andcommitted
REF: de-duplicate/parametrize arithmetic tests (#30438)
1 parent 04faf89 commit ed85c4f

File tree

4 files changed

+215
-363
lines changed

4 files changed

+215
-363
lines changed

pandas/tests/arithmetic/test_datetime64.py

+8-27
Original file line numberDiff line numberDiff line change
@@ -1890,13 +1890,10 @@ def test_dti_addsub_int(self, tz_naive_fixture, one):
18901890

18911891
with pytest.raises(TypeError, match=msg):
18921892
rng + one
1893-
18941893
with pytest.raises(TypeError, match=msg):
18951894
rng += one
1896-
18971895
with pytest.raises(TypeError, match=msg):
18981896
rng - one
1899-
19001897
with pytest.raises(TypeError, match=msg):
19011898
rng -= one
19021899

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

1913-
msg = "Addition/subtraction of integers"
1914-
1915-
with pytest.raises(TypeError, match=msg):
1916-
dti + other
1917-
1918-
with pytest.raises(TypeError, match=msg):
1919-
other + dti
1910+
msg = "Addition/subtraction of integers|cannot subtract DatetimeArray from"
1911+
assert_invalid_addsub_type(dti, other, msg)
19201912

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

1928-
msg = "Addition/subtraction of integers"
1929-
1930-
with pytest.raises(TypeError, match=msg):
1931-
dti + other
1932-
1933-
with pytest.raises(TypeError, match=msg):
1934-
other + dti
1920+
msg = "Addition/subtraction of integers|cannot subtract DatetimeArray from"
1921+
assert_invalid_addsub_type(dti, other, msg)
19351922

19361923
@pytest.mark.parametrize("int_holder", [np.array, pd.Index])
19371924
def test_dti_add_intarray_no_freq(self, int_holder):
19381925
# GH#19959
19391926
dti = pd.DatetimeIndex(["2016-01-01", "NaT", "2017-04-05 06:07:08"])
19401927
other = int_holder([9, 4, -1])
1941-
tmsg = "cannot subtract DatetimeArray from"
1942-
msg = "Addition/subtraction of integers"
1943-
with pytest.raises(TypeError, match=msg):
1944-
dti + other
1945-
with pytest.raises(TypeError, match=msg):
1946-
other + dti
1947-
with pytest.raises(TypeError, match=msg):
1948-
dti - other
1949-
with pytest.raises(TypeError, match=tmsg):
1950-
other - dti
1928+
msg = "|".join(
1929+
["cannot subtract DatetimeArray from", "Addition/subtraction of integers"]
1930+
)
1931+
assert_invalid_addsub_type(dti, other, msg)
19511932

19521933
# -------------------------------------------------------------
19531934
# Binary operations DatetimeIndex and TimedeltaIndex/array

0 commit comments

Comments
 (0)