pydata / pydata/xarray

Appending to a ZARR dataset removes dimension separator attribute

Open
#8,516 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-zarr
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
INSTALLED VERSIONS ------------------ commit: None python: 3.11.5 (main, Aug 24 2023, 15:18:16) [Clang 14.0.3 (clang-1403.0.22.14.1)] python-bits: 64 OS: Darwin OS-release: 22.5.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: None libnetcdf: None

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.