If xarray supports the numpy.datetime64 data format and so does zarr, why is xarray converting my numpy.datetime64 time array to a float array when I write it to zarr? #7776
Unanswered
christine-e-smit
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This all started because I'm trying to understand how xarray handles fill values and time arrays of type numpy.datetime64 (a.k.a. M8[ns]). My fill values disappeared for some reason in the conversion to zarr and I discovered that xarray was converting my time array to floating point for some reason.
Here is a simple example:
This block of code produces the following warning:
If I then try to read the dataset back out again, I get more errors and the time fill values are set to 2010-01-01:
Read warnings:
Print out of time array, which no longer has a fill value in the first position:
When I look in the actual files under
time_dataset.zarr
and look at thetime_dataset.zarr/.zmetadata
file created by xarray, the fill value has been changed toNaN
and the datatype is<f8
rather thanM8[ns]
. It looks as though xarray recognized that these are dates and decided to encode them as NetCDF/CF-1 style "seconds since ". Apparently the fill value did not survive this translation.I know xarray supports datetime64 values (https://docs.xarray.dev/en/stable/user-guide/time-series.html). I know zarr supports datetime64 values (https://zarr.readthedocs.io/en/stable/tutorial.html). So what is going on here?
Beta Was this translation helpful? Give feedback.
All reactions