@@ -153,14 +153,17 @@ def test_eq_integer_disallowed(self, other):
153
153
result = idx == other
154
154
155
155
tm .assert_numpy_array_equal (result , expected )
156
-
157
- with pytest .raises (TypeError ):
156
+ msg = (
157
+ r"(:?Invalid comparison between dtype=period\[D\] and .*)"
158
+ r"|(:?Cannot compare type Period with type .*)"
159
+ )
160
+ with pytest .raises (TypeError , match = msg ):
158
161
idx < other
159
- with pytest .raises (TypeError ):
162
+ with pytest .raises (TypeError , match = msg ):
160
163
idx > other
161
- with pytest .raises (TypeError ):
164
+ with pytest .raises (TypeError , match = msg ):
162
165
idx <= other
163
- with pytest .raises (TypeError ):
166
+ with pytest .raises (TypeError , match = msg ):
164
167
idx >= other
165
168
166
169
def test_pi_cmp_period (self ):
@@ -587,10 +590,11 @@ def test_parr_add_iadd_parr_raises(self, box_with_array):
587
590
# a set operation (union). This has since been changed to
588
591
# raise a TypeError. See GH#14164 and GH#13077 for historical
589
592
# reference.
590
- with pytest .raises (TypeError ):
593
+ msg = r"unsupported operand type\(s\) for \+: .* and .*"
594
+ with pytest .raises (TypeError , match = msg ):
591
595
rng + other
592
596
593
- with pytest .raises (TypeError ):
597
+ with pytest .raises (TypeError , match = msg ):
594
598
rng += other
595
599
596
600
def test_pi_sub_isub_pi (self ):
@@ -625,7 +629,8 @@ def test_parr_sub_pi_mismatched_freq(self, box_with_array):
625
629
# TODO: parametrize over boxes for other?
626
630
627
631
rng = tm .box_expected (rng , box_with_array )
628
- with pytest .raises (IncompatibleFrequency ):
632
+ msg = r"Input has different freq=[HD] from PeriodArray\(freq=[DH]\)"
633
+ with pytest .raises (IncompatibleFrequency , match = msg ):
629
634
rng - other
630
635
631
636
@pytest .mark .parametrize ("n" , [1 , 2 , 3 , 4 ])
@@ -677,7 +682,8 @@ def test_parr_add_sub_float_raises(self, op, other, box_with_array):
677
682
dti = pd .DatetimeIndex (["2011-01-01" , "2011-01-02" ], freq = "D" )
678
683
pi = dti .to_period ("D" )
679
684
pi = tm .box_expected (pi , box_with_array )
680
- with pytest .raises (TypeError ):
685
+ msg = r"unsupported operand type\(s\) for [+-]: .* and .*"
686
+ with pytest .raises (TypeError , match = msg ):
681
687
op (pi , other )
682
688
683
689
@pytest .mark .parametrize (
@@ -700,13 +706,18 @@ def test_parr_add_sub_invalid(self, other, box_with_array):
700
706
rng = pd .period_range ("1/1/2000" , freq = "D" , periods = 3 )
701
707
rng = tm .box_expected (rng , box_with_array )
702
708
703
- with pytest .raises (TypeError ):
709
+ msg = (
710
+ r"(:?cannot add PeriodArray and .*)"
711
+ r"|(:?cannot subtract .* from (:?a\s)?.*)"
712
+ r"|(:?unsupported operand type\(s\) for \+: .* and .*)"
713
+ )
714
+ with pytest .raises (TypeError , match = msg ):
704
715
rng + other
705
- with pytest .raises (TypeError ):
716
+ with pytest .raises (TypeError , match = msg ):
706
717
other + rng
707
- with pytest .raises (TypeError ):
718
+ with pytest .raises (TypeError , match = msg ):
708
719
rng - other
709
- with pytest .raises (TypeError ):
720
+ with pytest .raises (TypeError , match = msg ):
710
721
other - rng
711
722
712
723
# -----------------------------------------------------------------
@@ -717,14 +728,16 @@ def test_pi_add_sub_td64_array_non_tick_raises(self):
717
728
tdi = pd .TimedeltaIndex (["-1 Day" , "-1 Day" , "-1 Day" ])
718
729
tdarr = tdi .values
719
730
720
- with pytest .raises (IncompatibleFrequency ):
731
+ msg = r"Input has different freq=None from PeriodArray\(freq=Q-DEC\)"
732
+ with pytest .raises (IncompatibleFrequency , match = msg ):
721
733
rng + tdarr
722
- with pytest .raises (IncompatibleFrequency ):
734
+ with pytest .raises (IncompatibleFrequency , match = msg ):
723
735
tdarr + rng
724
736
725
- with pytest .raises (IncompatibleFrequency ):
737
+ with pytest .raises (IncompatibleFrequency , match = msg ):
726
738
rng - tdarr
727
- with pytest .raises (TypeError ):
739
+ msg = r"cannot subtract PeriodArray from timedelta64\[ns\]"
740
+ with pytest .raises (TypeError , match = msg ):
728
741
tdarr - rng
729
742
730
743
def test_pi_add_sub_td64_array_tick (self ):
@@ -751,10 +764,11 @@ def test_pi_add_sub_td64_array_tick(self):
751
764
result = rng - tdarr
752
765
tm .assert_index_equal (result , expected )
753
766
754
- with pytest .raises (TypeError ):
767
+ msg = r"cannot subtract .* from .*"
768
+ with pytest .raises (TypeError , match = msg ):
755
769
tdarr - rng
756
770
757
- with pytest .raises (TypeError ):
771
+ with pytest .raises (TypeError , match = msg ):
758
772
tdi - rng
759
773
760
774
# -----------------------------------------------------------------
@@ -783,10 +797,11 @@ def test_pi_add_offset_array(self, box):
783
797
unanchored = np .array ([pd .offsets .Hour (n = 1 ), pd .offsets .Minute (n = - 2 )])
784
798
# addition/subtraction ops with incompatible offsets should issue
785
799
# a PerformanceWarning and _then_ raise a TypeError.
786
- with pytest .raises (IncompatibleFrequency ):
800
+ msg = r"Input cannot be converted to Period\(freq=Q-DEC\)"
801
+ with pytest .raises (IncompatibleFrequency , match = msg ):
787
802
with tm .assert_produces_warning (PerformanceWarning ):
788
803
pi + unanchored
789
- with pytest .raises (IncompatibleFrequency ):
804
+ with pytest .raises (IncompatibleFrequency , match = msg ):
790
805
with tm .assert_produces_warning (PerformanceWarning ):
791
806
unanchored + pi
792
807
@@ -811,10 +826,11 @@ def test_pi_sub_offset_array(self, box):
811
826
812
827
# addition/subtraction ops with anchored offsets should issue
813
828
# a PerformanceWarning and _then_ raise a TypeError.
814
- with pytest .raises (IncompatibleFrequency ):
829
+ msg = r"Input has different freq=-1M from Period\(freq=Q-DEC\)"
830
+ with pytest .raises (IncompatibleFrequency , match = msg ):
815
831
with tm .assert_produces_warning (PerformanceWarning ):
816
832
pi - anchored
817
- with pytest .raises (IncompatibleFrequency ):
833
+ with pytest .raises (IncompatibleFrequency , match = msg ):
818
834
with tm .assert_produces_warning (PerformanceWarning ):
819
835
anchored - pi
820
836
@@ -924,7 +940,8 @@ def test_pi_sub_intarray(self, int_holder):
924
940
expected = pd .PeriodIndex ([pd .Period ("2014Q1" ), pd .Period ("NaT" )])
925
941
tm .assert_index_equal (result , expected )
926
942
927
- with pytest .raises (TypeError ):
943
+ msg = r"bad operand type for unary -: 'PeriodArray'"
944
+ with pytest .raises (TypeError , match = msg ):
928
945
other - pi
929
946
930
947
# ---------------------------------------------------------------
@@ -952,7 +969,11 @@ def test_pi_add_timedeltalike_minute_gt1(self, three_days):
952
969
result = rng - other
953
970
tm .assert_index_equal (result , expected )
954
971
955
- with pytest .raises (TypeError ):
972
+ msg = (
973
+ r"(:?bad operand type for unary -: 'PeriodArray')"
974
+ r"|(:?cannot subtract PeriodArray from timedelta64\[[hD]\])"
975
+ )
976
+ with pytest .raises (TypeError , match = msg ):
956
977
other - rng
957
978
958
979
@pytest .mark .parametrize ("freqstr" , ["5ns" , "5us" , "5ms" , "5s" , "5T" , "5h" , "5d" ])
@@ -974,8 +995,11 @@ def test_pi_add_timedeltalike_tick_gt1(self, three_days, freqstr):
974
995
expected = pd .period_range (rng [0 ] - other , periods = 6 , freq = freqstr )
975
996
result = rng - other
976
997
tm .assert_index_equal (result , expected )
977
-
978
- with pytest .raises (TypeError ):
998
+ msg = (
999
+ r"(:?bad operand type for unary -: 'PeriodArray')"
1000
+ r"|(:?cannot subtract PeriodArray from timedelta64\[[hD]\])"
1001
+ )
1002
+ with pytest .raises (TypeError , match = msg ):
979
1003
other - rng
980
1004
981
1005
def test_pi_add_iadd_timedeltalike_daily (self , three_days ):
@@ -1110,7 +1134,8 @@ def test_parr_add_sub_td64_nat(self, box_with_array, transpose):
1110
1134
tm .assert_equal (result , expected )
1111
1135
result = obj - other
1112
1136
tm .assert_equal (result , expected )
1113
- with pytest .raises (TypeError ):
1137
+ msg = r"cannot subtract .* from .*"
1138
+ with pytest .raises (TypeError , match = msg ):
1114
1139
other - obj
1115
1140
1116
1141
@pytest .mark .parametrize (
@@ -1133,7 +1158,8 @@ def test_parr_add_sub_tdt64_nat_array(self, box_with_array, other):
1133
1158
tm .assert_equal (result , expected )
1134
1159
result = obj - other
1135
1160
tm .assert_equal (result , expected )
1136
- with pytest .raises (TypeError ):
1161
+ msg = r"cannot subtract .* from .*"
1162
+ with pytest .raises (TypeError , match = msg ):
1137
1163
other - obj
1138
1164
1139
1165
# ---------------------------------------------------------------
0 commit comments