-
-
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
xarray allows several types for netcdf attributes. Is it expected ? #7093
Comments
What exactly do you mean by netcdf attributes? The special meaning ones like units, _FillValue or long_name? In general xarray is quite relaxed on what users put into the attrs, internally it is simply a dict of anything (see e.g. #7111 where people put in recursive DataArrays). As soon as you try to write it into a netCDF it has to be serializable, but that's why it raises an error. Personally I think the current behavior is fine (ofc, plotting etc should be able to deal with non-standard units etc.) |
|
I believe NetCDF, CF-Conventions, and |
In #9700 we added information to the docs that xarray relies on the capabilities of the backends what types of attributes can be written. This might help for non-CF attributes. We already check the CF attributes on read and preserve them in |
What is your issue?
Xarray is permissive regarding the type of the attributes. If using a wrong type, the error reveals the valid types: For serialization to netCDF files, its value must be of one of the following types: str, Number, ndarray, number, list, tuple
Using a non iterable type used to raise an Exception when reading the saved netcdf, but this is now solved with #7085
The pending question is whether it is valid to save netcdf attributes with type other than a string or not.
The following lines are working (in a notebook):
On the other hand, the following line raises an error:
The text was updated successfully, but these errors were encountered: