Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix DateOffset eq to depend on normalize attr #21404

Merged
merged 5 commits into from Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.0.txt
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`)
Copy link
Contributor

Choose a reason for hiding this comment

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

double backticks on normalize

-
-

Expand Down
52 changes: 24 additions & 28 deletions pandas/tests/tseries/offsets/test_offsets.py
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
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