Skip to content

Commit e0f81b3

Browse files
phoflKevin D Smith
authored and
Kevin D Smith
committed
Regression in offsets caused offsets to be no longer hashable (pandas-dev#37288)
1 parent f4620f8 commit e0f81b3

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
@@ -22,6 +22,7 @@ Fixed regressions
2222
- Fixed regression in :class:`RollingGroupby` causing a segmentation fault with Index of dtype object (:issue:`36727`)
2323
- Fixed regression in :meth:`DataFrame.resample(...).apply(...)` raised ``AttributeError`` when input was a :class:`DataFrame` and only a :class:`Series` was evaluated (:issue:`36951`)
2424
- Fixed regression in :class:`PeriodDtype` comparing both equal and unequal to its string representation (:issue:`37265`)
25+
- Fixed regression in certain offsets (:meth:`pd.offsets.Day() <pandas.tseries.offsets.Day>` and below) no longer being hashable (:issue:`37267`)
2526

2627
.. ---------------------------------------------------------------------------
2728

pandas/_libs/tslibs/offsets.pyx

+5
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,11 @@ cdef class Tick(SingleConstructorOffset):
791791
def is_anchored(self) -> bool:
792792
return False
793793

794+
# This is identical to BaseOffset.__hash__, but has to be redefined here
795+
# for Python 3, because we've redefined __eq__.
796+
def __hash__(self) -> int:
797+
return hash(self._params)
798+
794799
# --------------------------------------------------------------------
795800
# Comparison and Arithmetic Methods
796801

pandas/tests/tseries/offsets/test_offsets.py

+5
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,11 @@ def test_isAnchored_deprecated(self, offset_types):
678678
expected = off.is_anchored()
679679
assert result == expected
680680

681+
def test_offsets_hashable(self, offset_types):
682+
# GH: 37267
683+
off = self._get_offset(offset_types)
684+
assert hash(off) is not None
685+
681686

682687
class TestDateOffset(Base):
683688
def setup_method(self, method):

0 commit comments

Comments
 (0)