Skip to content

Commit 956159e

Browse files
committed
test_v2_and_v3_exist_at_same_path
1 parent fc64cbf commit 956159e

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/zarr/core/array.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
logger = getLogger(__name__)
135135

136136

137-
def parse_array_metadata(data: ArrayMetadata | ArrayMetadataDict) -> ArrayMetadata:
137+
def parse_array_metadata(data: ArrayMetadata | dict[str, JSON]) -> ArrayMetadata:
138138
if isinstance(data, ArrayMetadata):
139139
return data
140140
elif isinstance(data, dict):
@@ -152,7 +152,7 @@ def parse_array_metadata(data: ArrayMetadata | ArrayMetadataDict) -> ArrayMetada
152152
return ArrayV2Metadata.from_dict(data)
153153
else:
154154
raise ValueError(f"Invalid zarr_format: {zarr_format}. Expected 2 or 3")
155-
raise TypeError
155+
raise TypeError # pragma: no cover
156156

157157

158158
def create_codec_pipeline(metadata: ArrayMetadata) -> CodecPipeline:
@@ -161,8 +161,7 @@ def create_codec_pipeline(metadata: ArrayMetadata) -> CodecPipeline:
161161
elif isinstance(metadata, ArrayV2Metadata):
162162
v2_codec = V2Codec(filters=metadata.filters, compressor=metadata.compressor)
163163
return get_pipeline_class().from_codecs([v2_codec])
164-
else:
165-
raise TypeError
164+
raise TypeError # pragma: no cover
166165

167166

168167
async def get_array_metadata(

tests/test_api.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import re
34
from typing import TYPE_CHECKING
45

56
if TYPE_CHECKING:
@@ -156,6 +157,15 @@ async def test_open_array(memory_store: MemoryStore, zarr_format: ZarrFormat) ->
156157
open(store="doesnotexist", mode="r", zarr_format=zarr_format)
157158

158159

160+
@pytest.mark.parametrize("store", ["memory", "local", "zip"], indirect=True)
161+
def test_v2_and_v3_exist_at_same_path(store: Store) -> None:
162+
zarr.create_array(store, shape=(10,), dtype="uint8", zarr_format=3)
163+
zarr.create_array(store, shape=(10,), dtype="uint8", zarr_format=2)
164+
msg = f"Both zarr.json (Zarr format 3) and .zarray (Zarr format 2) metadata objects exist at {store}. Zarr v3 will be used."
165+
with pytest.warns(UserWarning, match=re.escape(msg)):
166+
zarr.open(store=store, mode="r")
167+
168+
159169
@pytest.mark.parametrize("store", ["memory"], indirect=True)
160170
async def test_create_group(store: Store, zarr_format: ZarrFormat) -> None:
161171
attrs = {"foo": 100}

tests/test_array.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,13 +1662,10 @@ async def test_sharding_coordinate_selection() -> None:
16621662
assert isinstance(result, NDArrayLike)
16631663
assert (result == np.array([[12, 13, 14, 15], [16, 17, 18, 19]])).all()
16641664

1665+
16651666
@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"])
16661667
def test_array_repr(store: Store) -> None:
16671668
shape = (2, 3, 4)
16681669
dtype = "uint8"
1669-
arr = zarr.create_array(
1670-
store,
1671-
shape=shape,
1672-
dtype=dtype
1673-
)
1670+
arr = zarr.create_array(store, shape=shape, dtype=dtype)
16741671
assert str(arr) == f"<Array {store} shape={shape} dtype={dtype}>"

0 commit comments

Comments
 (0)