Skip to content

Commit

Permalink
Backport PR pandas-dev#37288: Regression in offsets caused offsets to…
Browse files Browse the repository at this point in the history
… be no longer hashable
  • Loading branch information
phofl authored and meeseeksmachine committed Oct 22, 2020
1 parent 10717de commit adae73f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.4.rst
Expand Up @@ -21,6 +21,7 @@ Fixed regressions
- Fixed regression in :meth:`Series.astype` converting ``None`` to ``"nan"`` when casting to string (:issue:`36904`)
- Fixed regression in :class:`RollingGroupby` causing a segmentation fault with Index of dtype object (:issue:`36727`)
- Fixed regression in :class:`PeriodDtype` comparing both equal and unequal to its string representation (:issue:`37265`)
- Fixed regression in certain offsets (:meth:`pd.offsets.Day() <pandas.tseries.offsets.Day>` and below) no longer being hashable (:issue:`37267`)

.. ---------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions pandas/_libs/tslibs/offsets.pyx
Expand Up @@ -785,6 +785,11 @@ cdef class Tick(SingleConstructorOffset):
def is_anchored(self) -> bool:
return False

# This is identical to BaseOffset.__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
5 changes: 5 additions & 0 deletions pandas/tests/tseries/offsets/test_offsets.py
Expand Up @@ -685,6 +685,11 @@ def test_isAnchored_deprecated(self, offset_types):
expected = off.is_anchored()
assert result == expected

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


class TestDateOffset(Base):
def setup_method(self, method):
Expand Down

0 comments on commit adae73f

Please sign in to comment.