Skip to content

Commit 73610c3

Browse files
committed
Add warning when consolidation is used with Stores that don't support it
1 parent 7145260 commit 73610c3

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

src/zarr/api/asynchronous.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ async def consolidate_metadata(
203203

204204
group = await AsyncGroup.open(store_path, zarr_format=zarr_format, use_consolidated=False)
205205
if not store_path.store.supports_consolidated_metadata:
206+
store_name = type(store_path.store).__name__
207+
warnings.warn(
208+
f"The Zarr Store in use ({store_name}) doesn't support consolidated metadata. Ignoring.",
209+
stacklevel=1,
210+
)
206211
return group
207212

208213
group.store_path.store._check_writable()

src/zarr/core/group.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,13 @@ async def open(
507507
"""
508508
store_path = await make_store_path(store)
509509
if not store_path.store.supports_consolidated_metadata:
510+
if use_consolidated:
511+
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,
516+
)
510517
use_consolidated = False
511518

512519
consolidated_key = ZMETADATA_V2_JSON

tests/test_metadata/test_consolidated.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -653,16 +653,18 @@ async def test_consolidated_metadata_encodes_special_chars(
653653
assert root_metadata["time"]["fill_value"] == expected_fill_value
654654

655655

656+
class NonConsolidatedStore(zarr.storage.MemoryStore):
657+
"""A store that doesn't support consolidated metadata"""
658+
659+
@property
660+
def supports_consolidated_metadata(self) -> bool:
661+
return False
662+
663+
656664
async def test_consolidate_metadata_is_noop_for_self_consolidating_stores():
657665
"""Verify calling consolidate_metadata on a non supporting stores does nothing"""
658666

659-
# We create a store that doesn't support consolidated metadata
660-
class Store(zarr.storage.MemoryStore):
661-
@property
662-
def supports_consolidated_metadata(self) -> bool:
663-
return False
664-
665-
memory_store = Store()
667+
memory_store = NonConsolidatedStore()
666668
root = await zarr.api.asynchronous.create_group(store=memory_store)
667669
await root.create_group("a/b")
668670

@@ -672,6 +674,22 @@ async def set_raises(self, value: Buffer, byte_range: ByteRequest | None = None)
672674

673675
memory_store.set = set_raises
674676

675-
# consolidate_metadata would call `set` if the store supported consolidated metadata
676-
# if this doesn't raise, it means consolidate_metadata is NOOP
677-
await zarr.api.asynchronous.consolidate_metadata(memory_store)
677+
with pytest.warns(UserWarning, match="doesn't support consolidated metadata"):
678+
# consolidate_metadata would call `set` if the store supported consolidated metadata
679+
# if this doesn't raise, it means consolidate_metadata is NOOP
680+
await zarr.api.asynchronous.consolidate_metadata(memory_store)
681+
682+
683+
async def test_open_group_in_non_consolidating_stores():
684+
memory_store = NonConsolidatedStore()
685+
root = await zarr.api.asynchronous.create_group(store=memory_store)
686+
await root.create_group("a/b")
687+
688+
# Opening a group without consolidatedion works as expected
689+
await AsyncGroup.open(memory_store, use_consolidated=False)
690+
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+
):
695+
await AsyncGroup.open(memory_store, use_consolidated=True)

0 commit comments

Comments
 (0)