-
-
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
'numpy.datetime64' object has no attribute 'year' when writing to zarr or netcdf #6318
Comments
While I was typing this, @keewis provided a workaround here: fsspec/kerchunk#130 (comment) ! Leaving this open until I know whether this is something best left for users to implement or something to be handled in xarray. #6318 |
To be honest I didn't know it was possible to open a Dataset and maintain
I'll try and dig deeper into this in the next few days, but @keewis's workaround should be good in the meantime. |
I did a little more digging. I'm not a backend expert, but I think the issue can be distilled to the following. When passed an ordinary NumPy array as an input,
However, if passed a
This is based on this code within The casting does not occur in the Is this something that we maybe need to address within the xarray zarr backend? As I understand it, zarr is a bit unusual compared to other storage formats we deal with in that it can store and open |
Looks like this has been fixed by #9618. At least @spencerkclark's example works: arr = np.array([np.datetime64("2000-01-01", "us")])
print(xarray.Variable(["time"], arr))
lazily_indexed_arr = xarray.core.indexing.LazilyIndexedArray(arr)
print(xarray.Variable(["time"], lazily_indexed_arr)) Output: <xarray.Variable (time: 1)> Size: 8B
array(['2000-01-01T00:00:00.000000'], dtype='datetime64[us]')
<xarray.Variable (time: 1)> Size: 8B
array(['2000-01-01T00:00:00.000000'], dtype='datetime64[us]') Please reopen or open a new issue with updated examples. |
What happened?
I have a reproducible notebook where I've loaded a
referenceFileSystem
dataset into xarray and everything seems fine with time being understood correctly, but when I try to save a subset to zarr or netcdf, I get:I don't understand this since it seems time is always a
datetime64
object in xarray, and I've never had this problem before.What did you expect to happen?
Expected the file to be written as usual without error.
Minimal Complete Verifiable Example
Relevant log output
No response
Anything else we need to know?
I asked the question first over at fsspec/kerchunk#130 and @martindurant thought this looked like an xarray issue, not a kerchunk issue.
Environment
INSTALLED VERSIONS
commit: None
python: 3.9.10 | packaged by conda-forge | (main, Feb 1 2022, 21:24:11)
[GCC 9.4.0]
python-bits: 64
OS: Linux
OS-release: 4.12.14-150.17_5.0.85-cray_ari_c
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: None
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.12.1
libnetcdf: 4.8.1
xarray: 0.21.0
pandas: 1.4.0
numpy: 1.21.5
scipy: 1.7.3
netCDF4: 1.5.8
pydap: None
h5netcdf: 0.13.1
h5py: 3.6.0
Nio: None
zarr: 2.10.3
cftime: 1.5.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: 1.2.10
cfgrib: 0.9.10.0
iris: None
bottleneck: 1.3.2
dask: 2021.12.0
distributed: 2021.12.0
matplotlib: 3.5.1
cartopy: 0.20.2
seaborn: None
numbagg: None
fsspec: 2022.01.0
cupy: None
pint: 0.18
sparse: 0.13.0
setuptools: 59.8.0
pip: 22.0.2
conda: 4.11.0
pytest: None
IPython: 8.0.1
sphinx: 4.4.0
The text was updated successfully, but these errors were encountered: