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

BUG: Fix failing hash function for certain non-ns resolution Timedeltas #54037

Merged
merged 5 commits into from
Jul 7, 2023
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 pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ cdef class _Timedelta(timedelta):
# resolution.
try:
obj = (<_Timedelta>self)._as_creso(<NPY_DATETIMEUNIT>(self._creso + 1))
except OverflowError:
except OutOfBoundsTimedelta:
# Doesn't fit, so we're off the hook
return hash(self._value)
else:
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/scalar/timedelta/test_timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ def test_resolution(self, td):
assert result == expected
assert result._creso == expected._creso

def test_hash(self) -> None:
second_resolution_max = Timedelta(0).as_unit("s").max
harahu marked this conversation as resolved.
Show resolved Hide resolved

assert hash(second_resolution_max) == 42


def test_timedelta_class_min_max_resolution():
# when accessed on the class (as opposed to an instance), we default
Expand Down