-
-
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
datetime handling seems broken #9387
Comments
Thanks for opening your first issue here at xarray! Be sure to follow the issue template! |
Thanks for the issue. Is it possible to reduce the size of the example further? Does it require |
Issue 1 above is probably minimally simple - I'll work on simplifying issue 2 . Issue 2 might require a ufunc - but I'm not exactly sure what's triggering it and I haven't been able to recreate it without one. |
Issue 1 gives the following warning:
So I think it's a matter of waiting until that's relaxed... |
For issue (1) I would recommend using floor division with a unit timedelta: >>> timedelta_days = (data_array - start_date) // np.timedelta64(1, "D") The following seems to be a simpler reproducer for (2) still involving da = xr.DataArray(range(5), dims=["x"])
xr.apply_ufunc(
lambda x: np.datetime64("2000-01-01", "ns"),
da.chunk(),
vectorize=True,
output_dtypes=[np.dtype("datetime64[ns]")],
dask="parallelized"
).compute() |
This is an xarray-free reproducer for issue (2): import dask.array
import numpy as np
dask.array.apply_gufunc(
lambda x: np.datetime64("2000-01-01", "ns"),
"()->()",
dask.array.arange(5),
vectorize=True,
output_dtypes=[np.dtype("datetime64[ns]")]
).compute() |
That MCVE works for me on dask 2024.8.1. @ThomWorm please update dask and see if the error persists |
What happened?
I've recently run into a few datetime issues with xarray. I've provided two separate reproducible examples below that seem to be connected to the same issue.
What did you expect to happen?
#issue 1 - I expect to get out an xarray containing the number of days between my input array (january 5th) and my target day (january first). Instead, I'm getting out 64-bit ints that represent the nanosecond equivalent of datetime values
######################################
#issue 2
I'm getting some unexpected behavior when working with numpy arrays that should return as datetime64 objects. In the above example, when I set output_dtypes to output_dtypes=[datetime64[ns] I'm getting a TypeError: Cannot cast NumPy timedelta64 scalar from metadata [ns] to according to the rule 'same_kind'.
I have tried many variations of explicitly setting input and output dtypes with no change in the error.
If I set output_dtypes=[ ] I am able to get a return of float64 values that I can convert after the fact to the expected datetime's. Although conversion after the fact isn't a huge problem, it seems to suggest to me that there is either an underlying issue or I have some misunderstanding.
If I remove dask I do get the same error when I replace degree_days with a NumPy backed xarray,
Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
No response
Environment
The text was updated successfully, but these errors were encountered: