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
I'm attempting to set a nan fill value in the encoding of a zarr v3 format array created with xarray and seeing 0.0 in the fill value metadata instead. Not sure if this is user error or a bug.
What did you expect to happen?
see "fill_value": "NaN" in the variable's encoding in the array's zarr.json.
Minimal Complete Verifiable Example
importjsonimportnumpyasnpimportxarrayasxrvariable_data=np.full((4, 3), np.nan, dtype="float32")
ds=xr.Dataset({"example_var": (("x", "y"), variable_data)})
ds["example_var"].encoding["_FillValue"] ="NaN"ds["example_var"].encoding["fill_value"] ="NaN"# Also tried this but got the same 0.0 float value# xr_dataset["example_var"].encoding["_FillValue"] = np.nan# xr_dataset["example_var"].encoding["fill_value"] = np.nands.to_zarr("xarray_fill_value_test.zarr", mode="w", zarr_version=3)
withopen("xarray_fill_value_test.zarr/zarr.json") asf:
metadata=json.load(f)
# prints 0.0 instead of NaNprint(
f"{metadata['consolidated_metadata']['metadata']['example_var']['fill_value'] =}"
)
Note this doesn't appear to be a zarr-python issue, I'm seeing behavior I expect there:
importjsonimportnumpyasnpimportzarrdata=np.full((4, 3), np.nan, dtype="float32")
array=zarr.create_array("zarr_fill_value_test.zarr", data=data, fill_value=np.nan)
withopen("zarr_fill_value_test.zarr/zarr.json") asf:
metadata=json.load(f)
print(f"{metadata['fill_value']=}") # prints "NaN", good
MVCE confirmation
Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
Complete example — the example is self-contained, including all data and the text of any traceback.
Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
New issue — a search of GitHub Issues suggests this is not a duplicate.
Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Environment
xarray==2025.1.2
zarr==3.0.3
The text was updated successfully, but these errors were encountered:
Thanks for opening your first issue here at xarray! Be sure to follow the issue template!
If you have an idea for a solution, we would really welcome a Pull Request with proposed changes.
See the Contributing Guide for more.
It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better.
Thank you!
What happened?
I'm attempting to set a
nan
fill value in the encoding of a zarr v3 format array created with xarray and seeing0.0
in the fill value metadata instead. Not sure if this is user error or a bug.What did you expect to happen?
see
"fill_value": "NaN"
in the variable's encoding in the array's zarr.json.Minimal Complete Verifiable Example
Note this doesn't appear to be a zarr-python issue, I'm seeing behavior I expect there:
MVCE confirmation
Environment
The text was updated successfully, but these errors were encountered: