Skip to content

Commit c04d7cf

Browse files
committed
add test for illegal shards kwarg for v2 arrays
1 parent 2182793 commit c04d7cf

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/zarr/core/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3615,7 +3615,7 @@ async def create_array(
36153615
if zarr_format == 2:
36163616
if shard_shape_parsed is not None:
36173617
msg = (
3618-
"Zarr v2 arrays can only be created with `shard_shape` set to `None`."
3618+
"Zarr v2 arrays can only be created with `shard_shape` set to `None`. "
36193619
f"Got `shard_shape={shards}` instead."
36203620
)
36213621

tests/test_array.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import math
44
import pickle
5+
import re
56
from itertools import accumulate
67
from typing import Any, Literal
78

@@ -1096,18 +1097,18 @@ async def test_create_array_v2_default_filters_compressors(store: MemoryStore, d
10961097

10971098

10981099
@pytest.mark.parametrize("store", ["memory"], indirect=True)
1099-
async def test_create_array_v2(store: MemoryStore) -> None:
1100-
from numcodecs import Delta, Zstd
1101-
1102-
# TODO: fill in
1103-
dtype = "uint8"
1104-
_ = zarr.create_array(
1105-
store=store,
1106-
dtype=dtype,
1107-
shape=(10,),
1108-
shards=None,
1109-
chunks=(4,),
1110-
zarr_format=2,
1111-
filters=(Delta(dtype=dtype),),
1112-
compressors=Zstd(level=3),
1100+
async def test_create_array_v2_no_shards(store: MemoryStore) -> None:
1101+
"""
1102+
Test that creating a Zarr v2 array with ``shard_shape`` set to a non-None value raises an error.
1103+
"""
1104+
msg = re.escape(
1105+
"Zarr v2 arrays can only be created with `shard_shape` set to `None`. Got `shard_shape=(5,)` instead."
11131106
)
1107+
with pytest.raises(ValueError, match=msg):
1108+
_ = await create_array(
1109+
store=store,
1110+
dtype="uint8",
1111+
shape=(10,),
1112+
shards=(5,),
1113+
zarr_format=2,
1114+
)

0 commit comments

Comments
 (0)