-
-
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
Cannot open dataset with empty list units #6781
Comments
@antscloud As a workaround you could use keyword argument |
Thank you, i'll do this. One could just loop over variables attributes and replace |
I guess we could take a PR to change if "units" in attrs and attrs["units"] in TIME_UNITS: to if "units" in attrs and isinstance(attrs["units"], str) and attrs["units"] in TIME_UNITS: |
I was wondering why the units attribute is parsed this way in the first place ? If it's xarray, wouldn't it be better to just not parse it ? |
It is checking to see if we can decode it as a time variable |
I think this is now fixed by #7085 (thanks @ghislainp ) |
What happened?
I found myself using a netcdf with empty units and by using xarray i was unable to use open_dataset due to the parsing of cf conventions.
I reproduce the bug, and it happens in a particular situation when the units is an empty list (See Minimal Complete Verifiable Example)
What did you expect to happen?
To parse the units attribute as an empty string ?
Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
Anything else we need to know?
The following assignation produces the bug :
But these ones does not produce the bug :
Also, i don't know how the units attributes get encoded for writing but i see no difference between
ds.temperature.attrs["units"] = ""
andds.temperature.attrs["units"] = []
when usingncdump
on the fileEnvironment
This bug was encountered with versions below this one.
INSTALLED VERSIONS
commit: None
python: 3.10.4 (main, Mar 31 2022, 08:41:55) [GCC 7.5.0]
python-bits: 64
OS: Linux
OS-release: 5.13.0-52-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: fr_FR.UTF-8
LOCALE: ('fr_FR', 'UTF-8')
libhdf5: 1.10.6
libnetcdf: 4.6.1
xarray: 0.20.1
pandas: 1.4.3
numpy: 1.22.3
scipy: None
netCDF4: 1.5.7
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.5.1.1
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.3.5
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
setuptools: 61.2.0
pip: 22.1.2
conda: None
pytest: None
IPython: 8.4.0
sphinx: None
The text was updated successfully, but these errors were encountered: