Skip to content

Commit b5fc769

Browse files
jbrockmendelgfyoung
authored andcommitted
BUG: Fix DateOffset eq to depend on normalize attr (#21404)
Partially addresses gh-18854
1 parent 576d5c6 commit b5fc769

File tree

3 files changed

+24
-30
lines changed

3 files changed

+24
-30
lines changed

doc/source/whatsnew/v0.24.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Categorical
9191
Datetimelike
9292
^^^^^^^^^^^^
9393

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

pandas/tests/tseries/offsets/test_offsets.py

+22-28
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,10 @@ def setup_method(self, method):
564564
self.offset2 = BDay(2)
565565

566566
def test_different_normalize_equals(self):
567-
# equivalent in this special case
568-
offset = BDay()
569-
offset2 = BDay()
570-
offset2.normalize = True
571-
assert offset == offset2
567+
# GH#21404 changed __eq__ to return False when `normalize` doesnt match
568+
offset = self._offset()
569+
offset2 = self._offset(normalize=True)
570+
assert offset != offset2
572571

573572
def test_repr(self):
574573
assert repr(self.offset) == '<BusinessDay>'
@@ -734,11 +733,10 @@ def test_constructor_errors(self):
734733
BusinessHour(start='14:00:05')
735734

736735
def test_different_normalize_equals(self):
737-
# equivalent in this special case
736+
# GH#21404 changed __eq__ to return False when `normalize` doesnt match
738737
offset = self._offset()
739-
offset2 = self._offset()
740-
offset2.normalize = True
741-
assert offset == offset2
738+
offset2 = self._offset(normalize=True)
739+
assert offset != offset2
742740

743741
def test_repr(self):
744742
assert repr(self.offset1) == '<BusinessHour: BH=09:00-17:00>'
@@ -1397,11 +1395,10 @@ def test_constructor_errors(self):
13971395
CustomBusinessHour(start='14:00:05')
13981396

13991397
def test_different_normalize_equals(self):
1400-
# equivalent in this special case
1398+
# GH#21404 changed __eq__ to return False when `normalize` doesnt match
14011399
offset = self._offset()
1402-
offset2 = self._offset()
1403-
offset2.normalize = True
1404-
assert offset == offset2
1400+
offset2 = self._offset(normalize=True)
1401+
assert offset != offset2
14051402

14061403
def test_repr(self):
14071404
assert repr(self.offset1) == '<CustomBusinessHour: CBH=09:00-17:00>'
@@ -1627,11 +1624,10 @@ def setup_method(self, method):
16271624
self.offset2 = CDay(2)
16281625

16291626
def test_different_normalize_equals(self):
1630-
# equivalent in this special case
1631-
offset = CDay()
1632-
offset2 = CDay()
1633-
offset2.normalize = True
1634-
assert offset == offset2
1627+
# GH#21404 changed __eq__ to return False when `normalize` doesnt match
1628+
offset = self._offset()
1629+
offset2 = self._offset(normalize=True)
1630+
assert offset != offset2
16351631

16361632
def test_repr(self):
16371633
assert repr(self.offset) == '<CustomBusinessDay>'
@@ -1865,11 +1861,10 @@ class TestCustomBusinessMonthEnd(CustomBusinessMonthBase, Base):
18651861
_offset = CBMonthEnd
18661862

18671863
def test_different_normalize_equals(self):
1868-
# equivalent in this special case
1869-
offset = CBMonthEnd()
1870-
offset2 = CBMonthEnd()
1871-
offset2.normalize = True
1872-
assert offset == offset2
1864+
# GH#21404 changed __eq__ to return False when `normalize` doesnt match
1865+
offset = self._offset()
1866+
offset2 = self._offset(normalize=True)
1867+
assert offset != offset2
18731868

18741869
def test_repr(self):
18751870
assert repr(self.offset) == '<CustomBusinessMonthEnd>'
@@ -1982,11 +1977,10 @@ class TestCustomBusinessMonthBegin(CustomBusinessMonthBase, Base):
19821977
_offset = CBMonthBegin
19831978

19841979
def test_different_normalize_equals(self):
1985-
# equivalent in this special case
1986-
offset = CBMonthBegin()
1987-
offset2 = CBMonthBegin()
1988-
offset2.normalize = True
1989-
assert offset == offset2
1980+
# GH#21404 changed __eq__ to return False when `normalize` doesnt match
1981+
offset = self._offset()
1982+
offset2 = self._offset(normalize=True)
1983+
assert offset != offset2
19901984

19911985
def test_repr(self):
19921986
assert repr(self.offset) == '<CustomBusinessMonthBegin>'

pandas/tseries/offsets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def _params(self):
290290
all_paras = self.__dict__.copy()
291291
if 'holidays' in all_paras and not all_paras['holidays']:
292292
all_paras.pop('holidays')
293-
exclude = ['kwds', 'name', 'normalize', 'calendar']
293+
exclude = ['kwds', 'name', 'calendar']
294294
attrs = [(k, v) for k, v in all_paras.items()
295295
if (k not in exclude) and (k[0] != '_')]
296296
attrs = sorted(set(attrs))

0 commit comments

Comments
 (0)