Skip to content

Commit 2f6f8a0

Browse files
committed
tests
1 parent 75b2197 commit 2f6f8a0

File tree

6 files changed

+31
-25
lines changed

6 files changed

+31
-25
lines changed

src/zarr/core/array.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -680,10 +680,10 @@ async def _create_v2(
680680
dimension_separator = "."
681681

682682
dtype = parse_dtype(dtype, zarr_format=2)
683-
# if not filters:
684-
# filters = _default_filters(dtype)
685-
# if not compressor:
686-
# compressor = _default_compressor(dtype)
683+
if not filters:
684+
filters = _default_filters(dtype)
685+
if not compressor:
686+
compressor = _default_compressor(dtype)
687687

688688
# inject VLenUTF8 for str dtype if not already present
689689
if np.issubdtype(dtype, np.str_):
@@ -3528,10 +3528,10 @@ async def create_array(
35283528
dtype: npt.DTypeLike,
35293529
chunks: ChunkCoords | Literal["auto"] = "auto",
35303530
shards: ShardsParam | None = None,
3531-
filters: FiltersParam = "auto",
3531+
filters: FiltersParam | None = "auto",
35323532
compressors: CompressorsParam = "auto",
3533-
array_bytes_codec: ArrayBytesCodecParam | None = "auto",
3534-
fill_value: Any | None = 0,
3533+
array_bytes_codec: ArrayBytesCodecParam = "auto",
3534+
fill_value: Any | None = None,
35353535
order: MemoryOrder | None = None,
35363536
zarr_format: ZarrFormat | None = 3,
35373537
attributes: dict[str, JSON] | None = None,
@@ -3665,6 +3665,9 @@ async def create_array(
36653665
)
36663666

36673667
raise ValueError(msg)
3668+
if array_bytes_codec != "auto":
3669+
raise ValueError("Zarr v2 arrays do not support `array_bytes_codec`.")
3670+
36683671
filters_parsed, compressor_parsed = _parse_chunk_encoding_v2(
36693672
compressor=compressors, filters=filters, dtype=np.dtype(dtype)
36703673
)
@@ -3825,7 +3828,7 @@ def _get_default_chunk_encoding_v2(
38253828
def _parse_chunk_encoding_v2(
38263829
*,
38273830
compressor: CompressorsParam,
3828-
filters: FiltersParam,
3831+
filters: FiltersParam | None,
38293832
dtype: np.dtype[Any],
38303833
) -> tuple[tuple[numcodecs.abc.Codec, ...] | None, numcodecs.abc.Codec | None]:
38313834
"""
@@ -3839,11 +3842,7 @@ def _parse_chunk_encoding_v2(
38393842
if compressor == "auto":
38403843
_compressor = default_compressor
38413844
else:
3842-
if (
3843-
isinstance(compressor, Iterable)
3844-
and not isinstance(compressor, dict)
3845-
and len(compressor) > 1
3846-
):
3845+
if isinstance(compressor, Iterable) and not isinstance(compressor, dict):
38473846
msg = f"For Zarr v2 arrays, the `compressor` must be a single codec. Got an iterable with type {type(compressor)} instead."
38483847
raise TypeError(msg)
38493848
_compressor = parse_compressor(compressor)
@@ -3866,7 +3865,7 @@ def _parse_chunk_encoding_v3(
38663865
*,
38673866
compressors: CompressorsParam | None,
38683867
filters: FiltersParam | None,
3869-
array_bytes_codec: ArrayBytesCodecParam | None,
3868+
array_bytes_codec: ArrayBytesCodecParam,
38703869
dtype: np.dtype[Any],
38713870
) -> tuple[tuple[ArrayArrayCodec, ...], ArrayBytesCodec, tuple[BytesBytesCodec, ...]]:
38723871
"""

src/zarr/core/metadata/v2.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,6 @@ def parse_filters(data: object) -> tuple[numcodecs.abc.Codec, ...] | None:
232232
if data is None:
233233
return data
234234
if isinstance(data, Iterable):
235-
if len(data) == 0:
236-
return None
237235
for idx, val in enumerate(data):
238236
if isinstance(val, numcodecs.abc.Codec):
239237
out.append(val)
@@ -251,11 +249,6 @@ def parse_compressor(data: object) -> numcodecs.abc.Codec | None:
251249
"""
252250
Parse a potential compressor.
253251
"""
254-
if isinstance(data, Iterable) and not isinstance(data, dict):
255-
if len(data) == 0:
256-
data = None
257-
else:
258-
data = data[0]
259252
if data is None or isinstance(data, numcodecs.abc.Codec):
260253
return data
261254
if isinstance(data, dict):

src/zarr/registry.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ def _parse_array_bytes_codec(data: dict[str, JSON] | Codec) -> ArrayBytesCodec:
200200
msg = f"Expected a dict representation of a ArrayBytesCodec; got a dict representation of a {type(result)} instead."
201201
raise TypeError(msg)
202202
else:
203+
if not isinstance(data, ArrayBytesCodec):
204+
raise TypeError(f"Expected a ArrayBytesCodec. Got {type(data)} instead.")
203205
result = data
204206
return result
205207

tests/test_array.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def test_array_v3_fill_value(store: MemoryStore, fill_value: int, dtype_str: str
219219
def test_create_positional_args_deprecated() -> None:
220220
store = MemoryStore()
221221
with pytest.warns(FutureWarning, match="Pass"):
222-
zarr.create_array(store, (2, 2), dtype="f8")
222+
zarr.Array._create(store, (2, 2), dtype="f8")
223223

224224

225225
def test_selection_positional_args_deprecated() -> None:
@@ -994,6 +994,17 @@ async def test_create_array_no_filters_compressors(store: MemoryStore, dtype: st
994994
"""
995995

996996
# v2
997+
arr = await create_array(
998+
store=store,
999+
dtype=dtype,
1000+
shape=(10,),
1001+
zarr_format=2,
1002+
compressors=None,
1003+
filters=None,
1004+
)
1005+
assert arr.metadata.filters is None # type: ignore[union-attr]
1006+
assert arr.metadata.compressor is None # type: ignore[union-attr]
1007+
9971008
arr = await create_array(
9981009
store=store,
9991010
dtype=dtype,
@@ -1002,8 +1013,8 @@ async def test_create_array_no_filters_compressors(store: MemoryStore, dtype: st
10021013
compressors=(),
10031014
filters=(),
10041015
)
1005-
assert arr.metadata.filters == None # type: ignore[union-attr]
1006-
assert arr.metadata.compressor == None # type: ignore[union-attr]
1016+
assert arr.metadata.filters == () # type: ignore[union-attr]
1017+
assert arr.metadata.compressor is None # type: ignore[union-attr]
10071018

10081019
# v3
10091020
arr = await create_array(

tests/test_codecs/test_endian.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import numpy as np
44
import pytest
55

6-
from zarr import AsyncArray
76
import zarr
87
from zarr.abc.store import Store
98
from zarr.codecs import BytesCodec

tests/test_codecs/test_sharding.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,10 @@ async def test_delete_empty_shards(store: Store) -> None:
297297
chunks=(8, 8),
298298
shards=(8, 16),
299299
dtype="uint16",
300+
compressors=None,
300301
fill_value=1,
301302
)
303+
print(a.metadata.to_dict())
302304
await _AsyncArrayProxy(a)[:, :].set(np.zeros((16, 16)))
303305
await _AsyncArrayProxy(a)[8:, :].set(np.ones((8, 16)))
304306
await _AsyncArrayProxy(a)[:, 8:].set(np.ones((16, 8)))

0 commit comments

Comments
 (0)