Skip to content

Saving to zarr-store using shards changes underlying data #10831

@Holmgren825

Description

@Holmgren825

What happened?

Hey!
I tried saving a dataset (CMIP6 derived data) with very small chunks (dask array) to a zarr store using shards to limit the number of files used in the store. But, I noticed that computation based on the sharded store returned different results compared to the results from a store with the same data, but no shards.

What did you expect to happen?

I'm expecting the store using shards to represent the same data as the store not using shards, and any following computations would be identical.

Minimal Complete Verifiable Example

import xarray as xr
import dask.array as da
from dask.distributed import Client

client = Client()
rng = da.random.default_rng(seed=42)

# Generate some moderately size data to save to disk.
# Chunksize should be (255, 255, 255)
test_data = rng.integers(0, 2, size=(10000, 300, 300))

# Put in DataArray.
test_data = xr.DataArray(test_data)
test_data.name = "test_data"

#Setup encoding for shards.
encoding = {
    "test_data": {
        "shards": (255*2, 255, 255),
    }
}

# Save to disk.
test_data.to_zarr("test_random.zarr", zarr_format=3, mode="w")
test_data.to_zarr("test_random_shard.zarr", zarr_format=3, encoding=encoding, mode="w")

# Read from disk
test_data = xr.open_zarr("test_random.zarr").test_data
test_data_shard = xr.open_zarr("test_random_shard.zarr").test_data


#Expect this to return true, but it doesn't.
assert test_data.sum().compute().values == test_data_shard.sum().compute().values

Steps to reproduce

Note that setting shards to `(255*1, 255, 255) for the encoding above makes the assert return true.

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.

Relevant log output

Anything else we need to know?

Maybe this a zarr issue. Happy to raise there instead if that is the case.

Environment

Details INSTALLED VERSIONS ------------------ commit: None python: 3.12.11 | packaged by conda-forge | (main, Jun 4 2025, 14:45:31) [GCC 13.3.0] python-bits: 64 OS: Linux OS-release: 6.17.0-2-default machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.14.6 libnetcdf: 4.9.3

xarray: 2025.10.1
pandas: 2.3.2
numpy: 2.2.6
scipy: 1.16.1
netCDF4: 1.7.2
pydap: None
h5netcdf: None
h5py: None
zarr: 3.1.3
cftime: 1.6.4
nc_time_axis: 1.4.1
iris: None
bottleneck: 1.5.0
dask: 2025.9.1
distributed: 2025.9.1
matplotlib: 3.10.6
cartopy: 0.24.0
seaborn: None
numbagg: 0.9.2
fsspec: 2025.9.0
cupy: None
pint: None
sparse: 0.17.0
flox: 0.10.6
numpy_groupies: 0.11.3
setuptools: 80.9.0
pip: None
conda: None
pytest: None
mypy: None
IPython: 9.5.0
sphinx: None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions