Open
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.)