You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
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 also tend to agree that this behavior is fine for the non-specific netcdf attributes.
For specific attributes as unit and _FillValue, is it also fine ? I would expect that Dataset.to_netcdf check the type (string for unit and the type of the variable for _FillValue and raise at least a warning. It is currently possible to save a number for the unit... Is the resulting netcdf CF-compliant ?
I believe NetCDF, CF-Conventions, and xarray should all be considered independently. It is not necessarily the responsibility of xarray serialization to ensure a CF-complaint file...
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: