From efedd5fea1d9c941ea43446aa66ee9c14127eaf6 Mon Sep 17 00:00:00 2001 From: OlivierLuG Date: Wed, 27 May 2020 22:46:40 +0200 Subject: [PATCH 1/3] TST #28980 Certain comparison operations misbehaving for period dtype --- pandas/tests/series/test_period.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/tests/series/test_period.py b/pandas/tests/series/test_period.py index b54c09e5750fd..202452dab5c3a 100644 --- a/pandas/tests/series/test_period.py +++ b/pandas/tests/series/test_period.py @@ -113,3 +113,13 @@ def test_to_period(self, input_vals): expected = Series([input_vals], dtype="Period[D]") result = Series([input_vals], dtype="datetime64[ns]").dt.to_period("D") tm.assert_series_equal(result, expected) + + @pytest.mark.parametrize("comparison_data", ["a", False, 1, 1.0, None]) + def test_comparison_operations(self, comparison_data): + # GH 28980 + expected = Series([False, False]) + result = ( + Series([pd.Period("2019"), pd.Period("2020")], dtype="period[A-DEC]") + == comparison_data + ) + tm.assert_series_equal(result, expected) From 26aaed37a69d2744840de1de472cc465c3c3d99c Mon Sep 17 00:00:00 2001 From: OlivierLuG Date: Thu, 28 May 2020 05:52:02 +0200 Subject: [PATCH 2/3] TST closes #28980 was split in 2 lines --- pandas/tests/series/test_period.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/tests/series/test_period.py b/pandas/tests/series/test_period.py index 202452dab5c3a..a4c00f4e8a687 100644 --- a/pandas/tests/series/test_period.py +++ b/pandas/tests/series/test_period.py @@ -118,8 +118,6 @@ def test_to_period(self, input_vals): def test_comparison_operations(self, comparison_data): # GH 28980 expected = Series([False, False]) - result = ( - Series([pd.Period("2019"), pd.Period("2020")], dtype="period[A-DEC]") - == comparison_data - ) + s = Series([pd.Period("2019"), pd.Period("2020")], dtype="period[A-DEC]") + result = s == comparison_data tm.assert_series_equal(result, expected) From 7f3614c2a5dd2473b1d94c4cdfba2ed54f6bac77 Mon Sep 17 00:00:00 2001 From: OlivierLuG Date: Thu, 28 May 2020 06:38:42 +0200 Subject: [PATCH 3/3] move test to 'tests/arithmetics/test_period.py' --- pandas/tests/arithmetic/test_period.py | 8 ++++++++ pandas/tests/series/test_period.py | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/tests/arithmetic/test_period.py b/pandas/tests/arithmetic/test_period.py index 9fc6568a019b6..d206622521816 100644 --- a/pandas/tests/arithmetic/test_period.py +++ b/pandas/tests/arithmetic/test_period.py @@ -1522,3 +1522,11 @@ def test_pi_sub_period_nat(self): exp = pd.TimedeltaIndex([np.nan, np.nan, np.nan, np.nan], name="idx") tm.assert_index_equal(idx - pd.Period("NaT", freq="M"), exp) tm.assert_index_equal(pd.Period("NaT", freq="M") - idx, exp) + + @pytest.mark.parametrize("scalars", ["a", False, 1, 1.0, None]) + def test_comparison_operations(self, scalars): + # GH 28980 + expected = Series([False, False]) + s = Series([pd.Period("2019"), pd.Period("2020")], dtype="period[A-DEC]") + result = s == scalars + tm.assert_series_equal(result, expected) diff --git a/pandas/tests/series/test_period.py b/pandas/tests/series/test_period.py index a4c00f4e8a687..b54c09e5750fd 100644 --- a/pandas/tests/series/test_period.py +++ b/pandas/tests/series/test_period.py @@ -113,11 +113,3 @@ def test_to_period(self, input_vals): expected = Series([input_vals], dtype="Period[D]") result = Series([input_vals], dtype="datetime64[ns]").dt.to_period("D") tm.assert_series_equal(result, expected) - - @pytest.mark.parametrize("comparison_data", ["a", False, 1, 1.0, None]) - def test_comparison_operations(self, comparison_data): - # GH 28980 - expected = Series([False, False]) - s = Series([pd.Period("2019"), pd.Period("2020")], dtype="period[A-DEC]") - result = s == comparison_data - tm.assert_series_equal(result, expected)