From 7506bc7d6b2dbfcaff06d499f315e7a6afd9b429 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sat, 9 Jun 2018 19:04:55 -0700 Subject: [PATCH 1/3] fix DateOffset eq to depend on normalize attr --- doc/source/whatsnew/v0.24.0.txt | 2 +- pandas/tests/tseries/offsets/test_offsets.py | 52 +++++++++----------- pandas/tseries/offsets.py | 2 +- 3 files changed, 26 insertions(+), 30 deletions(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index de985d4db5fa3..a2cea271e3aa3 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -91,7 +91,7 @@ Categorical Datetimelike ^^^^^^^^^^^^ -- +- Fixed Bug where two :class:`DateOffset` objects with different `normalize` attributes could evaluate as equal (:issue:`????`) - - diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 5369b1a94a956..f841d4a81d379 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -518,11 +518,10 @@ def setup_method(self, method): self.offset2 = BDay(2) def test_different_normalize_equals(self): - # equivalent in this special case - offset = BDay() - offset2 = BDay() - offset2.normalize = True - assert offset == offset2 + # GH#???? changed __eq__ to return False when `normalize` doesnt match + offset = self._offset() + offset2 = self._offset(normalize=True) + assert offset != offset2 def test_repr(self): assert repr(self.offset) == '' @@ -713,11 +712,10 @@ def test_constructor_errors(self): BusinessHour(start='14:00:05') def test_different_normalize_equals(self): - # equivalent in this special case + # GH#???? changed __eq__ to return False when `normalize` doesnt match offset = self._offset() - offset2 = self._offset() - offset2.normalize = True - assert offset == offset2 + offset2 = self._offset(normalize=True) + assert offset != offset2 def test_repr(self): assert repr(self.offset1) == '' @@ -1391,11 +1389,10 @@ def test_constructor_errors(self): CustomBusinessHour(start='14:00:05') def test_different_normalize_equals(self): - # equivalent in this special case + # GH#???? changed __eq__ to return False when `normalize` doesnt match offset = self._offset() - offset2 = self._offset() - offset2.normalize = True - assert offset == offset2 + offset2 = self._offset(normalize=True) + assert offset != offset2 def test_repr(self): assert repr(self.offset1) == '' @@ -1632,11 +1629,10 @@ def setup_method(self, method): self.offset2 = CDay(2) def test_different_normalize_equals(self): - # equivalent in this special case - offset = CDay() - offset2 = CDay() - offset2.normalize = True - assert offset == offset2 + # GH#???? changed __eq__ to return False when `normalize` doesnt match + offset = self._offset() + offset2 = self._offset(normalize=True) + assert offset != offset2 def test_repr(self): assert repr(self.offset) == '' @@ -1916,13 +1912,13 @@ def test_copy(self): class TestCustomBusinessMonthEnd(CustomBusinessMonthBase, Base): _object = CBMonthEnd + _offset = CBMonthEnd def test_different_normalize_equals(self): - # equivalent in this special case - offset = CBMonthEnd() - offset2 = CBMonthEnd() - offset2.normalize = True - assert offset == offset2 + # GH#???? changed __eq__ to return False when `normalize` doesnt match + offset = self._offset() + offset2 = self._offset(normalize=True) + assert offset != offset2 def test_repr(self): assert repr(self.offset) == '' @@ -2033,13 +2029,13 @@ def test_datetimeindex(self): class TestCustomBusinessMonthBegin(CustomBusinessMonthBase, Base): _object = CBMonthBegin + _offset = CBMonthBegin def test_different_normalize_equals(self): - # equivalent in this special case - offset = CBMonthBegin() - offset2 = CBMonthBegin() - offset2.normalize = True - assert offset == offset2 + # GH#???? changed __eq__ to return False when `normalize` doesnt match + offset = self._offset() + offset2 = self._offset(normalize=True) + assert offset != offset2 def test_repr(self): assert repr(self.offset) == '' diff --git a/pandas/tseries/offsets.py b/pandas/tseries/offsets.py index c294110d89ec5..a5ac0c9540c58 100644 --- a/pandas/tseries/offsets.py +++ b/pandas/tseries/offsets.py @@ -290,7 +290,7 @@ def _params(self): all_paras = self.__dict__.copy() if 'holidays' in all_paras and not all_paras['holidays']: all_paras.pop('holidays') - exclude = ['kwds', 'name', 'normalize', 'calendar'] + exclude = ['kwds', 'name', 'calendar'] attrs = [(k, v) for k, v in all_paras.items() if (k not in exclude) and (k[0] != '_')] attrs = sorted(set(attrs)) From e12329eebdd35b412dd265a1bf9bfea3b6feabf7 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sat, 9 Jun 2018 19:10:16 -0700 Subject: [PATCH 2/3] Fill in GH refernece --- doc/source/whatsnew/v0.24.0.txt | 2 +- pandas/tests/tseries/offsets/test_offsets.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index a2cea271e3aa3..98a4ac593ebc2 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -91,7 +91,7 @@ Categorical Datetimelike ^^^^^^^^^^^^ -- Fixed Bug where two :class:`DateOffset` objects with different `normalize` attributes could evaluate as equal (:issue:`????`) +- Fixed Bug where two :class:`DateOffset` objects with different `normalize` attributes could evaluate as equal (:issue:`21404`) - - diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index f841d4a81d379..bd1f720f958e6 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -518,7 +518,7 @@ def setup_method(self, method): self.offset2 = BDay(2) def test_different_normalize_equals(self): - # GH#???? changed __eq__ to return False when `normalize` doesnt match + # GH#21404 changed __eq__ to return False when `normalize` doesnt match offset = self._offset() offset2 = self._offset(normalize=True) assert offset != offset2 @@ -712,7 +712,7 @@ def test_constructor_errors(self): BusinessHour(start='14:00:05') def test_different_normalize_equals(self): - # GH#???? changed __eq__ to return False when `normalize` doesnt match + # GH#21404 changed __eq__ to return False when `normalize` doesnt match offset = self._offset() offset2 = self._offset(normalize=True) assert offset != offset2 @@ -1389,7 +1389,7 @@ def test_constructor_errors(self): CustomBusinessHour(start='14:00:05') def test_different_normalize_equals(self): - # GH#???? changed __eq__ to return False when `normalize` doesnt match + # GH#21404 changed __eq__ to return False when `normalize` doesnt match offset = self._offset() offset2 = self._offset(normalize=True) assert offset != offset2 @@ -1629,7 +1629,7 @@ def setup_method(self, method): self.offset2 = CDay(2) def test_different_normalize_equals(self): - # GH#???? changed __eq__ to return False when `normalize` doesnt match + # GH#21404 changed __eq__ to return False when `normalize` doesnt match offset = self._offset() offset2 = self._offset(normalize=True) assert offset != offset2 @@ -1915,7 +1915,7 @@ class TestCustomBusinessMonthEnd(CustomBusinessMonthBase, Base): _offset = CBMonthEnd def test_different_normalize_equals(self): - # GH#???? changed __eq__ to return False when `normalize` doesnt match + # GH#21404 changed __eq__ to return False when `normalize` doesnt match offset = self._offset() offset2 = self._offset(normalize=True) assert offset != offset2 @@ -2032,7 +2032,7 @@ class TestCustomBusinessMonthBegin(CustomBusinessMonthBase, Base): _offset = CBMonthBegin def test_different_normalize_equals(self): - # GH#???? changed __eq__ to return False when `normalize` doesnt match + # GH#21404 changed __eq__ to return False when `normalize` doesnt match offset = self._offset() offset2 = self._offset(normalize=True) assert offset != offset2 From ee9d96d731616f00c180d2408e4660a25f44637f Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Tue, 12 Jun 2018 09:25:44 -0700 Subject: [PATCH 3/3] more backticks --- doc/source/whatsnew/v0.24.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index 98a4ac593ebc2..b0e32baee6456 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -91,7 +91,7 @@ Categorical Datetimelike ^^^^^^^^^^^^ -- Fixed Bug where two :class:`DateOffset` objects with different `normalize` attributes could evaluate as equal (:issue:`21404`) +- Fixed bug where two :class:`DateOffset` objects with different ``normalize`` attributes could evaluate as equal (:issue:`21404`) - -