Skip to content

Commit

Permalink
test + userwarning
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamman committed Oct 13, 2024
1 parent d78d177 commit b6e8935
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/zarr/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import itertools
import json
import logging
import warnings
from collections import defaultdict
from dataclasses import asdict, dataclass, field, fields, replace
from typing import TYPE_CHECKING, Literal, TypeVar, assert_never, cast, overload
Expand Down Expand Up @@ -1170,9 +1171,10 @@ async def _members(
# keyerror is raised when `key` names an object (in the object storage sense),
# as opposed to a prefix, in the store under the prefix associated with this group
# in which case `key` cannot be the name of a sub-array or sub-group.
logger.warning(
"Object at %s is not recognized as a component of a Zarr hierarchy.",
key,
warnings.warn(
f"Object at {key} is not recognized as a component of a Zarr hierarchy.",
UserWarning,
stacklevel=1,
)

def _members_consolidated(
Expand Down
11 changes: 9 additions & 2 deletions tests/v3/test_group.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import pickle
import warnings
from typing import TYPE_CHECKING, Any, Literal, cast

import numpy as np
Expand Down Expand Up @@ -1091,8 +1092,8 @@ async def test_require_array(store: Store, zarr_format: ZarrFormat) -> None:


@pytest.mark.parametrize("consolidate", [True, False])
def test_members_name(store: Store, consolidate: bool):
group = Group.from_store(store=store)
async def test_members_name(store: Store, consolidate: bool, zarr_format: ZarrFormat):
group = Group.from_store(store=store, zarr_format=zarr_format)
a = group.create_group(name="a")
a.create_array("array", shape=(1,))
b = a.create_group(name="b")
Expand All @@ -1108,6 +1109,12 @@ def test_members_name(store: Store, consolidate: bool):
expected = ["/a", "/a/array", "/a/b", "/a/b/array"]
assert paths == expected

# regression test for https://github.com/zarr-developers/zarr-python/pull/2356
g = zarr.open_group(store, use_consolidated=False)
with warnings.catch_warnings():
warnings.simplefilter("error")
assert list(g)


async def test_open_mutable_mapping():
group = await zarr.api.asynchronous.open_group(store={}, mode="w")
Expand Down

0 comments on commit b6e8935

Please sign in to comment.