1313from pandas ._libs .tslibs .conversion import localize_pydatetime
1414from pandas ._libs .tslibs .offsets import shift_months
1515from pandas .compat .numpy import np_datetime64_compat
16- from pandas .errors import NullFrequencyError , PerformanceWarning
16+ from pandas .errors import PerformanceWarning
1717
1818import pandas as pd
1919from pandas import (
@@ -1856,10 +1856,8 @@ def test_dt64_series_add_intlike(self, tz, op):
18561856 method = getattr (ser , op )
18571857 msg = "|" .join (
18581858 [
1859- "incompatible type for a .* operation" ,
1860- "cannot evaluate a numeric op" ,
1861- "ufunc .* cannot use operands" ,
1862- "cannot (add|subtract)" ,
1859+ "Addition/subtraction of integers and integer-arrays" ,
1860+ "cannot subtract .* from ndarray" ,
18631861 ]
18641862 )
18651863 with pytest .raises (TypeError , match = msg ):
@@ -1941,38 +1939,23 @@ class TestDatetimeIndexArithmetic:
19411939 # -------------------------------------------------------------
19421940 # Binary operations DatetimeIndex and int
19431941
1944- def test_dti_add_int (self , tz_naive_fixture , one ):
1942+ def test_dti_addsub_int (self , tz_naive_fixture , one ):
19451943 # Variants of `one` for #19012
19461944 tz = tz_naive_fixture
19471945 rng = pd .date_range ("2000-01-01 09:00" , freq = "H" , periods = 10 , tz = tz )
1948- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
1949- result = rng + one
1950- expected = pd .date_range ("2000-01-01 10:00" , freq = "H" , periods = 10 , tz = tz )
1951- tm .assert_index_equal (result , expected )
1946+ msg = "Addition/subtraction of integers"
19521947
1953- def test_dti_iadd_int (self , tz_naive_fixture , one ):
1954- tz = tz_naive_fixture
1955- rng = pd .date_range ("2000-01-01 09:00" , freq = "H" , periods = 10 , tz = tz )
1956- expected = pd .date_range ("2000-01-01 10:00" , freq = "H" , periods = 10 , tz = tz )
1957- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
1948+ with pytest .raises (TypeError , match = msg ):
1949+ rng + one
1950+
1951+ with pytest .raises (TypeError , match = msg ):
19581952 rng += one
1959- tm .assert_index_equal (rng , expected )
19601953
1961- def test_dti_sub_int (self , tz_naive_fixture , one ):
1962- tz = tz_naive_fixture
1963- rng = pd .date_range ("2000-01-01 09:00" , freq = "H" , periods = 10 , tz = tz )
1964- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
1965- result = rng - one
1966- expected = pd .date_range ("2000-01-01 08:00" , freq = "H" , periods = 10 , tz = tz )
1967- tm .assert_index_equal (result , expected )
1954+ with pytest .raises (TypeError , match = msg ):
1955+ rng - one
19681956
1969- def test_dti_isub_int (self , tz_naive_fixture , one ):
1970- tz = tz_naive_fixture
1971- rng = pd .date_range ("2000-01-01 09:00" , freq = "H" , periods = 10 , tz = tz )
1972- expected = pd .date_range ("2000-01-01 08:00" , freq = "H" , periods = 10 , tz = tz )
1973- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
1957+ with pytest .raises (TypeError , match = msg ):
19741958 rng -= one
1975- tm .assert_index_equal (rng , expected )
19761959
19771960 # -------------------------------------------------------------
19781961 # __add__/__sub__ with integer arrays
@@ -1984,14 +1967,13 @@ def test_dti_add_intarray_tick(self, int_holder, freq):
19841967 dti = pd .date_range ("2016-01-01" , periods = 2 , freq = freq )
19851968 other = int_holder ([4 , - 1 ])
19861969
1987- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
1988- expected = DatetimeIndex ([dti [n ] + other [n ] for n in range (len (dti ))])
1989- result = dti + other
1990- tm .assert_index_equal (result , expected )
1970+ msg = "Addition/subtraction of integers"
19911971
1992- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
1993- result = other + dti
1994- tm .assert_index_equal (result , expected )
1972+ with pytest .raises (TypeError , match = msg ):
1973+ dti + other
1974+
1975+ with pytest .raises (TypeError , match = msg ):
1976+ other + dti
19951977
19961978 @pytest .mark .parametrize ("freq" , ["W" , "M" , "MS" , "Q" ])
19971979 @pytest .mark .parametrize ("int_holder" , [np .array , pd .Index ])
@@ -2000,34 +1982,26 @@ def test_dti_add_intarray_non_tick(self, int_holder, freq):
20001982 dti = pd .date_range ("2016-01-01" , periods = 2 , freq = freq )
20011983 other = int_holder ([4 , - 1 ])
20021984
2003- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
2004- expected = DatetimeIndex ([dti [n ] + other [n ] for n in range (len (dti ))])
1985+ msg = "Addition/subtraction of integers"
20051986
2006- # tm.assert_produces_warning does not handle cases where we expect
2007- # two warnings, in this case PerformanceWarning and FutureWarning.
2008- # Until that is fixed, we don't catch either
2009- with warnings .catch_warnings ():
2010- warnings .simplefilter ("ignore" )
2011- result = dti + other
2012- tm .assert_index_equal (result , expected )
1987+ with pytest .raises (TypeError , match = msg ):
1988+ dti + other
20131989
2014- with warnings .catch_warnings ():
2015- warnings .simplefilter ("ignore" )
2016- result = other + dti
2017- tm .assert_index_equal (result , expected )
1990+ with pytest .raises (TypeError , match = msg ):
1991+ other + dti
20181992
20191993 @pytest .mark .parametrize ("int_holder" , [np .array , pd .Index ])
20201994 def test_dti_add_intarray_no_freq (self , int_holder ):
20211995 # GH#19959
20221996 dti = pd .DatetimeIndex (["2016-01-01" , "NaT" , "2017-04-05 06:07:08" ])
20231997 other = int_holder ([9 , 4 , - 1 ])
2024- nfmsg = "Cannot shift with no freq"
20251998 tmsg = "cannot subtract DatetimeArray from"
2026- with pytest .raises (NullFrequencyError , match = nfmsg ):
1999+ msg = "Addition/subtraction of integers"
2000+ with pytest .raises (TypeError , match = msg ):
20272001 dti + other
2028- with pytest .raises (NullFrequencyError , match = nfmsg ):
2002+ with pytest .raises (TypeError , match = msg ):
20292003 other + dti
2030- with pytest .raises (NullFrequencyError , match = nfmsg ):
2004+ with pytest .raises (TypeError , match = msg ):
20312005 dti - other
20322006 with pytest .raises (TypeError , match = tmsg ):
20332007 other - dti
0 commit comments