Skip to content

More typing fixes for tests #2173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ ignore_errors = true
module = [
"tests.v2.*",
"tests.v3.package_with_entrypoint.*",
"tests.v3.test_codecs.*",
"tests.v3.test_codecs.test_codecs",
"tests.v3.test_codecs.test_transpose",
"tests.v3.test_metadata.*",
"tests.v3.test_store.*",
"tests.v3.test_config",
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ async def require_array(
self,
name: str,
*,
shape: ChunkCoords,
shape: ShapeLike,
dtype: npt.DTypeLike = None,
exact: bool = False,
**kwargs: Any,
Expand Down
7 changes: 4 additions & 3 deletions tests/v3/package_with_entrypoint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from numpy import ndarray

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


class TestEntrypointCodecPipeline(CodecPipeline):
def __init__(self, batch_size: int = 1):
def __init__(self, batch_size: int = 1) -> None:
pass

async def encode(
Expand All @@ -55,10 +56,10 @@ class TestEntrypointGroup:
class Codec(BytesCodec):
pass

class Buffer(Buffer):
class Buffer(zarr.core.buffer.Buffer):
pass

class NDBuffer(NDBuffer):
class NDBuffer(zarr.core.buffer.NDBuffer):
pass

class Pipeline(CodecPipeline):
Expand Down
14 changes: 6 additions & 8 deletions tests/v3/test_codecs/test_blosc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ async def test_blosc_evolve(store: Store, dtype: str) -> None:
fill_value=0,
codecs=[BytesCodec(), BloscCodec()],
)

zarr_json = json.loads(
(await store.get(f"{path}/zarr.json", prototype=default_buffer_prototype())).to_bytes()
)
buf = await store.get(f"{path}/zarr.json", prototype=default_buffer_prototype())
assert buf is not None
zarr_json = json.loads(buf.to_bytes())
blosc_configuration_json = zarr_json["codecs"][1]["configuration"]
assert blosc_configuration_json["typesize"] == typesize
if typesize == 1:
Expand All @@ -45,10 +44,9 @@ async def test_blosc_evolve(store: Store, dtype: str) -> None:
fill_value=0,
codecs=[ShardingCodec(chunk_shape=(16, 16), codecs=[BytesCodec(), BloscCodec()])],
)

zarr_json = json.loads(
(await store.get(f"{path2}/zarr.json", prototype=default_buffer_prototype())).to_bytes()
)
buf = await store.get(f"{path2}/zarr.json", prototype=default_buffer_prototype())
assert buf is not None
zarr_json = json.loads(buf.to_bytes())
blosc_configuration_json = zarr_json["codecs"][0]["configuration"]["codecs"][1]["configuration"]
assert blosc_configuration_json["typesize"] == typesize
if typesize == 1:
Expand Down
13 changes: 7 additions & 6 deletions tests/v3/test_codecs/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
import pytest

import zarr.v2
import zarr.v2.creation
from zarr import Array, AsyncArray, config
from zarr.codecs import (
BytesCodec,
Expand All @@ -23,6 +23,7 @@
if TYPE_CHECKING:
from zarr.abc.codec import Codec
from zarr.abc.store import Store
from zarr.core.buffer.core import NDArrayLike
from zarr.core.common import MemoryOrder


Expand All @@ -39,7 +40,7 @@ class _AsyncArraySelectionProxy:
array: AsyncArray
selection: Selection

async def get(self) -> np.ndarray:
async def get(self) -> NDArrayLike:
return await self.array.getitem(self.selection)

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

if not with_sharding:
# Compare with zarr-python
z = zarr.v2.create(
z = zarr.v2.creation.create(
shape=data.shape,
chunks=(32, 8),
dtype="<u2",
Expand Down Expand Up @@ -268,7 +269,7 @@ async def test_zarr_compat(store: Store) -> None:
fill_value=1,
)

z2 = zarr.v2.create(
z2 = zarr.v2.creation.create(
shape=data.shape,
chunks=(10, 10),
dtype=data.dtype,
Expand Down Expand Up @@ -310,7 +311,7 @@ async def test_zarr_compat_F(store: Store) -> None:
codecs=[TransposeCodec(order=order_from_dim("F", data.ndim)), BytesCodec()],
)

z2 = zarr.v2.create(
z2 = zarr.v2.creation.create(
shape=data.shape,
chunks=(10, 10),
dtype=data.dtype,
Expand Down Expand Up @@ -406,7 +407,7 @@ def test_invalid_metadata(store: Store) -> None:
fill_value=0,
codecs=[
BytesCodec(),
TransposeCodec(order="F"),
TransposeCodec(order="F"), # type: ignore[arg-type]
],
)
spath4 = StorePath(store, "invalid_missing_bytes_codec")
Expand Down
6 changes: 3 additions & 3 deletions tests/v3/test_codecs/test_endian.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import pytest

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

# Compare with v2
z = zarr.v2.create(
z = zarr.v2.creation.create(
shape=data.shape,
chunks=(16, 16),
dtype=">u2" if endian == "big" else "<u2",
Expand Down Expand Up @@ -74,7 +74,7 @@ async def test_endian_write(
assert np.array_equal(data, readback_data)

# Compare with zarr-python
z = zarr.v2.create(
z = zarr.v2.creation.create(
shape=data.shape,
chunks=(16, 16),
dtype=">u2" if dtype_store_endian == "big" else "<u2",
Expand Down
15 changes: 10 additions & 5 deletions tests/v3/test_codecs/test_sharding.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pickle
from typing import Any

import numpy as np
import numpy.typing as npt
import pytest

from zarr import Array, AsyncArray
Expand Down Expand Up @@ -32,7 +34,10 @@
)
@pytest.mark.parametrize("offset", [0, 10])
def test_sharding(
store: Store, array_fixture: np.ndarray, index_location: ShardingCodecIndexLocation, offset: int
store: Store,
array_fixture: npt.NDArray[Any],
index_location: ShardingCodecIndexLocation,
offset: int,
) -> None:
"""
Test that we can create an array with a sharding codec, write data to that array, and get
Expand Down Expand Up @@ -80,7 +85,7 @@ def test_sharding(
indirect=["array_fixture"],
)
def test_sharding_partial(
store: Store, array_fixture: np.ndarray, index_location: ShardingCodecIndexLocation
store: Store, array_fixture: npt.NDArray[Any], index_location: ShardingCodecIndexLocation
) -> None:
data = array_fixture
spath = StorePath(store)
Expand Down Expand Up @@ -123,7 +128,7 @@ def test_sharding_partial(
@pytest.mark.parametrize("index_location", ["start", "end"])
@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"])
def test_sharding_partial_read(
store: Store, array_fixture: np.ndarray, index_location: ShardingCodecIndexLocation
store: Store, array_fixture: npt.NDArray[Any], index_location: ShardingCodecIndexLocation
) -> None:
data = array_fixture
spath = StorePath(store)
Expand Down Expand Up @@ -160,7 +165,7 @@ def test_sharding_partial_read(
@pytest.mark.parametrize("index_location", ["start", "end"])
@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"])
def test_sharding_partial_overwrite(
store: Store, array_fixture: np.ndarray, index_location: ShardingCodecIndexLocation
store: Store, array_fixture: npt.NDArray[Any], index_location: ShardingCodecIndexLocation
) -> None:
data = array_fixture[:10, :10, :10]
spath = StorePath(store)
Expand Down Expand Up @@ -212,7 +217,7 @@ def test_sharding_partial_overwrite(
@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"])
def test_nested_sharding(
store: Store,
array_fixture: np.ndarray,
array_fixture: npt.NDArray[Any],
outer_index_location: ShardingCodecIndexLocation,
inner_index_location: ShardingCodecIndexLocation,
) -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/v3/test_codecs/test_transpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import pytest

import zarr.v2
import zarr.v2.creation
from zarr import Array, AsyncArray, config
from zarr.abc.store import Store
from zarr.codecs import BytesCodec, ShardingCodec, TransposeCodec
Expand Down Expand Up @@ -72,7 +72,7 @@ async def test_transpose(

if not with_sharding:
# Compare with zarr-python
z = zarr.v2.create(
z = zarr.v2.creation.create(
shape=data.shape,
chunks=(1, 32, 8),
dtype="<u2",
Expand Down
6 changes: 3 additions & 3 deletions tests/v3/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from zarr import Array, AsyncArray, AsyncGroup, Group
from zarr.api.synchronous import open_group
from zarr.core.buffer import default_buffer_prototype
from zarr.core.common import ZarrFormat
from zarr.core.common import JSON, ZarrFormat
from zarr.core.group import GroupMetadata
from zarr.core.sync import sync
from zarr.errors import ContainsArrayError, ContainsGroupError
Expand Down Expand Up @@ -409,7 +409,7 @@ def test_group_creation_existing_node(
spath = StorePath(store)
group = Group.create(spath, zarr_format=zarr_format)
expected_exception: type[ContainsArrayError] | type[ContainsGroupError]
attributes = {"old": True}
attributes: dict[str, JSON] = {"old": True}

if extant_node == "array":
expected_exception = ContainsArrayError
Expand Down Expand Up @@ -645,7 +645,7 @@ async def test_asyncgroup_create_array(
shape = (10,)
dtype = "uint8"
chunk_shape = (4,)
attributes = {"foo": 100}
attributes: dict[str, JSON] = {"foo": 100}

sub_node_path = "sub_array"
subnode = await agroup.create_array(
Expand Down
Loading