Skip to content

Commit 7bd3668

Browse files
committed
AsyncGroup.open with use_consolidated=None lets the Store select behavior
1 parent d5e4c54 commit 7bd3668

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/zarr/core/group.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,11 @@ async def open(
490490
491491
By default, consolidated metadata is used if it's present in the
492492
store (in the ``zarr.json`` for Zarr format 3 and in the ``.zmetadata`` file
493-
for Zarr format 2).
493+
for Zarr format 2) and the Store supports it.
494494
495495
To explicitly require consolidated metadata, set ``use_consolidated=True``.
496-
If the Store supports consolidated metadata, this will raise an
497-
exception if consolidated metadata is not found. If the Store doesn't want
498-
to use consolidated metadata, we assume it implements its own consolidation,
499-
so this is equivalent to use_consolidated=False.
496+
In this case, if the Store doesn't support consolidation or consolidated metadata is
497+
not found, a ``ValueError`` exception is raised.
500498
501499
To explicitly *not* use consolidated metadata, set ``use_consolidated=False``,
502500
which will fall back to using the regular, non consolidated metadata.
@@ -507,13 +505,14 @@ async def open(
507505
"""
508506
store_path = await make_store_path(store)
509507
if not store_path.store.supports_consolidated_metadata:
508+
# Fail if consolidated metadata was requseted but the Store doesn't support it
510509
if use_consolidated:
511510
store_name = type(store_path.store).__name__
512-
warnings.warn(
513-
f"The Zarr Store in use ({store_name}) doesn't support consolidated metadata "
514-
f"or has its own consolidation. Ignoring use_consolidated={use_consolidated}.",
515-
stacklevel=1,
511+
raise ValueError(
512+
f"The Zarr store in use ({store_name}) doesn't support consolidated metadata."
516513
)
514+
515+
# if use_consolidated was None (optional), the Store dictates it doesn't want consolidation
517516
use_consolidated = False
518517

519518
consolidated_key = ZMETADATA_V2_JSON

tests/test_metadata/test_consolidated.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,9 @@ async def test_open_group_in_non_consolidating_stores():
688688
# Opening a group without consolidatedion works as expected
689689
await AsyncGroup.open(memory_store, use_consolidated=False)
690690

691-
# Opening a group with use_consolidated=True should warn
692-
with pytest.warns(
693-
UserWarning, match="doesn't support consolidated metadata.*Ignoring use_consolidated=True"
694-
):
691+
# let the Store opt out of consolidation
692+
await AsyncGroup.open(memory_store, use_consolidated=None)
693+
694+
# Opening a group with use_consolidated=True should fail
695+
with pytest.raises(ValueError, match="doesn't support consolidated metadata"):
695696
await AsyncGroup.open(memory_store, use_consolidated=True)

0 commit comments

Comments
 (0)