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
If there is a time variable that can be encoded using integers only, but that has a _FillValue set to NaN, saving to_netcdf(name, format="NETCDF4_CLASSIC") fails. The problem is that xarray adds a (unnecessary) _FillValue when saving a file.
Note: if the time cannot be encoded using integers only, it works:
da=xr.DataArray(time, dims=["time"])
da.encoding["_FillValue"] =np.array([np.nan])
da.encoding["units"] ="days since 2006-01-01T12:00:00"xr.backends.netcdf3.encode_nc3_variable(xr.conventions.encode_cf_variable(da))
#3652 helps indeed. Example 1 from above now works without error. Example 2 still throws an error. However, I think this is fine, because you are unlikely to end up with an encoding that defines only a _FillValue and not a dtype.
MCVE Code Sample
yields:
Or an example without
to_netcdf
:Expected Output
Xarray can save the dataset/ an
xr.Variable
.Problem Description
If there is a time variable that can be encoded using integers only, but that has a
_FillValue
set toNaN
, savingto_netcdf(name, format="NETCDF4_CLASSIC")
fails. The problem is that xarray adds a (unnecessary)_FillValue
when saving a file.Note: if the time cannot be encoded using integers only, it works:
Another note: when saving with NETCDF4
The following is returned:
Output of
xr.show_versions()
xarray: 0.14.1
pandas: 0.25.2
numpy: 1.17.3
scipy: 1.3.1
netCDF4: 1.5.3
pydap: None
h5netcdf: 0.7.4
h5py: 2.10.0
Nio: None
zarr: None
cftime: 1.0.4.2
nc_time_axis: 1.2.0
PseudoNetCDF: None
rasterio: 1.1.1
cfgrib: None
iris: None
bottleneck: 1.3.1
dask: 2.6.0
distributed: 2.6.0
matplotlib: 3.1.2
cartopy: 0.17.0
seaborn: 0.9.0
numbagg: None
setuptools: 41.4.0
pip: 19.3.1
conda: None
pytest: 5.2.2
IPython: 7.9.0
sphinx: 2.2.1
The text was updated successfully, but these errors were encountered: