Skip to content

Commit

Permalink
fix mypy in test_array.py
Browse files Browse the repository at this point in the history
  • Loading branch information
brokkoli71 committed Feb 12, 2025
1 parent 584762b commit 3835768
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
8 changes: 4 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def test_open_with_mode_r(tmp_path: pathlib.Path) -> None:
assert isinstance(z2, Array)
assert z2.fill_value == 1
assert isinstance(z2[:], NDArrayLike)
assert (z2[:] == 1).all() # type: ignore [union-attr]
assert (z2[:] == 1).all() # type: ignore [union-attr]
with pytest.raises(ValueError):
z2[:] = 3

Expand All @@ -250,7 +250,7 @@ def test_open_with_mode_r_plus(tmp_path: pathlib.Path) -> None:
z2 = zarr.open(store=tmp_path, mode="r+")
assert isinstance(z2, Array)
assert isinstance(z2[:], NDArrayLike)
assert (z2[:] == 1).all() # type: ignore [union-attr]
assert (z2[:] == 1).all() # type: ignore [union-attr]
z2[:] = 3


Expand All @@ -267,7 +267,7 @@ async def test_open_with_mode_a(tmp_path: pathlib.Path) -> None:
z2 = zarr.open(store=tmp_path, mode="a")
assert isinstance(z2, Array)
assert isinstance(z2[:], NDArrayLike)
assert (z2[:] == 1).all() # type: ignore [union-attr]
assert (z2[:] == 1).all() # type: ignore [union-attr]
z2[:] = 3


Expand All @@ -280,7 +280,7 @@ def test_open_with_mode_w(tmp_path: pathlib.Path) -> None:
z2 = zarr.open(store=tmp_path, mode="w", shape=(3, 3))
assert isinstance(z2, Array)
assert isinstance(z2[:], NDArrayLike)
assert (z2[:] == 3).all() # type: ignore [union-attr]
assert (z2[:] == 3).all() # type: ignore [union-attr]
z2[:] = 3


Expand Down
6 changes: 2 additions & 4 deletions tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
create_array,
)
from zarr.core.buffer import default_buffer_prototype
from zarr.core.buffer.core import NDArrayLike
from zarr.core.buffer.cpu import NDBuffer
from zarr.core.chunk_grids import _auto_partition
from zarr.core.common import JSON, MemoryOrder, ZarrFormat
Expand Down Expand Up @@ -656,10 +655,9 @@ def test_resize_1d(store: MemoryStore, zarr_format: ZarrFormat) -> None:
a = np.arange(105, dtype="i4")
z[:] = a
assert (105,) == z.shape
assert hasattr(z[:], "shape") and hasattr(z[:], "dtype")
assert (105,) == z[:].shape
assert hasattr(z[:], "shape") and (105,) == z[:].shape
assert np.dtype("i4") == z.dtype
assert np.dtype("i4") == z[:].dtype
assert hasattr(z[:], "dtype") and np.dtype("i4") == z[:].dtype
assert (10,) == z.chunks
np.testing.assert_array_equal(a, z[:])

Expand Down
6 changes: 2 additions & 4 deletions tests/test_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ async def test_async_array_prototype() -> None:
prototype=my_prototype,
)
got = await a.getitem(selection=(slice(0, 9), slice(0, 9)), prototype=my_prototype)
# ignoring a mypy error here that TestNDArrayLike doesn't meet the NDArrayLike protocol
# The test passes, so it clearly does.
assert isinstance(got, TestNDArrayLike) # type: ignore[unreachable]
assert np.array_equal(expect, got) # type: ignore[unreachable]
assert isinstance(got, TestNDArrayLike)
assert np.array_equal(expect, got)


@gpu_test
Expand Down

0 comments on commit 3835768

Please sign in to comment.