Skip to content

Zarr loading from ZipStore gives error on default arguments #2586

Closed
@eeopd

Description

@eeopd

(This is not too much of a problem, but it would probably be a reasonably easy fix)

import xarray as xr
import zarr

ds = xr.Dataset({'foo': [2,3,4], 'bar': ('x', [1, 2]), 'baz': 3.14})

ds.to_zarr(zarr.ZipStore("test.zarr"))
print(xr.open_zarr(zarr.ZipStore("test.zarr")))

This gives the following error:

ValueError                                Traceback (most recent call last)
<ipython-input-1-c68e53adfa79> in <module>
      5 
      6 ds.to_zarr(zarr.ZipStore("test.zarr"))
----> 7 print(xr.open_zarr(zarr.ZipStore("test.zarr")))

~/.local/lib/python3.7/site-packages/xarray/backends/zarr.py in open_zarr(store, group, synchronizer, auto_chunk, decode_cf, mask_and_scale, decode_times, concat_characters, decode_coords, drop_variables)
    424     zarr_store = ZarrStore.open_group(store, mode=mode,
    425                                       synchronizer=synchronizer,
--> 426                                       group=group)
    427     ds = maybe_decode_store(zarr_store)
    428 

~/.local/lib/python3.7/site-packages/xarray/backends/zarr.py in open_group(cls, store, mode, synchronizer, group)
    236                                       "#installation" % min_zarr)
    237         zarr_group = zarr.open_group(store=store, mode=mode,
--> 238                                      synchronizer=synchronizer, path=group)
    239         return cls(zarr_group)
    240 

~/.local/lib/python3.7/site-packages/zarr/hierarchy.py in open_group(store, mode, cache_attrs, synchronizer, path)
   1111             err_contains_array(path)
   1112         elif not contains_group(store, path=path):
-> 1113             err_group_not_found(path)
   1114 
   1115     elif mode == 'w':

~/.local/lib/python3.7/site-packages/zarr/errors.py in err_group_not_found(path)
     27 
     28 def err_group_not_found(path):
---> 29     raise ValueError('group not found at path %r' % path)
     30 
     31 

ValueError: group not found at path ''

Instead, one has to use

xr.open_zarr(zarr.ZipStore("test.zarr"), group='/')

When using a dictionary as store (e.g. when using ds.to_zarr('test_zarr')), this group='/' is unnecessary when loading it again, but everything still works when using it anyway. So I'd propose changing the default value of the group argument to '/', so the ZipStore (and probably also the other stores) will work by default as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic-zarrRelated to zarr storage library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions