Skip to content

BUG: DatetimeIndex.equals returns false if units mismatch #55694

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

Open
2 of 3 tasks
batterseapower opened this issue Oct 26, 2023 · 4 comments
Open
2 of 3 tasks

BUG: DatetimeIndex.equals returns false if units mismatch #55694

batterseapower opened this issue Oct 26, 2023 · 4 comments
Labels
Bug Index Related to the Index class or subclasses

Comments

@batterseapower
Copy link
Contributor

Pandas version checks

  • 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 main branch of pandas.

Reproducible Example

assert pd.DatetimeIndex(['2020-01-01'], dtype='datetime64[s]').equals(
    pd.DatetimeIndex(['2020-01-01'], dtype='datetime64[ns]')
)

Issue Description

This assertion should pass, but it fails.

Expected Behavior

The assertion should pass for the same reason that this one does:

assert pd.Index([0, 1], dtype=int).equals(pd.Index([0., 1.], dtype=float))

Or that this one does:

assert np.array_equal(
    pd.DatetimeIndex(['2020-01-01'], dtype='datetime64[s]').values,
    pd.DatetimeIndex(['2020-01-01'], dtype='datetime64[ns]').values
)

Installed Versions

INSTALLED VERSIONS ------------------ commit : e86ed37 python : 3.10.10.final.0 python-bits : 64 OS : Linux OS-release : 4.18.0-348.20.1.el8_5.x86_64 Version : #1 SMP Thu Mar 10 20:59:28 UTC 2022 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_GB.UTF-8 LOCALE : en_GB.UTF-8

pandas : 2.1.1
numpy : 1.23.5
pytz : 2023.3
dateutil : 2.8.2
setuptools : 67.7.2
pip : 23.1.2
Cython : 3.0.0
pytest : 7.3.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.2
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.13.2
pandas_datareader : None
bs4 : 4.12.2
bottleneck : 1.3.7
dataframe-api-compat: None
fastparquet : None
fsspec : 2023.6.0
gcsfs : None
matplotlib : 3.7.1
numba : 0.56.4
numexpr : 2.8.7
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 10.0.1
pyreadstat : None
pyxlsb : None
s3fs : 2023.6.0
scipy : 1.10.1
sqlalchemy : None
tables : None
tabulate : None
xarray : 2023.4.2
xlrd : 2.0.1
zstandard : None
tzdata : 2023.3
qtpy : 2.3.1
pyqt5 : None

@batterseapower batterseapower added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 26, 2023
@ziadk
Copy link
Contributor

ziadk commented Oct 26, 2023

I think this is related to this issue #55564

@paulreece paulreece added Index Related to the Index class or subclasses and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 26, 2023
@paulreece
Copy link
Contributor

Confirmed. Exists on main and 2.1.x.

@jbrockmendel
Copy link
Member

Not related to #55564, but it is related to #55638 and #33940. 33940 is probably a good place to comment if you have an opinion here.

@avm19
Copy link
Contributor

avm19 commented Jan 4, 2024

This behaviour is not limited to pd.DatetimeIndex, but also applies to pd.Series and pd.Dataframe. At least in version 2.0.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Index Related to the Index class or subclasses
Projects
None yet
Development

No branches or pull requests

5 participants