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
When saving a variable as a NetCDF coordinate variable (in the CF sense a variable with the same name as its dimension) you get a serialization warning:
SerializationWarning: saving variable x with floating point data as an integer dtype without any _FillValue to use for NaNs
CF coordinate variables are not supposed to have a _FillValue defined:
This stackoverflow answer says I can set fill value to None to not have a fill value for the variable, but it doesn't seem to change anything regarding the warning:
First, although I've committed the changes in #7719, this has merely been a refactor of already existing code. This behaviour has been around for almost 10 years now, dating back to @shoyer's PR #494.
I agree, that a warning in the case of CF coordinate variable is not needed (and is probably misleading in that sense). As a simple check for coordinate in NonStringCoder we could test if the variable name is the same as the variables only dimensions.
For the case of x.encoding["_FillValue"] = None this isn't as trivial as it might seem. In that case any nan would be converted to whatever astype returns in that case (which might different on different architectures). I'm not sure what's the best way forward here. We could catch any invalid cast RuntimeWarning and re-raise with added information. Thoughts?
Oh I see. Thanks. It is possible I updated my code to fix a warning from a CF checker (remove the fill value) and then ignored the warnings created by xarray for not having the fill value.
What happened?
When saving a variable as a NetCDF coordinate variable (in the CF sense a variable with the same name as its dimension) you get a serialization warning:
CF coordinate variables are not supposed to have a _FillValue defined:
https://cfconventions.org/Data/cf-conventions/cf-conventions-1.7/cf-conventions.html#missing-data
What did you expect to happen?
For variables that are CF coordinate variables I expect no warning. Or if I explicitly set the
_FillValue
toNone
then I would expect no warning.Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
Anything else we need to know?
@kmuehlbauer added this check in #7719
This stackoverflow answer says I can set fill value to None to not have a fill value for the variable, but it doesn't seem to change anything regarding the warning:
https://stackoverflow.com/a/45696423/433202
Environment
INSTALLED VERSIONS
commit: None
python: 3.12.8 | packaged by conda-forge | (main, Dec 5 2024, 14:24:40) [GCC 13.3.0]
python-bits: 64
OS: Linux
OS-release: 6.12.10-76061203-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.14.3
libnetcdf: 4.9.2
xarray: 2025.4.0
pandas: 2.2.3
numpy: 2.2.5
scipy: 1.15.2
netCDF4: 1.7.2
pydap: None
h5netcdf: 1.6.1
h5py: 3.13.0
zarr: 2.18.7
cftime: 1.6.4
nc_time_axis: None
iris: None
bottleneck: 1.4.2
dask: 2025.4.1
distributed: 2025.4.1
matplotlib: 3.10.1
cartopy: 0.24.0
seaborn: None
numbagg: None
fsspec: 2025.3.2
cupy: None
pint: 0.24.4
sparse: None
flox: None
numpy_groupies: None
setuptools: 80.1.0
pip: 25.1
conda: 25.3.1
pytest: 8.3.5
mypy: 1.15.0
IPython: 9.2.0
sphinx: 8.2.3
The text was updated successfully, but these errors were encountered: