Skip to content

BUG: pd.Timedelta breaks hash invariant #44504

Open
@harahu

Description

@harahu

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

import pandas as pd
import numpy as np

pd_td = pd.Timedelta(0)
np_td = np.timedelta64(0)

# One of these should be true
assert (pd_td == np_td and hash(pd_td) == hash(np_td)) or pd_td != np_td

Issue Description

Ref: https://bugs.python.org/issue45832

I was prompted by @rhettinger to bring this up with you.

pd.Timedelta and np.timedelta64 are in violation of the python hash invariant.

Specifically:

Hashable objects which compare equal must have the same hash value.

Expected Behavior

# Should pass
assert (pd_td == np_td and hash(pd_td) == hash(np_td)) or pd_td != np_td

Installed Versions

INSTALLED VERSIONS

commit : 945c9ed
python : 3.10.0.final.0
python-bits : 64
OS : Darwin
OS-release : 21.1.0
Version : Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:23 PDT 2021; root:xnu-8019.41.5~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_US.UTF-8

pandas : 1.3.4
numpy : 1.21.1
pytz : 2021.3
dateutil : 2.8.2
pip : 21.3.1
setuptools : 58.3.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : 7.29.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 6.0.0
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds DiscussionRequires discussion from core team before further actionTimedeltaTimedelta data type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions