@@ -636,12 +636,12 @@ def test_pi_sub_pi_with_nat(self):
636
636
expected = pd .Index ([pd .NaT , 0 * off , 0 * off , 0 * off , 0 * off ])
637
637
tm .assert_index_equal (result , expected )
638
638
639
- def test_parr_sub_pi_mismatched_freq (self , box_with_array ):
639
+ def test_parr_sub_pi_mismatched_freq (self , box_with_array , box_with_array2 ):
640
640
rng = period_range ("1/1/2000" , freq = "D" , periods = 5 )
641
641
other = period_range ("1/6/2000" , freq = "H" , periods = 5 )
642
- # TODO: parametrize over boxes for other?
643
642
644
643
rng = tm .box_expected (rng , box_with_array )
644
+ other = tm .box_expected (other , box_with_array2 )
645
645
msg = r"Input has different freq=[HD] from PeriodArray\(freq=[DH]\)"
646
646
with pytest .raises (IncompatibleFrequency , match = msg ):
647
647
rng - other
@@ -998,58 +998,67 @@ def test_pi_sub_intarray(self, int_holder):
998
998
# Timedelta-like (timedelta, timedelta64, Timedelta, Tick)
999
999
# TODO: Some of these are misnomers because of non-Tick DateOffsets
1000
1000
1001
- def test_pi_add_timedeltalike_minute_gt1 (self , three_days ):
1001
+ def test_parr_add_timedeltalike_minute_gt1 (self , three_days , box_with_array ):
1002
1002
# GH#23031 adding a time-delta-like offset to a PeriodArray that has
1003
1003
# minute frequency with n != 1. A more general case is tested below
1004
1004
# in test_pi_add_timedeltalike_tick_gt1, but here we write out the
1005
1005
# expected result more explicitly.
1006
1006
other = three_days
1007
1007
rng = period_range ("2014-05-01" , periods = 3 , freq = "2D" )
1008
+ rng = tm .box_expected (rng , box_with_array )
1008
1009
1009
1010
expected = PeriodIndex (["2014-05-04" , "2014-05-06" , "2014-05-08" ], freq = "2D" )
1011
+ expected = tm .box_expected (expected , box_with_array )
1010
1012
1011
1013
result = rng + other
1012
- tm .assert_index_equal (result , expected )
1014
+ tm .assert_equal (result , expected )
1013
1015
1014
1016
result = other + rng
1015
- tm .assert_index_equal (result , expected )
1017
+ tm .assert_equal (result , expected )
1016
1018
1017
1019
# subtraction
1018
1020
expected = PeriodIndex (["2014-04-28" , "2014-04-30" , "2014-05-02" ], freq = "2D" )
1021
+ expected = tm .box_expected (expected , box_with_array )
1019
1022
result = rng - other
1020
- tm .assert_index_equal (result , expected )
1023
+ tm .assert_equal (result , expected )
1021
1024
1022
1025
msg = "|" .join (
1023
1026
[
1024
- r"(:? bad operand type for unary -: 'PeriodArray') " ,
1025
- r"(:? cannot subtract PeriodArray from timedelta64\[[hD]\]) " ,
1027
+ r"bad operand type for unary -: 'PeriodArray'" ,
1028
+ r"cannot subtract PeriodArray from timedelta64\[[hD]\]" ,
1026
1029
]
1027
1030
)
1028
1031
with pytest .raises (TypeError , match = msg ):
1029
1032
other - rng
1030
1033
1031
1034
@pytest .mark .parametrize ("freqstr" , ["5ns" , "5us" , "5ms" , "5s" , "5T" , "5h" , "5d" ])
1032
- def test_pi_add_timedeltalike_tick_gt1 (self , three_days , freqstr ):
1035
+ def test_parr_add_timedeltalike_tick_gt1 (self , three_days , freqstr , box_with_array ):
1033
1036
# GH#23031 adding a time-delta-like offset to a PeriodArray that has
1034
1037
# tick-like frequency with n != 1
1035
1038
other = three_days
1036
1039
rng = period_range ("2014-05-01" , periods = 6 , freq = freqstr )
1040
+ first = rng [0 ]
1041
+ rng = tm .box_expected (rng , box_with_array )
1037
1042
1038
- expected = period_range (rng [0 ] + other , periods = 6 , freq = freqstr )
1043
+ expected = period_range (first + other , periods = 6 , freq = freqstr )
1044
+ expected = tm .box_expected (expected , box_with_array )
1039
1045
1040
1046
result = rng + other
1041
- tm .assert_index_equal (result , expected )
1047
+ tm .assert_equal (result , expected )
1042
1048
1043
1049
result = other + rng
1044
- tm .assert_index_equal (result , expected )
1050
+ tm .assert_equal (result , expected )
1045
1051
1046
1052
# subtraction
1047
- expected = period_range (rng [0 ] - other , periods = 6 , freq = freqstr )
1053
+ expected = period_range (first - other , periods = 6 , freq = freqstr )
1054
+ expected = tm .box_expected (expected , box_with_array )
1048
1055
result = rng - other
1049
- tm .assert_index_equal (result , expected )
1050
- msg = (
1051
- r"(:?bad operand type for unary -: 'PeriodArray')"
1052
- r"|(:?cannot subtract PeriodArray from timedelta64\[[hD]\])"
1056
+ tm .assert_equal (result , expected )
1057
+ msg = "|" .join (
1058
+ [
1059
+ r"bad operand type for unary -: 'PeriodArray'" ,
1060
+ r"cannot subtract PeriodArray from timedelta64\[[hD]\]" ,
1061
+ ]
1053
1062
)
1054
1063
with pytest .raises (TypeError , match = msg ):
1055
1064
other - rng
@@ -1078,9 +1087,13 @@ def test_pi_sub_isub_timedeltalike_daily(self, three_days):
1078
1087
rng -= other
1079
1088
tm .assert_index_equal (rng , expected )
1080
1089
1081
- def test_pi_add_sub_timedeltalike_freq_mismatch_daily (self , not_daily ):
1090
+ def test_parr_add_sub_timedeltalike_freq_mismatch_daily (
1091
+ self , not_daily , box_with_array
1092
+ ):
1082
1093
other = not_daily
1083
1094
rng = period_range ("2014-05-01" , "2014-05-15" , freq = "D" )
1095
+ rng = tm .box_expected (rng , box_with_array )
1096
+
1084
1097
msg = "Input has different freq(=.+)? from Period.*?\\ (freq=D\\ )"
1085
1098
with pytest .raises (IncompatibleFrequency , match = msg ):
1086
1099
rng + other
@@ -1102,9 +1115,12 @@ def test_pi_add_iadd_timedeltalike_hourly(self, two_hours):
1102
1115
rng += other
1103
1116
tm .assert_index_equal (rng , expected )
1104
1117
1105
- def test_pi_add_timedeltalike_mismatched_freq_hourly (self , not_hourly ):
1118
+ def test_parr_add_timedeltalike_mismatched_freq_hourly (
1119
+ self , not_hourly , box_with_array
1120
+ ):
1106
1121
other = not_hourly
1107
1122
rng = period_range ("2014-01-01 10:00" , "2014-01-05 10:00" , freq = "H" )
1123
+ rng = tm .box_expected (rng , box_with_array )
1108
1124
msg = "Input has different freq(=.+)? from Period.*?\\ (freq=H\\ )"
1109
1125
1110
1126
with pytest .raises (IncompatibleFrequency , match = msg ):
0 commit comments