Skip to content

Commit 60edd86

Browse files
Backport PR pandas-dev#37288: Regression in offsets caused offsets to be no longer hashable (pandas-dev#37326)
Co-authored-by: patrick <[email protected]>
1 parent 10717de commit 60edd86

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

doc/source/whatsnew/v1.1.4.rst

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Fixed regressions
2121
- Fixed regression in :meth:`Series.astype` converting ``None`` to ``"nan"`` when casting to string (:issue:`36904`)
2222
- Fixed regression in :class:`RollingGroupby` causing a segmentation fault with Index of dtype object (:issue:`36727`)
2323
- Fixed regression in :class:`PeriodDtype` comparing both equal and unequal to its string representation (:issue:`37265`)
24+
- Fixed regression in certain offsets (:meth:`pd.offsets.Day() <pandas.tseries.offsets.Day>` and below) no longer being hashable (:issue:`37267`)
2425

2526
.. ---------------------------------------------------------------------------
2627

pandas/_libs/tslibs/offsets.pyx

+5
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,11 @@ cdef class Tick(SingleConstructorOffset):
785785
def is_anchored(self) -> bool:
786786
return False
787787

788+
# This is identical to BaseOffset.__hash__, but has to be redefined here
789+
# for Python 3, because we've redefined __eq__.
790+
def __hash__(self) -> int:
791+
return hash(self._params)
792+
788793
# --------------------------------------------------------------------
789794
# Comparison and Arithmetic Methods
790795

pandas/tests/tseries/offsets/test_offsets.py

+5
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,11 @@ def test_isAnchored_deprecated(self, offset_types):
685685
expected = off.is_anchored()
686686
assert result == expected
687687

688+
def test_offsets_hashable(self, offset_types):
689+
# GH: 37267
690+
off = self._get_offset(offset_types)
691+
assert hash(off) is not None
692+
688693

689694
class TestDateOffset(Base):
690695
def setup_method(self, method):

0 commit comments

Comments
 (0)