13
13
from pandas ._libs .tslibs .conversion import localize_pydatetime
14
14
from pandas ._libs .tslibs .offsets import shift_months
15
15
from pandas .compat .numpy import np_datetime64_compat
16
- from pandas .errors import NullFrequencyError , PerformanceWarning
16
+ from pandas .errors import PerformanceWarning
17
17
18
18
import pandas as pd
19
19
from pandas import (
@@ -1856,10 +1856,8 @@ def test_dt64_series_add_intlike(self, tz, op):
1856
1856
method = getattr (ser , op )
1857
1857
msg = "|" .join (
1858
1858
[
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" ,
1863
1861
]
1864
1862
)
1865
1863
with pytest .raises (TypeError , match = msg ):
@@ -1941,38 +1939,23 @@ class TestDatetimeIndexArithmetic:
1941
1939
# -------------------------------------------------------------
1942
1940
# Binary operations DatetimeIndex and int
1943
1941
1944
- def test_dti_add_int (self , tz_naive_fixture , one ):
1942
+ def test_dti_addsub_int (self , tz_naive_fixture , one ):
1945
1943
# Variants of `one` for #19012
1946
1944
tz = tz_naive_fixture
1947
1945
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"
1952
1947
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 ):
1958
1952
rng += one
1959
- tm .assert_index_equal (rng , expected )
1960
1953
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
1968
1956
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 ):
1974
1958
rng -= one
1975
- tm .assert_index_equal (rng , expected )
1976
1959
1977
1960
# -------------------------------------------------------------
1978
1961
# __add__/__sub__ with integer arrays
@@ -1984,14 +1967,13 @@ def test_dti_add_intarray_tick(self, int_holder, freq):
1984
1967
dti = pd .date_range ("2016-01-01" , periods = 2 , freq = freq )
1985
1968
other = int_holder ([4 , - 1 ])
1986
1969
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"
1991
1971
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
1995
1977
1996
1978
@pytest .mark .parametrize ("freq" , ["W" , "M" , "MS" , "Q" ])
1997
1979
@pytest .mark .parametrize ("int_holder" , [np .array , pd .Index ])
@@ -2000,34 +1982,26 @@ def test_dti_add_intarray_non_tick(self, int_holder, freq):
2000
1982
dti = pd .date_range ("2016-01-01" , periods = 2 , freq = freq )
2001
1983
other = int_holder ([4 , - 1 ])
2002
1984
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"
2005
1986
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
2013
1989
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
2018
1992
2019
1993
@pytest .mark .parametrize ("int_holder" , [np .array , pd .Index ])
2020
1994
def test_dti_add_intarray_no_freq (self , int_holder ):
2021
1995
# GH#19959
2022
1996
dti = pd .DatetimeIndex (["2016-01-01" , "NaT" , "2017-04-05 06:07:08" ])
2023
1997
other = int_holder ([9 , 4 , - 1 ])
2024
- nfmsg = "Cannot shift with no freq"
2025
1998
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 ):
2027
2001
dti + other
2028
- with pytest .raises (NullFrequencyError , match = nfmsg ):
2002
+ with pytest .raises (TypeError , match = msg ):
2029
2003
other + dti
2030
- with pytest .raises (NullFrequencyError , match = nfmsg ):
2004
+ with pytest .raises (TypeError , match = msg ):
2031
2005
dti - other
2032
2006
with pytest .raises (TypeError , match = tmsg ):
2033
2007
other - dti
0 commit comments