You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I expected the two values to be equal even when the dtypes are datetime64[ns] vs datetime64[s].
At a minimum, I expected the treatment of dtypes in equality to be consistent for coordinates vs data variables, and for .equals vs .broadcast_equals.
Minimal Complete Verifiable Example
See above.
MVCE confirmation
Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
Complete example — the example is self-contained, including all data and the text of any traceback.
Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
New issue — a search of GitHub Issues suggests this is not a duplicate.
Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Anything else we need to know?
I suspect the cause is that pandas DatetimeIndex is not .equals when the dtype differs:
Indeed, the underlying issue here seems to be that pandas.DatetimeIndex.equals() requires matching dtypes, whereas .equals() on xarray.Variable (like NumPy) does not.
This is arguably a bug upstream in pandas, because the handling of other Index types is not sensitive to dtype:
I agree, it is awkward that the DatetimeIndex behavior in this context does not follow the behavior of other types of indexes. These are some relevant upstream issues: pandas-dev/pandas#55694, pandas-dev/pandas#33940. Maybe we can spur some more discussion there.
What happened?
When the datetime resolution of coordinates differs, this breaks equality via
.equals
:But not via
.broadcast_equals
:For data variables, equality via
.equals
holds even when the datetime resolution differs:What did you expect to happen?
I expected the two values to be equal even when the dtypes are
datetime64[ns]
vsdatetime64[s]
.At a minimum, I expected the treatment of dtypes in equality to be consistent for coordinates vs data variables, and for
.equals
vs.broadcast_equals
.Minimal Complete Verifiable Example
See above.
MVCE confirmation
Anything else we need to know?
I suspect the cause is that pandas DatetimeIndex is not
.equals
when the dtype differs:Environment
xarray: 2025.01.2
pandas: 2.2.3
numpy: 2.2.1
scipy: 1.13.1
netCDF4: 1.4.1
pydap: None
h5netcdf: 999
h5py: 3.11.0
zarr: 2.18.2
cftime: 1.6.4
nc_time_axis: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: 3.9.1
cartopy: None
seaborn: 0.12.2
numbagg: None
fsspec: 2023.3.0
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 0.dev0+unknown
pip: None
conda: None
pytest: None
mypy: None
IPython: 7.34.0
sphinx: None
The text was updated successfully, but these errors were encountered: