document limitations of cftime arithmetics#10653
Conversation
for more information, see https://pre-commit.ci
|
I have a code example that inentionally should fail, i used the notation for that part. |
|
I'm not sure why the readthedocs fails, my local build seems to work. |
spencerkclark
left a comment
There was a problem hiding this comment.
Thanks @larsbuntemeyer! It would be nice to get this working cleanly someday, especially now that xarray supports coarser resolution np.timedelta64 values.
You could also consider including a more verbose, but also more robust, workaround that adds the two DataArrays via apply_ufunc:
def add_cftime_and_timedelta64(cftime_da, timedelta64_da, join="inner"):
def func(cftime_array, timedelta64_array):
shape = cftime_array.shape
cftime_array = cftime_array.ravel()
timedelta64_array = timedelta64_array.ravel()
timedelta_array = pd.to_timedelta(timedelta64_array).to_pytimedelta()
return (cftime_array + timedelta_array).reshape(shape)
return xr.apply_ufunc(
func,
cftime_da,
timedelta64_da,
dask="parallelized",
output_dtypes=[cftime_da.dtype],
join=join
)This function has the advantage that it preserves the coordinate alignment, as well as multi-dimensional and dask compatibility features of xarray.
Co-authored-by: Spencer Clark <spencerkclark@gmail.com>
I agree! That would be really helpful!
Thanks for this solution! I'll add this to the docs. |
|
@spencerkclark I added your workaround to the docs. Thanks a lot for that! |
spencerkclark
left a comment
There was a problem hiding this comment.
Thanks @larsbuntemeyer!
* main: Document limitations of cftime arithmetic (pydata#10653) Remove RTD htmlzip output format (pydata#10977) Support decoding unsigned integers to timedelta (pydata#10972) Use `._data` in `Variable._replace` (pydata#10969) small changes to the pixi env definitions (pydata#10976) Add GitHub Codespaces config for Pixi (pydata#10929) Fix workflow name to embed `matrix.pytest-addopts` (pydata#10970)

whats-new.rst