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
From version 2025.1.2, this is no longer true, and we get
datetime64[s]
datetime64[ns]
Together with the equality check failing (pandas-dev/pandas#55694), this means comparing DataArrays and Datasets is now subtly dependent on whether datetime or np.datetime64 was used to construct them.
Is this the intended behaviour? Is there a recommended way to deal with this difference beyond requiring the users to always specify np.datetime(..., 'ns')?
The text was updated successfully, but these errors were encountered:
In some sense, yes, in alignment with pandas we did intentionally relax the previous automatic casting of all datetime-like objects passed to xarray to nanosecond resolution. For certain use cases it is beneficial to be able to use coarser resolution times. However we agree the dtype equality issue for DatetimeIndex-backed variables is a particularly awkward unintended consequence (see also #10045). Ideally this could be addressed upstream.
In terms of resolutions, specifically "s", "ms", "us", and "ns" are now permitted. Following pandas, coarser resolution np.datetime64 values are cast to "s" resolution, and finer resolution values are cast to "ns" resolution, but anything in between passes through unmodified. Xarray similarly defers to pandas on how to translate datetime.datetime objects into np.datetime64 values. For better or worse pandas still always chooses "ns" resolution in that context.
To the extent that we support datetime values with different resolutions, it seems somewhat inevitable that without special care users will end up with DataArrays of different dtypes, but it would be nice if equality was not sensitive to dtype.
What is your issue?
In xarray prior to
2025.1.2
usage ofnp.datetime64
anddatetime
resulted in identical resultwould yield
From version
2025.1.2
, this is no longer true, and we getTogether with the equality check failing (pandas-dev/pandas#55694), this means comparing
DataArray
s andDataset
s is now subtly dependent on whetherdatetime
ornp.datetime64
was used to construct them.Is this the intended behaviour? Is there a recommended way to deal with this difference beyond requiring the users to always specify
np.datetime(..., 'ns')
?The text was updated successfully, but these errors were encountered: