Skip to content

Commit ba4fb47

Browse files
committed
fixup
1 parent b8b5f51 commit ba4fb47

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/zarr/api/asynchronous.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ async def open(
299299

300300
async def open_consolidated(*args: Any, use_consolidated: bool = True, **kwargs: Any) -> AsyncGroup:
301301
"""
302-
Alias for :func:`open_group`.
302+
Alias for :func:`open_group` with ``use_consolidated=True``.
303303
"""
304-
return await open_group(*args, **kwargs)
304+
return await open_group(*args, use_consolidated=use_consolidated, **kwargs)
305305

306306

307307
async def save(

src/zarr/core/group.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ async def open(
397397
store_path = await make_store_path(store)
398398

399399
consolidated_key = ZMETADATA_V2_JSON
400+
400401
if (zarr_format == 2 or zarr_format is None) and isinstance(use_consolidated, str):
401402
consolidated_key = use_consolidated
402403

@@ -414,9 +415,6 @@ async def open(
414415
if use_consolidated or use_consolidated is None:
415416
maybe_consolidated_metadata_bytes = rest[0]
416417

417-
if use_consolidated and maybe_consolidated_metadata_bytes is None:
418-
# the user requested consolidated metadata, but it was missing
419-
raise FileNotFoundError(paths[-1])
420418
else:
421419
maybe_consolidated_metadata_bytes = None
422420

@@ -453,6 +451,11 @@ async def open(
453451
if zarr_format == 2:
454452
# this is checked above, asserting here for mypy
455453
assert zgroup_bytes is not None
454+
455+
if use_consolidated and maybe_consolidated_metadata_bytes is None:
456+
# the user requested consolidated metadata, but it was missing
457+
raise ValueError(consolidated_key)
458+
456459
return cls._from_bytes_v2(
457460
store_path, zgroup_bytes, zattrs_bytes, maybe_consolidated_metadata_bytes
458461
)
@@ -517,7 +520,6 @@ def _from_bytes_v3(
517520
group_metadata = json.loads(zarr_json_bytes.to_bytes())
518521
if use_consolidated and group_metadata.get("consolidated_metadata") is None:
519522
msg = f"Consolidated metadata requested with 'use_consolidated=True' but not found in '{store_path.path}'."
520-
# Use `FileNotFoundError` here to match the error from v2?
521523
raise ValueError(msg)
522524

523525
elif use_consolidated is False:
@@ -1086,7 +1088,6 @@ def _members_consolidated(
10861088
self.store_path, key, prefix=self.name
10871089
) # Metadata -> Group/Array
10881090
key = "/".join([prefix, key]).lstrip("/")
1089-
# breakpoint()
10901091
yield key, obj
10911092

10921093
if ((max_depth is None) or (current_depth < max_depth)) and isinstance(

tests/v3/test_metadata/test_consolidated.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import numpy as np
77
import pytest
88

9+
import zarr.api.asynchronous
910
import zarr.api.synchronous
11+
import zarr.store
1012
from zarr.api.asynchronous import (
1113
AsyncGroup,
1214
consolidate_metadata,
@@ -21,6 +23,7 @@
2123

2224
if TYPE_CHECKING:
2325
from zarr.abc.store import Store
26+
from zarr.core.common import ZarrFormat
2427

2528

2629
@pytest.fixture
@@ -472,3 +475,13 @@ def test_to_dict_empty(self):
472475
},
473476
}
474477
assert result == expected
478+
479+
@pytest.mark.parametrize("zarr_format", [2, 3])
480+
async def test_open_consolidated_raises_async(self, zarr_format: ZarrFormat):
481+
store = zarr.store.MemoryStore(mode="w")
482+
await AsyncGroup.from_store(store, zarr_format=zarr_format)
483+
with pytest.raises(ValueError):
484+
await zarr.api.asynchronous.open_consolidated(store, zarr_format=zarr_format)
485+
486+
with pytest.raises(ValueError):
487+
await zarr.api.asynchronous.open_consolidated(store, zarr_format=None)

0 commit comments

Comments
 (0)