@@ -48,7 +48,8 @@ def test_compare_timedelta64_zerodim(self, box_with_array):
48
48
expected = tm .box_expected (expected , xbox )
49
49
tm .assert_equal (res , expected )
50
50
51
- with pytest .raises (TypeError ):
51
+ msg = "Invalid comparison between dtype"
52
+ with pytest .raises (TypeError , match = msg ):
52
53
# zero-dim of wrong dtype should still raise
53
54
tdi >= np .array (4 )
54
55
@@ -442,7 +443,8 @@ def test_addition_ops(self):
442
443
tdi [0 :1 ] + dti
443
444
444
445
# random indexes
445
- with pytest .raises (TypeError ):
446
+ msg = "Addition/subtraction of integers and integer-arrays"
447
+ with pytest .raises (TypeError , match = msg ):
446
448
tdi + pd .Int64Index ([1 , 2 , 3 ])
447
449
448
450
# this is a union!
@@ -604,6 +606,7 @@ def test_tdi_add_timestamp_nat_masking(self):
604
606
def test_tdi_add_overflow (self ):
605
607
# See GH#14068
606
608
# preliminary test scalar analogue of vectorized tests below
609
+ # TODO: Make raised error message more informative and test
607
610
with pytest .raises (OutOfBoundsDatetime ):
608
611
pd .to_timedelta (106580 , "D" ) + Timestamp ("2000" )
609
612
with pytest .raises (OutOfBoundsDatetime ):
@@ -700,13 +703,14 @@ def test_timedelta_ops_with_missing_values(self):
700
703
actual = - timedelta_NaT + s1
701
704
tm .assert_series_equal (actual , sn )
702
705
703
- with pytest .raises (TypeError ):
706
+ msg = "unsupported operand type"
707
+ with pytest .raises (TypeError , match = msg ):
704
708
s1 + np .nan
705
- with pytest .raises (TypeError ):
709
+ with pytest .raises (TypeError , match = msg ):
706
710
np .nan + s1
707
- with pytest .raises (TypeError ):
711
+ with pytest .raises (TypeError , match = msg ):
708
712
s1 - np .nan
709
- with pytest .raises (TypeError ):
713
+ with pytest .raises (TypeError , match = msg ):
710
714
- np .nan + s1
711
715
712
716
actual = s1 + pd .NaT
@@ -738,9 +742,10 @@ def test_timedelta_ops_with_missing_values(self):
738
742
actual = df1 - timedelta_NaT
739
743
tm .assert_frame_equal (actual , dfn )
740
744
741
- with pytest .raises (TypeError ):
745
+ msg = "cannot subtract a datelike from|unsupported operand type"
746
+ with pytest .raises (TypeError , match = msg ):
742
747
df1 + np .nan
743
- with pytest .raises (TypeError ):
748
+ with pytest .raises (TypeError , match = msg ):
744
749
df1 - np .nan
745
750
746
751
actual = df1 + pd .NaT # NaT is datetime, not timedelta
@@ -957,7 +962,8 @@ def test_td64arr_add_sub_datetimelike_scalar(self, ts, box_with_array):
957
962
tm .assert_equal (ts - tdarr , expected2 )
958
963
tm .assert_equal (ts + (- tdarr ), expected2 )
959
964
960
- with pytest .raises (TypeError ):
965
+ msg = "cannot subtract a datelike"
966
+ with pytest .raises (TypeError , match = msg ):
961
967
tdarr - ts
962
968
963
969
def test_tdi_sub_dt64_array (self , box_with_array ):
@@ -969,7 +975,8 @@ def test_tdi_sub_dt64_array(self, box_with_array):
969
975
tdi = tm .box_expected (tdi , box_with_array )
970
976
expected = tm .box_expected (expected , box_with_array )
971
977
972
- with pytest .raises (TypeError ):
978
+ msg = "cannot subtract a datelike from"
979
+ with pytest .raises (TypeError , match = msg ):
973
980
tdi - dtarr
974
981
975
982
# TimedeltaIndex.__rsub__
@@ -1025,7 +1032,8 @@ def test_td64arr_sub_periodlike(self, box_with_array, tdi_freq, pi_freq):
1025
1032
1026
1033
# TODO: parametrize over box for pi?
1027
1034
tdi = tm .box_expected (tdi , box_with_array )
1028
- with pytest .raises (TypeError ):
1035
+ msg = "cannot subtract|unsupported operand type"
1036
+ with pytest .raises (TypeError , match = msg ):
1029
1037
tdi - pi
1030
1038
1031
1039
# FIXME: don't leave commented-out
@@ -1034,9 +1042,9 @@ def test_td64arr_sub_periodlike(self, box_with_array, tdi_freq, pi_freq):
1034
1042
# pi - tdi
1035
1043
1036
1044
# GH#13078 subtraction of Period scalar not supported
1037
- with pytest .raises (TypeError ):
1045
+ with pytest .raises (TypeError , match = msg ):
1038
1046
tdi - pi [0 ]
1039
- with pytest .raises (TypeError ):
1047
+ with pytest .raises (TypeError , match = msg ):
1040
1048
pi [0 ] - tdi
1041
1049
1042
1050
@pytest .mark .parametrize (
@@ -1499,16 +1507,17 @@ def test_td64arr_addsub_anchored_offset_arraylike(self, obox, box_with_array):
1499
1507
1500
1508
# addition/subtraction ops with anchored offsets should issue
1501
1509
# a PerformanceWarning and _then_ raise a TypeError.
1502
- with pytest .raises (TypeError ):
1510
+ msg = "has incorrect type|cannot add the type MonthEnd"
1511
+ with pytest .raises (TypeError , match = msg ):
1503
1512
with tm .assert_produces_warning (PerformanceWarning ):
1504
1513
tdi + anchored
1505
- with pytest .raises (TypeError ):
1514
+ with pytest .raises (TypeError , match = msg ):
1506
1515
with tm .assert_produces_warning (PerformanceWarning ):
1507
1516
anchored + tdi
1508
- with pytest .raises (TypeError ):
1517
+ with pytest .raises (TypeError , match = msg ):
1509
1518
with tm .assert_produces_warning (PerformanceWarning ):
1510
1519
tdi - anchored
1511
- with pytest .raises (TypeError ):
1520
+ with pytest .raises (TypeError , match = msg ):
1512
1521
with tm .assert_produces_warning (PerformanceWarning ):
1513
1522
anchored - tdi
1514
1523
@@ -1533,7 +1542,8 @@ def test_td64arr_add_sub_object_array(self, box_with_array):
1533
1542
expected = tm .box_expected (expected , box_with_array )
1534
1543
tm .assert_equal (result , expected )
1535
1544
1536
- with pytest .raises (TypeError ):
1545
+ msg = "unsupported operand type|cannot subtract a datelike"
1546
+ with pytest .raises (TypeError , match = msg ):
1537
1547
with tm .assert_produces_warning (warn ):
1538
1548
tdarr - other
1539
1549
@@ -1588,7 +1598,8 @@ def test_td64arr_mul_int(self, box_with_array):
1588
1598
def test_td64arr_mul_tdlike_scalar_raises (self , two_hours , box_with_array ):
1589
1599
rng = timedelta_range ("1 days" , "10 days" , name = "foo" )
1590
1600
rng = tm .box_expected (rng , box_with_array )
1591
- with pytest .raises (TypeError ):
1601
+ msg = "argument must be an integer|cannot use operands with types dtype"
1602
+ with pytest .raises (TypeError , match = msg ):
1592
1603
rng * two_hours
1593
1604
1594
1605
def test_tdi_mul_int_array_zerodim (self , box_with_array ):
@@ -1777,12 +1788,13 @@ def test_tdarr_div_length_mismatch(self, box_with_array):
1777
1788
mismatched = [1 , 2 , 3 , 4 ]
1778
1789
1779
1790
rng = tm .box_expected (rng , box_with_array )
1791
+ msg = "Cannot divide vectors|Unable to coerce to Series"
1780
1792
for obj in [mismatched , mismatched [:2 ]]:
1781
1793
# one shorter, one longer
1782
1794
for other in [obj , np .array (obj ), pd .Index (obj )]:
1783
- with pytest .raises (ValueError ):
1795
+ with pytest .raises (ValueError , match = msg ):
1784
1796
rng / other
1785
- with pytest .raises (ValueError ):
1797
+ with pytest .raises (ValueError , match = msg ):
1786
1798
other / rng
1787
1799
1788
1800
# ------------------------------------------------------------------
@@ -1908,7 +1920,8 @@ def test_td64arr_mod_int(self, box_with_array):
1908
1920
result = tdarr % 2
1909
1921
tm .assert_equal (result , expected )
1910
1922
1911
- with pytest .raises (TypeError ):
1923
+ msg = "Cannot divide int by"
1924
+ with pytest .raises (TypeError , match = msg ):
1912
1925
2 % tdarr
1913
1926
1914
1927
if box_with_array is pd .DataFrame :
@@ -1957,15 +1970,21 @@ def test_td64arr_mul_tdscalar_invalid(self, box_with_array, scalar_td):
1957
1970
def test_td64arr_mul_too_short_raises (self , box_with_array ):
1958
1971
idx = TimedeltaIndex (np .arange (5 , dtype = "int64" ))
1959
1972
idx = tm .box_expected (idx , box_with_array )
1960
- with pytest .raises (TypeError ):
1973
+ msg = (
1974
+ "cannot use operands with types dtype|"
1975
+ "Cannot multiply with unequal lengths|"
1976
+ "Unable to coerce to Series"
1977
+ )
1978
+ with pytest .raises (TypeError , match = msg ):
1961
1979
idx * idx [:3 ]
1962
- with pytest .raises (ValueError ):
1980
+ with pytest .raises (ValueError , match = msg ):
1963
1981
idx * np .array ([1 , 2 ])
1964
1982
1965
1983
def test_td64arr_mul_td64arr_raises (self , box_with_array ):
1966
1984
idx = TimedeltaIndex (np .arange (5 , dtype = "int64" ))
1967
1985
idx = tm .box_expected (idx , box_with_array )
1968
- with pytest .raises (TypeError ):
1986
+ msg = "cannot use operands with types dtype"
1987
+ with pytest .raises (TypeError , match = msg ):
1969
1988
idx * idx
1970
1989
1971
1990
# ------------------------------------------------------------------
0 commit comments