Skip to content

Commit 534e0cd

Browse files
authored
More typing fixes for tests (#2173)
1 parent 52d6849 commit 534e0cd

File tree

13 files changed

+102
-87
lines changed

13 files changed

+102
-87
lines changed

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ ignore_errors = true
241241
module = [
242242
"tests.v2.*",
243243
"tests.v3.package_with_entrypoint.*",
244-
"tests.v3.test_codecs.*",
244+
"tests.v3.test_codecs.test_codecs",
245+
"tests.v3.test_codecs.test_transpose",
245246
"tests.v3.test_metadata.*",
246247
"tests.v3.test_store.*",
247248
"tests.v3.test_config",

src/zarr/core/group.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ async def require_array(
516516
self,
517517
name: str,
518518
*,
519-
shape: ChunkCoords,
519+
shape: ShapeLike,
520520
dtype: npt.DTypeLike = None,
521521
exact: bool = False,
522522
**kwargs: Any,

tests/v3/package_with_entrypoint/__init__.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from numpy import ndarray
44

5+
import zarr.core.buffer
56
from zarr.abc.codec import ArrayBytesCodec, CodecInput, CodecOutput, CodecPipeline
67
from zarr.codecs import BytesCodec
78
from zarr.core.array_spec import ArraySpec
@@ -29,7 +30,7 @@ def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) ->
2930

3031

3132
class TestEntrypointCodecPipeline(CodecPipeline):
32-
def __init__(self, batch_size: int = 1):
33+
def __init__(self, batch_size: int = 1) -> None:
3334
pass
3435

3536
async def encode(
@@ -55,10 +56,10 @@ class TestEntrypointGroup:
5556
class Codec(BytesCodec):
5657
pass
5758

58-
class Buffer(Buffer):
59+
class Buffer(zarr.core.buffer.Buffer):
5960
pass
6061

61-
class NDBuffer(NDBuffer):
62+
class NDBuffer(zarr.core.buffer.NDBuffer):
6263
pass
6364

6465
class Pipeline(CodecPipeline):

tests/v3/test_codecs/test_blosc.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ async def test_blosc_evolve(store: Store, dtype: str) -> None:
2424
fill_value=0,
2525
codecs=[BytesCodec(), BloscCodec()],
2626
)
27-
28-
zarr_json = json.loads(
29-
(await store.get(f"{path}/zarr.json", prototype=default_buffer_prototype())).to_bytes()
30-
)
27+
buf = await store.get(f"{path}/zarr.json", prototype=default_buffer_prototype())
28+
assert buf is not None
29+
zarr_json = json.loads(buf.to_bytes())
3130
blosc_configuration_json = zarr_json["codecs"][1]["configuration"]
3231
assert blosc_configuration_json["typesize"] == typesize
3332
if typesize == 1:
@@ -45,10 +44,9 @@ async def test_blosc_evolve(store: Store, dtype: str) -> None:
4544
fill_value=0,
4645
codecs=[ShardingCodec(chunk_shape=(16, 16), codecs=[BytesCodec(), BloscCodec()])],
4746
)
48-
49-
zarr_json = json.loads(
50-
(await store.get(f"{path2}/zarr.json", prototype=default_buffer_prototype())).to_bytes()
51-
)
47+
buf = await store.get(f"{path2}/zarr.json", prototype=default_buffer_prototype())
48+
assert buf is not None
49+
zarr_json = json.loads(buf.to_bytes())
5250
blosc_configuration_json = zarr_json["codecs"][0]["configuration"]["codecs"][1]["configuration"]
5351
assert blosc_configuration_json["typesize"] == typesize
5452
if typesize == 1:

tests/v3/test_codecs/test_codecs.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy as np
88
import pytest
99

10-
import zarr.v2
10+
import zarr.v2.creation
1111
from zarr import Array, AsyncArray, config
1212
from zarr.codecs import (
1313
BytesCodec,
@@ -23,6 +23,7 @@
2323
if TYPE_CHECKING:
2424
from zarr.abc.codec import Codec
2525
from zarr.abc.store import Store
26+
from zarr.core.buffer.core import NDArrayLike
2627
from zarr.core.common import MemoryOrder
2728

2829

@@ -39,7 +40,7 @@ class _AsyncArraySelectionProxy:
3940
array: AsyncArray
4041
selection: Selection
4142

42-
async def get(self) -> np.ndarray:
43+
async def get(self) -> NDArrayLike:
4344
return await self.array.getitem(self.selection)
4445

4546
async def set(self, value: np.ndarray) -> None:
@@ -119,7 +120,7 @@ async def test_order(
119120

120121
if not with_sharding:
121122
# Compare with zarr-python
122-
z = zarr.v2.create(
123+
z = zarr.v2.creation.create(
123124
shape=data.shape,
124125
chunks=(32, 8),
125126
dtype="<u2",
@@ -268,7 +269,7 @@ async def test_zarr_compat(store: Store) -> None:
268269
fill_value=1,
269270
)
270271

271-
z2 = zarr.v2.create(
272+
z2 = zarr.v2.creation.create(
272273
shape=data.shape,
273274
chunks=(10, 10),
274275
dtype=data.dtype,
@@ -310,7 +311,7 @@ async def test_zarr_compat_F(store: Store) -> None:
310311
codecs=[TransposeCodec(order=order_from_dim("F", data.ndim)), BytesCodec()],
311312
)
312313

313-
z2 = zarr.v2.create(
314+
z2 = zarr.v2.creation.create(
314315
shape=data.shape,
315316
chunks=(10, 10),
316317
dtype=data.dtype,
@@ -406,7 +407,7 @@ def test_invalid_metadata(store: Store) -> None:
406407
fill_value=0,
407408
codecs=[
408409
BytesCodec(),
409-
TransposeCodec(order="F"),
410+
TransposeCodec(order="F"), # type: ignore[arg-type]
410411
],
411412
)
412413
spath4 = StorePath(store, "invalid_missing_bytes_codec")

tests/v3/test_codecs/test_endian.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44
import pytest
55

6-
import zarr.v2
6+
import zarr.v2.creation
77
from zarr import AsyncArray
88
from zarr.abc.store import Store
99
from zarr.codecs import BytesCodec
@@ -35,7 +35,7 @@ async def test_endian(store: Store, endian: Literal["big", "little"]) -> None:
3535
assert np.array_equal(data, readback_data)
3636

3737
# Compare with v2
38-
z = zarr.v2.create(
38+
z = zarr.v2.creation.create(
3939
shape=data.shape,
4040
chunks=(16, 16),
4141
dtype=">u2" if endian == "big" else "<u2",
@@ -74,7 +74,7 @@ async def test_endian_write(
7474
assert np.array_equal(data, readback_data)
7575

7676
# Compare with zarr-python
77-
z = zarr.v2.create(
77+
z = zarr.v2.creation.create(
7878
shape=data.shape,
7979
chunks=(16, 16),
8080
dtype=">u2" if dtype_store_endian == "big" else "<u2",

tests/v3/test_codecs/test_sharding.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import pickle
2+
from typing import Any
23

34
import numpy as np
5+
import numpy.typing as npt
46
import pytest
57

68
from zarr import Array, AsyncArray
@@ -32,7 +34,10 @@
3234
)
3335
@pytest.mark.parametrize("offset", [0, 10])
3436
def test_sharding(
35-
store: Store, array_fixture: np.ndarray, index_location: ShardingCodecIndexLocation, offset: int
37+
store: Store,
38+
array_fixture: npt.NDArray[Any],
39+
index_location: ShardingCodecIndexLocation,
40+
offset: int,
3641
) -> None:
3742
"""
3843
Test that we can create an array with a sharding codec, write data to that array, and get
@@ -80,7 +85,7 @@ def test_sharding(
8085
indirect=["array_fixture"],
8186
)
8287
def test_sharding_partial(
83-
store: Store, array_fixture: np.ndarray, index_location: ShardingCodecIndexLocation
88+
store: Store, array_fixture: npt.NDArray[Any], index_location: ShardingCodecIndexLocation
8489
) -> None:
8590
data = array_fixture
8691
spath = StorePath(store)
@@ -123,7 +128,7 @@ def test_sharding_partial(
123128
@pytest.mark.parametrize("index_location", ["start", "end"])
124129
@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"])
125130
def test_sharding_partial_read(
126-
store: Store, array_fixture: np.ndarray, index_location: ShardingCodecIndexLocation
131+
store: Store, array_fixture: npt.NDArray[Any], index_location: ShardingCodecIndexLocation
127132
) -> None:
128133
data = array_fixture
129134
spath = StorePath(store)
@@ -160,7 +165,7 @@ def test_sharding_partial_read(
160165
@pytest.mark.parametrize("index_location", ["start", "end"])
161166
@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"])
162167
def test_sharding_partial_overwrite(
163-
store: Store, array_fixture: np.ndarray, index_location: ShardingCodecIndexLocation
168+
store: Store, array_fixture: npt.NDArray[Any], index_location: ShardingCodecIndexLocation
164169
) -> None:
165170
data = array_fixture[:10, :10, :10]
166171
spath = StorePath(store)
@@ -212,7 +217,7 @@ def test_sharding_partial_overwrite(
212217
@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"])
213218
def test_nested_sharding(
214219
store: Store,
215-
array_fixture: np.ndarray,
220+
array_fixture: npt.NDArray[Any],
216221
outer_index_location: ShardingCodecIndexLocation,
217222
inner_index_location: ShardingCodecIndexLocation,
218223
) -> None:

tests/v3/test_codecs/test_transpose.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44
import pytest
55

6-
import zarr.v2
6+
import zarr.v2.creation
77
from zarr import Array, AsyncArray, config
88
from zarr.abc.store import Store
99
from zarr.codecs import BytesCodec, ShardingCodec, TransposeCodec
@@ -72,7 +72,7 @@ async def test_transpose(
7272

7373
if not with_sharding:
7474
# Compare with zarr-python
75-
z = zarr.v2.create(
75+
z = zarr.v2.creation.create(
7676
shape=data.shape,
7777
chunks=(1, 32, 8),
7878
dtype="<u2",

tests/v3/test_group.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from zarr import Array, AsyncArray, AsyncGroup, Group
1010
from zarr.api.synchronous import open_group
1111
from zarr.core.buffer import default_buffer_prototype
12-
from zarr.core.common import ZarrFormat
12+
from zarr.core.common import JSON, ZarrFormat
1313
from zarr.core.group import GroupMetadata
1414
from zarr.core.sync import sync
1515
from zarr.errors import ContainsArrayError, ContainsGroupError
@@ -409,7 +409,7 @@ def test_group_creation_existing_node(
409409
spath = StorePath(store)
410410
group = Group.create(spath, zarr_format=zarr_format)
411411
expected_exception: type[ContainsArrayError] | type[ContainsGroupError]
412-
attributes = {"old": True}
412+
attributes: dict[str, JSON] = {"old": True}
413413

414414
if extant_node == "array":
415415
expected_exception = ContainsArrayError
@@ -645,7 +645,7 @@ async def test_asyncgroup_create_array(
645645
shape = (10,)
646646
dtype = "uint8"
647647
chunk_shape = (4,)
648-
attributes = {"foo": 100}
648+
attributes: dict[str, JSON] = {"foo": 100}
649649

650650
sub_node_path = "sub_array"
651651
subnode = await agroup.create_array(

0 commit comments

Comments
 (0)