Skip to content

Commit 0bf4dd0

Browse files
committed
fix some tests
1 parent d9c30a3 commit 0bf4dd0

File tree

11 files changed

+44
-43
lines changed

11 files changed

+44
-43
lines changed

src/zarr/core/array.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3748,16 +3748,22 @@ def _get_default_encoding_v3(
37483748

37493749
def _get_default_chunk_encoding_v2(
37503750
dtype: np.dtype[Any],
3751-
) -> tuple[tuple[numcodecs.abc.Codec, ...], numcodecs.abc.Codec | None]:
3751+
) -> tuple[tuple[numcodecs.abc.Codec, ...] | None, numcodecs.abc.Codec | None]:
37523752
"""
37533753
Get the default chunk encoding for zarr v2 arrays, given a dtype
37543754
"""
37553755

37563756
compressor_dict = _default_compressor(dtype)
37573757
filter_dicts = _default_filters(dtype)
37583758

3759-
compressor = numcodecs.get_codec(compressor_dict)
3760-
filters = tuple(numcodecs.get_codec(f) for f in filter_dicts)
3759+
compressor = None
3760+
if compressor_dict is not None:
3761+
compressor = numcodecs.get_codec(compressor_dict)
3762+
3763+
filters = None
3764+
if filter_dicts is not None:
3765+
filters = tuple(numcodecs.get_codec(f) for f in filter_dicts)
3766+
37613767
return filters, compressor
37623768

37633769

@@ -3766,7 +3772,7 @@ def _parse_chunk_encoding_v2(
37663772
compression: numcodecs.abc.Codec | Literal["auto"],
37673773
filters: tuple[numcodecs.abc.Codec, ...] | Literal["auto"],
37683774
dtype: np.dtype[Any],
3769-
) -> tuple[tuple[numcodecs.abc.Codec, ...], numcodecs.abc.Codec]:
3775+
) -> tuple[tuple[numcodecs.abc.Codec, ...] | None, numcodecs.abc.Codec | None]:
37703776
"""
37713777
Generate chunk encoding classes for v2 arrays with optional defaults.
37723778
"""

src/zarr/core/config.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,27 +67,27 @@ def reset(self) -> None:
6767
"order": "C",
6868
"write_empty_chunks": False,
6969
"v2_default_compressor": {
70-
"numeric": {"id": "zstd", "level": 0, "checksum": True},
71-
"string": {"id": "zstd", "level": 0, "checksum": True},
72-
"bytes": {"id": "zstd", "level": 0, "checksum": True},
70+
"numeric": {"id": "zstd", "level": 0, "checksum": False},
71+
"string": {"id": "zstd", "level": 0, "checksum": False},
72+
"bytes": {"id": "zstd", "level": 0, "checksum": False},
7373
},
7474
"v2_default_filters": {
75-
"numeric": [],
75+
"numeric": None,
7676
"string": [{"id": "vlen-utf8"}],
7777
"bytes": [{"id": "vlen-bytes"}],
7878
},
7979
"v3_default_codecs": {
8080
"numeric": [
8181
{"name": "bytes", "configuration": {"endian": "little"}},
82-
{"name": "zstd", "configuration": {"level": 0, "checksum": True}},
82+
{"name": "zstd", "configuration": {"level": 0, "checksum": False}},
8383
],
8484
"string": [
8585
{"name": "vlen-utf8"},
86-
{"name": "zstd", "configuration": {"level": 0, "checksum": True}},
86+
{"name": "zstd", "configuration": {"level": 0, "checksum": False}},
8787
],
8888
"bytes": [
8989
{"name": "vlen-bytes"},
90-
{"name": "zstd", "configuration": {"level": 0, "checksum": True}},
90+
{"name": "zstd", "configuration": {"level": 0, "checksum": False}},
9191
],
9292
},
9393
},

