-
-
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
solve a bug when the units attribute is not a string #7085
Conversation
Looks good to me. |
|
||
@requires_cftime | ||
def test_scalar_unit() -> None: | ||
# test that a scalar units (often NaN when using to_netcdf) does not raise an error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Xarray actually write a nan
for units? That seems problematic. Can you open a new issue witha reproducible example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened: #7093
Test failures seem unrelated (same failures with pyDAP occurred flakily in main) so I'm going to merge this shortly. Thanks @ghislainp ! |
whats-new.rst
api.rst
We faced a sort of bug with a colleague of mine. It seems to be legal to set a numeric value to the units attributes in an xarray or a netcdf file. xarray accepts to save such an array to netcdf: xr.DataArray([1, 2, 3], attrs={'units': 1}, name='x').to_csv('tmp.nc'). Reading this netcdf file with xarray.open_dataset raises an error.
It is unlikely to have a scalar for the units, but at least it happened to us (the value was NaN) and this raised an exception very difficult to understand.
This raises an exception because
"since" in attrs["units"]
was called twice in xarray codebase (in coding_times.py and in conventions.py) without checking for the type of the attribute.This PR solves this improbable bug