diff --git a/zarr/_storage/store.py b/zarr/_storage/store.py index 6faf4a1250..9e265cf383 100644 --- a/zarr/_storage/store.py +++ b/zarr/_storage/store.py @@ -420,11 +420,11 @@ def _listdir_from_keys(store: BaseStore, path: Optional[str] = None) -> List[str def _prefix_to_array_key(store: StoreLike, prefix: str) -> str: if getattr(store, "_store_version", 2) == 3: + sfx = _get_metadata_suffix(store) # type: ignore if prefix: - sfx = _get_metadata_suffix(store) # type: ignore key = meta_root + prefix.rstrip("/") + ".array" + sfx else: - raise ValueError("prefix must be supplied to get a v3 array key") + key = meta_root[:-1] + '.array' + sfx else: key = prefix + array_meta_key return key @@ -432,11 +432,11 @@ def _prefix_to_array_key(store: StoreLike, prefix: str) -> str: def _prefix_to_group_key(store: StoreLike, prefix: str) -> str: if getattr(store, "_store_version", 2) == 3: + sfx = _get_metadata_suffix(store) # type: ignore if prefix: - sfx = _get_metadata_suffix(store) # type: ignore key = meta_root + prefix.rstrip('/') + ".group" + sfx else: - raise ValueError("prefix must be supplied to get a v3 group key") + key = meta_root[:-1] + '.group' + sfx else: key = prefix + group_meta_key return key @@ -449,7 +449,7 @@ def _prefix_to_attrs_key(store: StoreLike, prefix: str) -> str: if prefix: key = meta_root + prefix.rstrip('/') + ".array" + sfx else: - raise ValueError("prefix must be supplied to get a v3 array key") + key = meta_root[:-1] + '.array' + sfx else: key = prefix + attrs_key return key diff --git a/zarr/creation.py b/zarr/creation.py index e1c815ed21..3414a0158a 100644 --- a/zarr/creation.py +++ b/zarr/creation.py @@ -163,7 +163,7 @@ def create(shape, chunks=True, dtype=None, compressor='default', dimension_separator = normalize_dimension_separator(dimension_separator) if zarr_version > 2 and path is None: - raise ValueError("path must be supplied to initialize a zarr v3 array") + path = '/' # initialize array metadata init_array(store, shape=shape, chunks=chunks, dtype=dtype, compressor=compressor, diff --git a/zarr/hierarchy.py b/zarr/hierarchy.py index 177d1eec71..e1d390f497 100644 --- a/zarr/hierarchy.py +++ b/zarr/hierarchy.py @@ -1276,8 +1276,6 @@ def group(store=None, overwrite=False, chunk_store=None, if zarr_version != 2: assert_zarr_v3_api_available() - if zarr_version == 3 and path is None: - raise ValueError(f"path must be provided for a v{zarr_version} group") path = normalize_storage_path(path) if zarr_version == 2: @@ -1366,10 +1364,6 @@ def open_group(store=None, mode='a', cache_attrs=True, synchronizer=None, path=N "zarr_version of store and chunk_store must match" ) - store_version = getattr(store, '_store_version', 2) - if store_version == 3 and path is None: - raise ValueError("path must be supplied to initialize a zarr v3 group") - path = normalize_storage_path(path) # ensure store is initialized diff --git a/zarr/storage.py b/zarr/storage.py index 4a1408ec01..f5459990ba 100644 --- a/zarr/storage.py +++ b/zarr/storage.py @@ -230,8 +230,14 @@ def _getsize(store: BaseStore, path: Path = None) -> int: size = 0 store_version = getattr(store, '_store_version', 2) if store_version == 3: - members = store.list_prefix(data_root + path) # type: ignore - members += store.list_prefix(meta_root + path) # type: ignore + if path == '': + # have to list the root folders without trailing / in this case + members = store.list_prefix(data_root.rstrip('/')) # type: ignore + members += store.list_prefix(meta_root.rstrip('/')) # type: ignore + else: + members = store.list_prefix(data_root + path) # type: ignore + members += store.list_prefix(meta_root + path) # type: ignore + # also include zarr.json? # members += ['zarr.json'] else: members = listdir(store, path) diff --git a/zarr/tests/test_convenience.py b/zarr/tests/test_convenience.py index 59bb3aa7da..45ed9c3e11 100644 --- a/zarr/tests/test_convenience.py +++ b/zarr/tests/test_convenience.py @@ -73,11 +73,6 @@ def test_open_array(path_type, zarr_version): assert isinstance(z, Array) assert z.shape == (200,) - if zarr_version == 3: - # cannot open a v3 array without path - with pytest.raises(ValueError): - open(store, mode='w', shape=200, zarr_version=3) - # open array, read-only z = open(store, mode='r', **kwargs) assert isinstance(z, Array) @@ -108,11 +103,6 @@ def test_open_group(path_type, zarr_version): assert isinstance(g, Group) assert 'foo' not in g - if zarr_version == 3: - # cannot open a v3 group without path - with pytest.raises(ValueError): - open(store, mode='w', zarr_version=3) - # open group, read-only g = open(store, mode='r', **kwargs) assert isinstance(g, Group) diff --git a/zarr/tests/test_core.py b/zarr/tests/test_core.py index 7429cba8c7..ecfeb7a817 100644 --- a/zarr/tests/test_core.py +++ b/zarr/tests/test_core.py @@ -19,9 +19,6 @@ from zarr._storage.store import ( v3_api_available, - _prefix_to_array_key, - _prefix_to_attrs_key, - _prefix_to_group_key ) from zarr.core import Array from zarr.errors import ArrayNotFoundError, ContainsGroupError @@ -64,13 +61,15 @@ class TestArray(unittest.TestCase): version = 2 + root = '' + KVStoreClass = KVStore def test_array_init(self): # normal initialization - store = KVStore(dict()) + store = self.KVStoreClass(dict()) init_array(store, shape=100, chunks=10, dtype="