src/zarr/core/metadata/v2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def _default_compressor(
357357

358358
def _default_filters(
359359
dtype: np.dtype[Any],
360-
) -> list[dict[str, JSON]]:
360+
) -> list[dict[str, JSON]] | None:
361361
"""Get the default filters and compressor for a dtype.
362362
363363
https://numpy.org/doc/2.1/reference/generated/numpy.dtype.kind.html
@@ -372,4 +372,4 @@ def _default_filters(
372372
else:
373373
raise ValueError(f"Unsupported dtype kind {dtype.kind}")
374374

375-
return default_filters.get(dtype_key, [])
375+
return default_filters.get(dtype_key, None)

src/zarr/testing/strategies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def arrays(
143143
a = root.create_array(
144144
array_path,
145145
shape=nparray.shape,
146-
chunk_shape=chunks,
146+
chunks=chunks,
147147
dtype=nparray.dtype,
148148
attributes=attributes,
149149
# compressor=compressor, # FIXME

tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_create_array(store: Store) -> None:
6868
path = "foo"
6969
data_val = 1
7070
array_w = create_array(
71-
store, name=path, shape=shape, attributes=attrs, chunk_shape=shape, dtype="uint8"
71+
store, name=path, shape=shape, attributes=attrs, chunks=shape, dtype="uint8"
7272
)
7373
array_w[:] = data_val
7474
assert array_w.shape == shape

tests/test_array.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import numcodecs
99
import numpy as np
1010
import pytest
11-
from numcodecs import Zstd
1211

1312
import zarr.api.asynchronous
1413
from zarr import Array, AsyncArray, Group
@@ -138,13 +137,13 @@ def test_array_name_properties_with_group(
138137
store: LocalStore | MemoryStore, zarr_format: ZarrFormat
139138
) -> None:
140139
root = Group.from_store(store=store, zarr_format=zarr_format)
141-
foo = root.create_array("foo", shape=(100,), chunk_shape=(10,), dtype="i4")
140+
foo = root.create_array("foo", shape=(100,), chunks=(10,), dtype="i4")
142141
assert foo.path == "foo"
143142
assert foo.name == "/foo"
144143
assert foo.basename == "foo"
145144

146145
bar = root.create_group("bar")
147-
spam = bar.create_array("spam", shape=(100,), chunk_shape=(10,), dtype="i4")
146+
spam = bar.create_array("spam", shape=(100,), chunks=(10,), dtype="i4")
148147

149148
assert spam.path == "bar/spam"
150149
assert spam.name == "/bar/spam"
@@ -463,7 +462,7 @@ def test_info_v2(self) -> None:
463462
_read_only=False,
464463
_store_type="MemoryStore",
465464
_count_bytes=128,
466-
_filters=(numcodecs.Zstd(),),
465+
_compressor=numcodecs.Zstd(),
467466
)
468467
assert result == expected
469468

@@ -519,8 +518,8 @@ async def test_info_v2_async(self) -> None:
519518
_order="C",
520519
_read_only=False,
521520
_store_type="MemoryStore",
522-
_filters=(Zstd(level=0),),
523521
_count_bytes=128,
522+
_compressor=numcodecs.Zstd(),
524523
)
525524
assert result == expected
526525

@@ -925,7 +924,7 @@ def test_auto_partition_auto_shards(
925924
expected_shards += (cs,)
926925

927926
auto_shards, _ = _auto_partition(
928-
array_shape=array_shape, chunks=chunk_shape, shards="auto", dtype=dtype
927+
array_shape=array_shape, chunk_shape=chunk_shape, shard_shape="auto", dtype=dtype
929928
)
930929
assert auto_shards == expected_shards
931930

tests/test_config.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,27 @@ def test_config_defaults_set() -> None:
5454
"order": "C",
5555
"write_empty_chunks": False,
5656
"v2_default_compressor": {
57-
"numeric": {"id": "zstd", "level": 0, "checksum": True},
58-
"string": {"id": "zstd", "level": 0, "checksum": True},
59-
"bytes": {"id": "zstd", "level": 0, "checksum": True},
57+
"numeric": {"id": "zstd", "level": 0, "checksum": False},
58+
"string": {"id": "zstd", "level": 0, "checksum": False},
59+
"bytes": {"id": "zstd", "level": 0, "checksum": False},
6060
},
6161
"v2_default_filters": {
62-
"numeric": [],
62+
"numeric": None,
6363
"string": [{"id": "vlen-utf8"}],
6464
"bytes": [{"id": "vlen-bytes"}],
6565
},
6666
"v3_default_codecs": {
6767
"bytes": [
6868
{"name": "vlen-bytes"},
69-
{"name": "zstd", "configuration": {"level": 0, "checksum": True}},
69+
{"name": "zstd", "configuration": {"level": 0, "checksum": False}},
7070
],
7171
"numeric": [
7272
{"name": "bytes", "configuration": {"endian": "little"}},
73-
{"name": "zstd", "configuration": {"level": 0, "checksum": True}},
73+
{"name": "zstd", "configuration": {"level": 0, "checksum": False}},
7474
],
7575
"string": [
7676
{"name": "vlen-utf8"},
77-
{"name": "zstd", "configuration": {"level": 0, "checksum": True}},
77+
{"name": "zstd", "configuration": {"level": 0, "checksum": False}},
7878
],
7979
},
8080
},

tests/test_group.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def test_group_members(store: Store, zarr_format: ZarrFormat, consolidated_metad
155155
subsubsubgroup = subsubgroup.create_group("subsubsubgroup")
156156

157157
members_expected["subarray"] = group.create_array(
158-
"subarray", shape=(100,), dtype="uint8", chunk_shape=(10,), overwrite=True
158+
"subarray", shape=(100,), dtype="uint8", chunks=(10,), overwrite=True
159159
)
160160
# add an extra object to the domain of the group.
161161
# the list of children should ignore this object.
@@ -226,9 +226,7 @@ def test_group(store: Store, zarr_format: ZarrFormat) -> None:
226226

227227
# create an array from the "bar" group
228228
data = np.arange(0, 4 * 4, dtype="uint16").reshape((4, 4))
229-
arr = bar.create_array(
230-
"baz", shape=data.shape, dtype=data.dtype, chunk_shape=(2, 2), overwrite=True
231-
)
229+
arr = bar.create_array("baz", shape=data.shape, dtype=data.dtype, chunks=(2, 2), overwrite=True)
232230
arr[:] = data
233231

234232
# check the array
@@ -312,10 +310,8 @@ def test_group_getitem(store: Store, zarr_format: ZarrFormat, consolidated: bool
312310

313311
group = Group.from_store(store, zarr_format=zarr_format)
314312
subgroup = group.create_group(name="subgroup")
315-
subarray = group.create_array(name="subarray", shape=(10,), chunk_shape=(10,), dtype="uint8")
316-
subsubarray = subgroup.create_array(
317-
name="subarray", shape=(10,), chunk_shape=(10,), dtype="uint8"
318-
)
313+
subarray = group.create_array(name="subarray", shape=(10,), chunks=(10,), dtype="uint8")
314+
subsubarray = subgroup.create_array(name="subarray", shape=(10,), chunks=(10,), dtype="uint8")
319315

320316
if consolidated:
321317
group = zarr.api.synchronous.consolidate_metadata(store=store, zarr_format=zarr_format)
@@ -392,7 +388,7 @@ def test_group_delitem(store: Store, zarr_format: ZarrFormat, consolidated: bool
392388

393389
group = Group.from_store(store, zarr_format=zarr_format)
394390
subgroup = group.create_group(name="subgroup")
395-
subarray = group.create_array(name="subarray", shape=(10,), chunk_shape=(10,), dtype="uint8")
391+
subarray = group.create_array(name="subarray", shape=(10,), chunks=(10,), dtype="uint8")
396392

397393
if consolidated:
398394
group = zarr.api.synchronous.consolidate_metadata(store=store, zarr_format=zarr_format)
@@ -500,7 +496,7 @@ def test_group_child_iterators(store: Store, zarr_format: ZarrFormat, consolidat
500496
"shape": (1,),
501497
"chunks": (1,),
502498
"order": "C",
503-
"filters": (),
499+
"filters": None,
504500
"compressor": Zstd(level=0),
505501
"zarr_format": zarr_format,
506502
},

tests/test_metadata/test_consolidated.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async def test_consolidated(self, memory_store_with_hierarchy: Store) -> None:
7777
},
7878
"codecs": (
7979
{"configuration": {"endian": "little"}, "name": "bytes"},
80-
{"configuration": {}, "name": "zstd"},
80+
{"configuration": {"level": 0, "checksum": False}, "name": "zstd"},
8181
),
8282
"data_type": "uint8",
8383
"fill_value": 0,
@@ -225,7 +225,7 @@ def test_consolidated_sync(self, memory_store):
225225
},
226226
"codecs": (
227227
{"configuration": {"endian": "little"}, "name": "bytes"},
228-
{"configuration": {}, "name": "zstd"},
228+
{"configuration": {"level": 0, "checksum": False}, "name": "zstd"},
229229
),
230230
"data_type": dtype,
231231
"fill_value": 0,
@@ -498,7 +498,7 @@ async def test_consolidated_metadata_v2(self):
498498
attributes={"key": "a"},
499499
chunks=(1,),
500500
fill_value=0,
501-
filters=(Zstd(level=0),),
501+
compressor=Zstd(level=0),
502502
order="C",
503503
),
504504
"g1": GroupMetadata(

tests/test_store/test_zip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def test_api_integration(self, store: ZipStore) -> None:
6969

7070
data = np.arange(10000, dtype=np.uint16).reshape(100, 100)
7171
z = root.create_array(
72-
shape=data.shape, chunk_shape=(10, 10), name="foo", dtype=np.uint16, fill_value=99
72+
shape=data.shape, chunks=(10, 10), name="foo", dtype=np.uint16, fill_value=99
7373
)
7474
z[:] = data
7575

0 commit comments

Comments
 (0)