Skip to content

Regression in offsets caused offsets to be no longer hashable #37288

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

Merged
merged 8 commits into from
Oct 22, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.1.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Fixed regressions
- Fixed regression in :class:`RollingGroupby` causing a segmentation fault with Index of dtype object (:issue:`36727`)
- Fixed regression in :meth:`DataFrame.resample(...).apply(...)` raised ``AttributeError`` when input was a :class:`DataFrame` and only a :class:`Series` was evaluated (:issue:`36951`)
- Fixed regression in :class:`PeriodDtype` comparing both equal and unequal to its string representation (:issue:`37265`)
- Fixed regression in :meth:`pd.offsets.Day() <pandas.tseries.offsets.Day>` and associated functions caused that offsets were no longer hashable (:issue:`37267`)
- Fixed regression in certain offsets (:meth:`pd.offsets.Day() <pandas.tseries.offsets.Day>` and below) no longer being hashable (:issue:`37267`)

.. ---------------------------------------------------------------------------

Expand Down
7 changes: 4 additions & 3 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -752,9 +752,6 @@ cdef class Tick(SingleConstructorOffset):
"Tick offset with `normalize=True` are not allowed."
)

def __hash__(self) -> int:
return hash(self._params)

# FIXME: Without making this cpdef, we get AttributeError when calling
# from __mul__
cpdef Tick _next_higher_resolution(Tick self):
Expand Down Expand Up @@ -794,6 +791,10 @@ cdef class Tick(SingleConstructorOffset):
def is_anchored(self) -> bool:
return False

# This is identical to DateOffset.__hash__, but has to be redefined here
# for Python 3, because we've redefined __eq__.
def __hash__(self) -> int:
return hash(self._params)
# --------------------------------------------------------------------
# Comparison and Arithmetic Methods

Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/tseries/offsets/test_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,8 @@ def test_isAnchored_deprecated(self, offset_types):

def test_offsets_hashable(self, offset_types):
# GH: 37267
assert hash(offset_types) is not None
off = self._get_offset(offset_types)
assert hash(off) is not None


class TestDateOffset(Base):
Expand Down