Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Categorical
Datetimelike
^^^^^^^^^^^^

-
- Fixed bug where two :class:`DateOffset` objects with different ``normalize`` attributes could evaluate as equal (:issue:`21404`)
-
-

Expand Down
52 changes: 24 additions & 28 deletions pandas/tests/tseries/offsets/test_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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#21404 changed __eq__ to return False when `normalize` doesnt match
offset = self._offset()
offset2 = self._offset(normalize=True)
assert offset != offset2
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After substituting in self._offset for BDay, this test is identical to 5 others in this file. I'm putting together a separate PR to try to de-duplicate and parametrize a bunch of things like this.


def test_repr(self):
assert repr(self.offset) == '<BusinessDay>'
Expand Down Expand Up @@ -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#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) == '<BusinessHour: BH=09:00-17:00>'
Expand Down Expand Up @@ -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#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) == '<CustomBusinessHour: CBH=09:00-17:00>'
Expand Down Expand Up @@ -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#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) == '<CustomBusinessDay>'
Expand Down Expand Up @@ -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#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) == '<CustomBusinessMonthEnd>'
Expand Down Expand Up @@ -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#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) == '<CustomBusinessMonthBegin>'
Expand Down
2 changes: 1 addition & 1 deletion pandas/tseries/offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down