Description
What happened?
When appending a coordinate to an existing store, to_zarr
will save the coordinate as a data variable.
What did you expect to happen?
to_zarr
should record the appended item as a coordinate
Minimal Complete Verifiable Example
import numpy as np
import xarray as xr
da = xr.DataArray(np.ones(3), dims="x", name="a")
da.to_zarr("test")
da.coords["c"] = ("x", np.ones(3))
da.to_zarr("test", mode="a")
xr.open_zarr("test")
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
<xarray.Dataset> Size: 48B
Dimensions: (x: 3)
Dimensions without coordinates: x
Data variables:
a (x) float64 24B dask.array<chunksize=(3,), meta=np.ndarray>
c (x) float64 24B dask.array<chunksize=(3,), meta=np.ndarray>
Anything else we need to know?
In the example I gave above this is happening because open_zarr
expects the a
zarr array to have an attribute called "coordinates"
that is set to "c"
but ZarrStore.set_variables
doesn't save attributes for existing variables unless mode is set to "w"
.
Environment
INSTALLED VERSIONS
commit: None
python: 3.12.9 | packaged by conda-forge | (main, Mar 4 2025, 22:44:42) [Clang 18.1.8 ]
python-bits: 64
OS: Darwin
OS-release: 24.3.0
machine: arm64
processor: arm
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: None
libnetcdf: None
xarray: 0.1.dev5886+gcdebbf5
pandas: 2.2.3
numpy: 2.1.3
scipy: 1.15.2
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
zarr: 3.0.5
cftime: None
nc_time_axis: None
iris: None
bottleneck: None
dask: 2025.2.0
distributed: 2025.2.0
matplotlib: 3.10.1
cartopy: None
seaborn: 0.13.2
numbagg: None
fsspec: 2025.3.0
cupy: None
pint: 0.24.4
sparse: None
flox: None
numpy_groupies: None
setuptools: 75.8.2
pip: 25.0.1
conda: 24.11.3
pytest: None
mypy: None
IPython: 9.0.2
sphinx: 8.2.3