pydata / pydata/xarray

DataTree.to_zarr should be able to overwrite (and delete) zarr groups when `mode='w'`

Open
#10,433 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug io topic-DataTree topic-zarr
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

What is your issue?

In looking for a way to delete a single group from a zarr store, I found this somewhat counterintuitive behaviour:

# create a zarr store with two empty groups
store = zarr.storage.MemoryStore()
dt = xr.DataTree.from_dict(
    {'foo': xr.Dataset(), 'bar': xr.Dataset()}
)
dt.to_zarr(store, consolidated=False, zarr_format=3)

# prove that it has two groups
root = zarr.open_group(store, path='/', mode='r')
root.members()
# (('foo', <Group memory://139839489276800/foo>),
#  ('bar', <Group memory://139839489276800/bar>))

# overwrite with only one group
dt_without_group = xr.DataTree.from_dict(
    {'bar': xr.Dataset()}
)
dt_without_group.to_zarr(store2, consolidated=False, zarr_format=3, mode='w')

# but this has not changed anything
root.members()
# (('foo', <Group memory://139839489276800/foo>),
# ('bar', <Group memory://139839489276800/bar>))

I expected mode='w' to overwrite the whole store, which in this case would have effectively deleted the 'bar' group.

The behaviour actually seen is more like what I would have expected to occur with mode='a'. (mode='r+' should error.)

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 DataTree.to_zarr entry point and reproduce the provided MemoryStore example using zarr_format=3. Check the behavior of modes 'w', 'a', and 'r+'; done means mode='w' removes groups absent from the new tree, while the other modes retain or reject changes as described.

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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.