-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
DataArray constructor still coerces to np.datetime64[ns], not cftime in 0.11.0 #2587
Comments
Thanks for the clear report @Huite. Indeed we did not consider this particular use case when updating the behavior in version 0.11 (i.e. non-cftime dates passed to the DataArray constructor that are outside the As you noted, in this situation it would probably make sense to coerce these dates to a Note if you use
|
Thanks, I'll indeed use
|
In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity If this issue remains relevant, please comment here or remove the |
The example raises with xarray 2024.10.0: UserWarning: Converting non-nanosecond precision datetime values to nanosecond precision. This behavior can eventually be relaxed in xarray, as it is an artifact from pandas which is now beginning to support non-nanosecond precision values. This warning is caused by passing non-nanosecond np.datetime64 or np.timedelta64 values to the DataArray or Variable constructor; it can be silenced by converting the values to nanosecond precision ahead of time.
da = xr.DataArray(time, ("time",), {"time":time})
OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 1000-01-01 00:00:00 This should be working after #9618 is finalized. |
Code Sample
Results in:
Problem description
I was happy to see
cftime
as default in the release notes for 0.11.0:However, it seems that the DataArray constructor does not use
cftime
(yet?), and coerces tonp.datetime64[ns]
here:xarray/xarray/core/variable.py
Lines 183 to 189 in 0d6056e
Expected Output
I think I'd expect
cftime.datetime
in this case as well. Some coercion happens anyway as pandas timestamps are turned intonp.datetime64[ns]
.(But perhaps this was already on your radar, and am I just a little too eager!)
Output of
xr.show_versions()
The text was updated successfully, but these errors were encountered: