Skip to content

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

Open
@batterseapower

Description

@batterseapower

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexRelated to the Index class or subclasses

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions