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 3835768 commit 363f06b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/zarr/api/synchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import zarr.core.array
from zarr._compat import _deprecate_positional_args
from zarr.core.array import Array, AsyncArray
from zarr.core.buffer.core import NDArrayLike
from zarr.core.group import Group
from zarr.core.sync import sync

Expand All @@ -28,6 +27,7 @@
)
from zarr.core.array_spec import ArrayConfig, ArrayConfigLike
from zarr.core.buffer import NDArrayOrScalarLike
from zarr.core.buffer.core import NDArrayLike
from zarr.core.chunk_key_encodings import ChunkKeyEncoding, ChunkKeyEncodingLike
from zarr.core.common import (
JSON,
Expand Down
27 changes: 18 additions & 9 deletions tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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 @@ -654,35 +655,43 @@ def test_resize_1d(store: MemoryStore, zarr_format: ZarrFormat) -> None:
)
a = np.arange(105, dtype="i4")
z[:] = a
result = z[:]
assert isinstance(result, NDArrayLike)
assert (105,) == z.shape
assert hasattr(z[:], "shape") and (105,) == z[:].shape
assert (105,) == result.shape
assert np.dtype("i4") == z.dtype
assert hasattr(z[:], "dtype") and np.dtype("i4") == z[:].dtype
assert np.dtype("i4") == result.dtype
assert (10,) == z.chunks
np.testing.assert_array_equal(a, z[:])
np.testing.assert_array_equal(a, result)

z.resize(205)
result = z[:]
assert isinstance(result, NDArrayLike)
assert (205,) == z.shape
assert (205,) == z[:].shape
assert (205,) == result.shape
assert np.dtype("i4") == z.dtype
assert np.dtype("i4") == z[:].dtype
assert np.dtype("i4") == result.dtype
assert (10,) == z.chunks
np.testing.assert_array_equal(a, z[:105])
np.testing.assert_array_equal(np.zeros(100, dtype="i4"), z[105:])

z.resize(55)
result = z[:]
assert isinstance(result, NDArrayLike)
assert (55,) == z.shape
assert (55,) == z[:].shape
assert (55,) == result.shape
assert np.dtype("i4") == z.dtype
assert np.dtype("i4") == z[:].dtype
assert np.dtype("i4") == result.dtype
assert (10,) == z.chunks
np.testing.assert_array_equal(a[:55], z[:])
np.testing.assert_array_equal(a[:55], result)

# via shape setter
new_shape = (105,)
z.shape = new_shape
result = z[:]
assert isinstance(result, NDArrayLike)
assert new_shape == z.shape
assert new_shape == z[:].shape
assert new_shape == result.shape


@pytest.mark.parametrize("store", ["memory"], indirect=True)
Expand Down

0 comments on commit 363f06b

Please sign in to comment.