Skip to content

Commit e3f1f33

Browse files
committed
mypy
1 parent 2afe940 commit e3f1f33

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

tests/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
save_array,
2424
save_group,
2525
)
26-
from zarr.core.common import MemoryOrder, ZarrFormat
26+
from zarr.core.common import JSON, MemoryOrder, ZarrFormat
2727
from zarr.errors import MetadataValidationError
2828
from zarr.storage._utils import normalize_path
2929
from zarr.storage.memory import MemoryStore
@@ -61,7 +61,7 @@ def test_create(memory_store: Store) -> None:
6161
# TODO: parametrize over everything this function takes
6262
@pytest.mark.parametrize("store", ["memory"], indirect=True)
6363
def test_create_array(store: Store) -> None:
64-
attrs = {"foo": 100}
64+
attrs: dict[str, JSON] = {"foo": 100} # explicit type annotation to avoid mypy error
6565
shape = (10, 10)
6666
path = "foo"
6767
data_val = 1

tests/test_array.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pickle
55
import re
66
from itertools import accumulate
7-
from typing import Any, Literal
7+
from typing import TYPE_CHECKING, Any, Literal
88

99
import numcodecs
1010
import numpy as np
@@ -43,6 +43,9 @@
4343
from zarr.storage import LocalStore, MemoryStore
4444
from zarr.storage.common import StorePath
4545

46+
if TYPE_CHECKING:
47+
from zarr.core.array_spec import ArrayConfigParams
48+
4649

4750
@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"])
4851
@pytest.mark.parametrize("zarr_format", [2, 3])
@@ -421,16 +424,16 @@ async def test_nbytes_stored_async() -> None:
421424

422425

423426
def test_default_fill_values() -> None:
424-
a = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="<U4")
427+
a = zarr.Array.create(MemoryStore(), shape=5, chunk_shape=5, dtype="<U4")
425428
assert a.fill_value == ""
426429

427-
b = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="<S4")
430+
b = zarr.Array.create(MemoryStore(), shape=5, chunk_shape=5, dtype="<S4")
428431
assert b.fill_value == b""
429432

430-
c = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="i")
433+
c = zarr.Array.create(MemoryStore(), shape=5, chunk_shape=5, dtype="i")
431434
assert c.fill_value == 0
432435

433-
d = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="f")
436+
d = zarr.Array.create(MemoryStore(), shape=5, chunk_shape=5, dtype="f")
434437
assert d.fill_value == 0.0
435438

436439

@@ -458,15 +461,17 @@ def test_vlen_errors() -> None:
458461
match="For string dtype, ArrayBytesCodec must be `VLenUTF8Codec`, got `BytesCodec`.",
459462
):
460463
zarr.create_array(
461-
MemoryStore(), shape=5, chunks=5, dtype="<U4", array_bytes_codec=BytesCodec()
464+
MemoryStore(), shape=(5,), chunks=(5,), dtype="<U4", array_bytes_codec=BytesCodec()
462465
)
463466

464467

465468
@pytest.mark.parametrize("zarr_format", [2, 3])
466-
def test_update_attrs(zarr_format: int) -> None:
469+
def test_update_attrs(zarr_format: Literal[2, 3]) -> None:
467470
# regression test for https://github.com/zarr-developers/zarr-python/issues/2328
468471
store = MemoryStore()
469-
arr = zarr.create_array(store=store, shape=5, chunks=5, dtype="f8", zarr_format=zarr_format)
472+
arr = zarr.create_array(
473+
store=store, shape=(5,), chunks=(5,), dtype="f8", zarr_format=zarr_format
474+
)
470475
arr.attrs["foo"] = "bar"
471476
assert arr.attrs["foo"] == "bar"
472477

@@ -794,13 +799,14 @@ def test_array_create_metadata_order_v2(
794799
@pytest.mark.parametrize("store", ["memory"], indirect=True)
795800
def test_array_create_order(
796801
order_config: MemoryOrder | None,
797-
zarr_format: int,
802+
zarr_format: Literal[2, 3],
798803
store: MemoryStore,
799804
) -> None:
800805
"""
801806
Test that the arrays generated by array indexing have a memory order defined by the config order
802807
value
803808
"""
809+
config: ArrayConfigParams = {}
804810
if order_config is None:
805811
config = {}
806812
expected = zarr.config.get("array.order")
@@ -963,16 +969,16 @@ def test_chunks_and_shards() -> None:
963969

964970

965971
def test_create_array_default_fill_values() -> None:
966-
a = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="<U4")
972+
a = zarr.create_array(MemoryStore(), shape=(5,), chunks=(5,), dtype="<U4")
967973
assert a.fill_value == ""
968974

969-
b = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="<S4")
975+
b = zarr.create_array(MemoryStore(), shape=(5,), chunks=(5,), dtype="<S4")
970976
assert b.fill_value == b""
971977

972-
c = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="i")
978+
c = zarr.create_array(MemoryStore(), shape=(5,), chunks=(5,), dtype="i")
973979
assert c.fill_value == 0
974980

975-
d = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="f")
981+
d = zarr.create_array(MemoryStore(), shape=(5,), chunks=(5,), dtype="f")
976982
assert d.fill_value == 0.0
977983

978984

tests/test_codecs/test_sharding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ async def test_sharding_with_chunks_per_shard(
407407
store: Store, index_location: ShardingCodecIndexLocation, chunks_per_shard: tuple[int]
408408
) -> None:
409409
chunk_shape = (2, 1)
410-
shape = [x * y for x, y in zip(chunks_per_shard, chunk_shape, strict=False)]
410+
shape = tuple(x * y for x, y in zip(chunks_per_shard, chunk_shape, strict=False))
411411
data = np.ones(np.prod(shape), dtype="int32").reshape(shape)
412412
fill_value = 42
413413

0 commit comments

Comments
 (0)