Appending to a ZARR dataset removes dimension separator attribute
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
What happened?
When creating a ZARR store with dimension_separator="/", the to_zarr_store method removes dimension_separator attribute in the .zarray file.
What did you expect to happen?
It should retain the original storage attributes.
Minimal Complete Verifiable Example
import json
import xarray as xr
from zarr.storage import MemoryStore
store = MemoryStore(dimension_separator="/")
ds = xr.Dataset(
{"data": xr.DataArray([0.0], dims=("x",))},
coords={
"x": xr.DataArray([0.0], dims=("x",)),
},
)
ds.to_zarr(store, mode="w", consolidated=False)
assert json.loads(store["data/.zarray"].decode()).get("dimension_separator") == "/"
ds = xr.Dataset(
{"data": xr.DataArray([1.0], dims=("x",))},
coords={
"x": xr.DataArray([1.0], dims=("x",)),
},
)
ds.to_zarr(
store,
append_dim="x",
consolidated=False
)
assert json.loads(store["data/.zarray"].decode()).get("dimension_separator") == "/"
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
AssertionError Traceback (most recent call last)
File ~/xarray_repro/run.py:29
18 ds = xr.Dataset(
19 {"data": xr.DataArray([1.0], dims=("x",))},
20 coords={
21 "x": xr.DataArray([1.0], dims=("x",)),
22 },
23 )
24 ds.to_zarr(
25 store,
26 append_dim="x",
27 consolidated=False
28 )
---> 29 assert json.loads(store["data/.zarray"].decode()).get("dimension_separator") == "/"
AssertionError:
Anything else we need to know?
No response
Environment
xarray: 2023.11.0
pandas: 2.1.3
numpy: 1.26.2
scipy: None
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: 2.16.1
cftime: None
nc_time_axis: None
iris: None
bottleneck: None
dask: 2023.11.0
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: 2023.12.0
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 68.1.2
pip: 23.2.1
conda: None
pytest: None
mypy: None
IPython: 8.18.1
sphinx: None
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the to_zarr append path and reproduce the provided MemoryStore example using append_dim="x". Inspect how the data/.zarray metadata is updated during the append, then verify that the dimension_separator attribute remains "/" after the second write.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100