From e54c6d87f0563ba335e9b15ca13b1a27ea44ed4e Mon Sep 17 00:00:00 2001 From: Raisa Dzhamtyrova Date: Sun, 9 Feb 2020 16:45:39 +0000 Subject: [PATCH 1/2] add messages for test_period.py --- pandas/tests/arithmetic/test_period.py | 97 ++++++++++++++++++-------- 1 file changed, 67 insertions(+), 30 deletions(-) diff --git a/pandas/tests/arithmetic/test_period.py b/pandas/tests/arithmetic/test_period.py index abb667260f094..5a1cfd596fac9 100644 --- a/pandas/tests/arithmetic/test_period.py +++ b/pandas/tests/arithmetic/test_period.py @@ -153,14 +153,18 @@ def test_eq_integer_disallowed(self, other): result = idx == other tm.assert_numpy_array_equal(result, expected) - - with pytest.raises(TypeError): + msg = ( + r"(:?Invalid comparison between dtype=period\[D\] and .*)" + r"|(:?Cannot compare type Period with type .*)" + ) + # breakpoint() + with pytest.raises(TypeError, match=msg): idx < other - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): idx > other - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): idx <= other - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): idx >= other def test_pi_cmp_period(self): @@ -587,10 +591,11 @@ def test_parr_add_iadd_parr_raises(self, box_with_array): # a set operation (union). This has since been changed to # raise a TypeError. See GH#14164 and GH#13077 for historical # reference. - with pytest.raises(TypeError): + msg = r"unsupported operand type\(s\) for \+: .* and .*" + with pytest.raises(TypeError, match=msg): rng + other - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): rng += other def test_pi_sub_isub_pi(self): @@ -625,7 +630,9 @@ def test_parr_sub_pi_mismatched_freq(self, box_with_array): # TODO: parametrize over boxes for other? rng = tm.box_expected(rng, box_with_array) - with pytest.raises(IncompatibleFrequency): + # breakpoint() + msg = r"Input has different freq=[HD] from PeriodArray\(freq=[DH]\)" + with pytest.raises(IncompatibleFrequency, match=msg): rng - other @pytest.mark.parametrize("n", [1, 2, 3, 4]) @@ -677,7 +684,9 @@ def test_parr_add_sub_float_raises(self, op, other, box_with_array): dti = pd.DatetimeIndex(["2011-01-01", "2011-01-02"], freq="D") pi = dti.to_period("D") pi = tm.box_expected(pi, box_with_array) - with pytest.raises(TypeError): + # breakpoint() + msg = r"unsupported operand type\(s\) for [+-]: .* and .*" + with pytest.raises(TypeError, match=msg): op(pi, other) @pytest.mark.parametrize( @@ -700,13 +709,19 @@ def test_parr_add_sub_invalid(self, other, box_with_array): rng = pd.period_range("1/1/2000", freq="D", periods=3) rng = tm.box_expected(rng, box_with_array) - with pytest.raises(TypeError): + # breakpoint() + msg = ( + r"(:?cannot add PeriodArray and .*)" + r"|(:?cannot subtract .* from (:?a\s)?.*)" + r"|(:?unsupported operand type\(s\) for \+: .* and .*)" + ) + with pytest.raises(TypeError, match=msg): rng + other - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): other + rng - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): rng - other - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): other - rng # ----------------------------------------------------------------- @@ -716,15 +731,17 @@ def test_pi_add_sub_td64_array_non_tick_raises(self): rng = pd.period_range("1/1/2000", freq="Q", periods=3) tdi = pd.TimedeltaIndex(["-1 Day", "-1 Day", "-1 Day"]) tdarr = tdi.values - - with pytest.raises(IncompatibleFrequency): + # breakpoint() + msg = r"Input has different freq=None from PeriodArray\(freq=Q-DEC\)" + with pytest.raises(IncompatibleFrequency, match=msg): rng + tdarr - with pytest.raises(IncompatibleFrequency): + with pytest.raises(IncompatibleFrequency, match=msg): tdarr + rng - with pytest.raises(IncompatibleFrequency): + with pytest.raises(IncompatibleFrequency, match=msg): rng - tdarr - with pytest.raises(TypeError): + msg = r"cannot subtract PeriodArray from timedelta64\[ns\]" + with pytest.raises(TypeError, match=msg): tdarr - rng def test_pi_add_sub_td64_array_tick(self): @@ -751,10 +768,12 @@ def test_pi_add_sub_td64_array_tick(self): result = rng - tdarr tm.assert_index_equal(result, expected) - with pytest.raises(TypeError): + # breakpoint() + msg = r"cannot subtract .* from .*" + with pytest.raises(TypeError, match=msg): tdarr - rng - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): tdi - rng # ----------------------------------------------------------------- @@ -783,10 +802,12 @@ def test_pi_add_offset_array(self, box): unanchored = np.array([pd.offsets.Hour(n=1), pd.offsets.Minute(n=-2)]) # addition/subtraction ops with incompatible offsets should issue # a PerformanceWarning and _then_ raise a TypeError. - with pytest.raises(IncompatibleFrequency): + # breakpoint() + msg = r"Input cannot be converted to Period\(freq=Q-DEC\)" + with pytest.raises(IncompatibleFrequency, match=msg): with tm.assert_produces_warning(PerformanceWarning): pi + unanchored - with pytest.raises(IncompatibleFrequency): + with pytest.raises(IncompatibleFrequency, match=msg): with tm.assert_produces_warning(PerformanceWarning): unanchored + pi @@ -811,10 +832,11 @@ def test_pi_sub_offset_array(self, box): # addition/subtraction ops with anchored offsets should issue # a PerformanceWarning and _then_ raise a TypeError. - with pytest.raises(IncompatibleFrequency): + msg = r"Input has different freq=-1M from Period\(freq=Q-DEC\)" + with pytest.raises(IncompatibleFrequency, match=msg): with tm.assert_produces_warning(PerformanceWarning): pi - anchored - with pytest.raises(IncompatibleFrequency): + with pytest.raises(IncompatibleFrequency, match=msg): with tm.assert_produces_warning(PerformanceWarning): anchored - pi @@ -924,7 +946,9 @@ def test_pi_sub_intarray(self, int_holder): expected = pd.PeriodIndex([pd.Period("2014Q1"), pd.Period("NaT")]) tm.assert_index_equal(result, expected) - with pytest.raises(TypeError): + # breakpoint() + msg = r"bad operand type for unary -: 'PeriodArray'" + with pytest.raises(TypeError, match=msg): other - pi # --------------------------------------------------------------- @@ -952,7 +976,12 @@ def test_pi_add_timedeltalike_minute_gt1(self, three_days): result = rng - other tm.assert_index_equal(result, expected) - with pytest.raises(TypeError): + # breakpoint() + msg = ( + r"(:?bad operand type for unary -: 'PeriodArray')" + r"|(:?cannot subtract PeriodArray from timedelta64\[[hD]\])" + ) + with pytest.raises(TypeError, match=msg): other - rng @pytest.mark.parametrize("freqstr", ["5ns", "5us", "5ms", "5s", "5T", "5h", "5d"]) @@ -974,8 +1003,12 @@ def test_pi_add_timedeltalike_tick_gt1(self, three_days, freqstr): expected = pd.period_range(rng[0] - other, periods=6, freq=freqstr) result = rng - other tm.assert_index_equal(result, expected) - - with pytest.raises(TypeError): + # breakpoint() + msg = ( + r"(:?bad operand type for unary -: 'PeriodArray')" + r"|(:?cannot subtract PeriodArray from timedelta64\[[hD]\])" + ) + with pytest.raises(TypeError, match=msg): other - rng def test_pi_add_iadd_timedeltalike_daily(self, three_days): @@ -1110,7 +1143,9 @@ def test_parr_add_sub_td64_nat(self, box_with_array, transpose): tm.assert_equal(result, expected) result = obj - other tm.assert_equal(result, expected) - with pytest.raises(TypeError): + # breakpoint() + msg = r"cannot subtract .* from .*" + with pytest.raises(TypeError, match=msg): other - obj @pytest.mark.parametrize( @@ -1133,7 +1168,9 @@ def test_parr_add_sub_tdt64_nat_array(self, box_with_array, other): tm.assert_equal(result, expected) result = obj - other tm.assert_equal(result, expected) - with pytest.raises(TypeError): + # breakpoint() + msg = r"cannot subtract .* from .*" + with pytest.raises(TypeError, match=msg): other - obj # --------------------------------------------------------------- From 615d05ffb47d4117b53ce26324e9746b82df0259 Mon Sep 17 00:00:00 2001 From: Raisa Dzhamtyrova Date: Sun, 9 Feb 2020 16:51:58 +0000 Subject: [PATCH 2/2] remove breakpoints --- pandas/tests/arithmetic/test_period.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/pandas/tests/arithmetic/test_period.py b/pandas/tests/arithmetic/test_period.py index 5a1cfd596fac9..4cf1988a33de1 100644 --- a/pandas/tests/arithmetic/test_period.py +++ b/pandas/tests/arithmetic/test_period.py @@ -157,7 +157,6 @@ def test_eq_integer_disallowed(self, other): r"(:?Invalid comparison between dtype=period\[D\] and .*)" r"|(:?Cannot compare type Period with type .*)" ) - # breakpoint() with pytest.raises(TypeError, match=msg): idx < other with pytest.raises(TypeError, match=msg): @@ -630,7 +629,6 @@ def test_parr_sub_pi_mismatched_freq(self, box_with_array): # TODO: parametrize over boxes for other? rng = tm.box_expected(rng, box_with_array) - # breakpoint() msg = r"Input has different freq=[HD] from PeriodArray\(freq=[DH]\)" with pytest.raises(IncompatibleFrequency, match=msg): rng - other @@ -684,7 +682,6 @@ def test_parr_add_sub_float_raises(self, op, other, box_with_array): dti = pd.DatetimeIndex(["2011-01-01", "2011-01-02"], freq="D") pi = dti.to_period("D") pi = tm.box_expected(pi, box_with_array) - # breakpoint() msg = r"unsupported operand type\(s\) for [+-]: .* and .*" with pytest.raises(TypeError, match=msg): op(pi, other) @@ -709,7 +706,6 @@ def test_parr_add_sub_invalid(self, other, box_with_array): rng = pd.period_range("1/1/2000", freq="D", periods=3) rng = tm.box_expected(rng, box_with_array) - # breakpoint() msg = ( r"(:?cannot add PeriodArray and .*)" r"|(:?cannot subtract .* from (:?a\s)?.*)" @@ -731,7 +727,7 @@ def test_pi_add_sub_td64_array_non_tick_raises(self): rng = pd.period_range("1/1/2000", freq="Q", periods=3) tdi = pd.TimedeltaIndex(["-1 Day", "-1 Day", "-1 Day"]) tdarr = tdi.values - # breakpoint() + msg = r"Input has different freq=None from PeriodArray\(freq=Q-DEC\)" with pytest.raises(IncompatibleFrequency, match=msg): rng + tdarr @@ -768,7 +764,6 @@ def test_pi_add_sub_td64_array_tick(self): result = rng - tdarr tm.assert_index_equal(result, expected) - # breakpoint() msg = r"cannot subtract .* from .*" with pytest.raises(TypeError, match=msg): tdarr - rng @@ -802,7 +797,6 @@ def test_pi_add_offset_array(self, box): unanchored = np.array([pd.offsets.Hour(n=1), pd.offsets.Minute(n=-2)]) # addition/subtraction ops with incompatible offsets should issue # a PerformanceWarning and _then_ raise a TypeError. - # breakpoint() msg = r"Input cannot be converted to Period\(freq=Q-DEC\)" with pytest.raises(IncompatibleFrequency, match=msg): with tm.assert_produces_warning(PerformanceWarning): @@ -946,7 +940,6 @@ def test_pi_sub_intarray(self, int_holder): expected = pd.PeriodIndex([pd.Period("2014Q1"), pd.Period("NaT")]) tm.assert_index_equal(result, expected) - # breakpoint() msg = r"bad operand type for unary -: 'PeriodArray'" with pytest.raises(TypeError, match=msg): other - pi @@ -976,7 +969,6 @@ def test_pi_add_timedeltalike_minute_gt1(self, three_days): result = rng - other tm.assert_index_equal(result, expected) - # breakpoint() msg = ( r"(:?bad operand type for unary -: 'PeriodArray')" r"|(:?cannot subtract PeriodArray from timedelta64\[[hD]\])" @@ -1003,7 +995,6 @@ def test_pi_add_timedeltalike_tick_gt1(self, three_days, freqstr): expected = pd.period_range(rng[0] - other, periods=6, freq=freqstr) result = rng - other tm.assert_index_equal(result, expected) - # breakpoint() msg = ( r"(:?bad operand type for unary -: 'PeriodArray')" r"|(:?cannot subtract PeriodArray from timedelta64\[[hD]\])" @@ -1143,7 +1134,6 @@ def test_parr_add_sub_td64_nat(self, box_with_array, transpose): tm.assert_equal(result, expected) result = obj - other tm.assert_equal(result, expected) - # breakpoint() msg = r"cannot subtract .* from .*" with pytest.raises(TypeError, match=msg): other - obj @@ -1168,7 +1158,6 @@ def test_parr_add_sub_tdt64_nat_array(self, box_with_array, other): tm.assert_equal(result, expected) result = obj - other tm.assert_equal(result, expected) - # breakpoint() msg = r"cannot subtract .* from .*" with pytest.raises(TypeError, match=msg): other - obj