Skip to content

Unwritten Zarr v3 arrays values should default to NaN #10646

@shoyer

Description

@shoyer

What happened?

With Zarr v2, Xarray conflated _FillValue and fill_value (#5475), so unwritten data in a Zarr file is always decoded as NaN.

In Zarr v3, this changed. Now, it appears that unwritten data in a Zarr file uses the default Zarr fill_value=0.

In practice, this means that is Zarr metadata is written to disk (with compute=False) but no values are written, the data will be decoded by xarray as all zeros instead of all NaNs. This is perhaps unavoidable for integer data (there is no integer NaN), but for floats, we should default to a user controllable fill_value of NaN, which is clearly an invalid value.

To reproduce:

import xarray
import numpy as np

ds = xarray.Dataset({'foo': ('x', np.ones(3))}).chunk()

path = '/tmp/foo5.zarr'
ds.to_zarr(path, compute=False)

# all NaN with zarr v2, all zeros with zarr v3
print(xarray.open_zarr(path).compute())

Possibly related: #10633, #10269

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtopic-zarrRelated to zarr storage library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions