diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index 68c1839221508..6d5e40d37c8df 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`) - - diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 8bf0d9f915d04..6fd525f02f55c 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -564,11 +564,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#21404 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) == '' @@ -734,11 +733,10 @@ def test_constructor_errors(self): BusinessHour(start='14:00:05') def test_different_normalize_equals(self): - # equivalent in this special case + # GH#21404 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) == '' @@ -1397,11 +1395,10 @@ def test_constructor_errors(self): CustomBusinessHour(start='14:00:05') def test_different_normalize_equals(self): - # equivalent in this special case + # GH#21404 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) == '' @@ -1627,11 +1624,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#21404 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) == '' @@ -1865,11 +1861,10 @@ class TestCustomBusinessMonthEnd(CustomBusinessMonthBase, Base): _offset = CBMonthEnd def test_different_normalize_equals(self): - # equivalent in this special case - offset = CBMonthEnd() - offset2 = CBMonthEnd() - offset2.normalize = True - assert offset == offset2 + # GH#21404 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) == '' @@ -1982,11 +1977,10 @@ class TestCustomBusinessMonthBegin(CustomBusinessMonthBase, Base): _offset = CBMonthBegin def test_different_normalize_equals(self): - # equivalent in this special case - offset = CBMonthBegin() - offset2 = CBMonthBegin() - offset2.normalize = True - assert offset == offset2 + # GH#21404 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 a5a983bf94bb8..99f97d8fc7bc0 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))