diff --git a/pyproject.toml b/pyproject.toml index 49878b61f6..886cd5a0bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/src/zarr/core/group.py b/src/zarr/core/group.py index 56c9c88ea5..40815b96c8 100644 --- a/src/zarr/core/group.py +++ b/src/zarr/core/group.py @@ -516,7 +516,7 @@ async def require_array( self, name: str, *, - shape: ChunkCoords, + shape: ShapeLike, dtype: npt.DTypeLike = None, exact: bool = False, **kwargs: Any, diff --git a/tests/v3/package_with_entrypoint/__init__.py b/tests/v3/package_with_entrypoint/__init__.py index 352b9d570e..b818adf8ea 100644 --- a/tests/v3/package_with_entrypoint/__init__.py +++ b/tests/v3/package_with_entrypoint/__init__.py @@ -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 @@ -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( @@ -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): diff --git a/tests/v3/test_codecs/test_blosc.py b/tests/v3/test_codecs/test_blosc.py index 5de4c9fa99..4c569055b7 100644 --- a/tests/v3/test_codecs/test_blosc.py +++ b/tests/v3/test_codecs/test_blosc.py @@ -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: @@ -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: diff --git a/tests/v3/test_codecs/test_codecs.py b/tests/v3/test_codecs/test_codecs.py index f388fb1c1e..57103d17c2 100644 --- a/tests/v3/test_codecs/test_codecs.py +++ b/tests/v3/test_codecs/test_codecs.py @@ -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, @@ -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 @@ -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: @@ -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=" None: fill_value=1, ) - z2 = zarr.v2.create( + z2 = zarr.v2.creation.create( shape=data.shape, chunks=(10, 10), dtype=data.dtype, @@ -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, @@ -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") diff --git a/tests/v3/test_codecs/test_endian.py b/tests/v3/test_codecs/test_endian.py index f97d95d9b7..3c36c90b81 100644 --- a/tests/v3/test_codecs/test_endian.py +++ b/tests/v3/test_codecs/test_endian.py @@ -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 @@ -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 " None: """ 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( 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) @@ -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) @@ -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) @@ -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: diff --git a/tests/v3/test_codecs/test_transpose.py b/tests/v3/test_codecs/test_transpose.py index a24c650c5b..c42c56034a 100644 --- a/tests/v3/test_codecs/test_transpose.py +++ b/tests/v3/test_codecs/test_transpose.py @@ -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 @@ -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=" None: expect = a[selection] actual = z.get_basic_selection(selection) assert_array_equal(expect, actual) @@ -272,7 +272,7 @@ def test_get_basic_selection_1d(store: StorePath) -> None: z[selection] with pytest.raises(IndexError): - z.get_basic_selection([1, 0]) + z.get_basic_selection([1, 0]) # type: ignore[arg-type] basic_selections_2d = [ @@ -388,7 +388,9 @@ def test_fancy_indexing_fallback_on_get_setitem(store: StorePath) -> None: (([1, 0, 1]), [[3, 4, 5], [0, 1, 2], [3, 4, 5]]), ], ) -def test_orthogonal_indexing_fallback_on_getitem_2d(store: StorePath, index, expected_result): +def test_orthogonal_indexing_fallback_on_getitem_2d( + store: StorePath, index, expected_result +) -> None: """ Tests the orthogonal indexing fallback on __getitem__ for a 2D matrix. @@ -418,7 +420,9 @@ def test_orthogonal_indexing_fallback_on_getitem_2d(store: StorePath, index, exp ((slice(0, 2), [1, 2], slice(0, 2)), [[[3, 4], [6, 7]], [[12, 13], [15, 16]]]), ], ) -def test_orthogonal_indexing_fallback_on_getitem_3d(store: StorePath, index, expected_result): +def test_orthogonal_indexing_fallback_on_getitem_3d( + store: StorePath, index, expected_result +) -> None: """ Tests the orthogonal indexing fallback on __getitem__ for a 3D matrix. @@ -456,7 +460,9 @@ def test_orthogonal_indexing_fallback_on_getitem_3d(store: StorePath, index, exp (([0, 2], slice(None, None, 2)), [[1, 0, 1], [0, 0, 0], [1, 0, 1]]), ], ) -def test_orthogonal_indexing_fallback_on_setitem_2d(store: StorePath, index, expected_result): +def test_orthogonal_indexing_fallback_on_setitem_2d( + store: StorePath, index, expected_result +) -> None: """ Tests the orthogonal indexing fallback on __setitem__ for a 3D matrix. @@ -472,7 +478,7 @@ def test_orthogonal_indexing_fallback_on_setitem_2d(store: StorePath, index, exp np.testing.assert_array_equal(z[:], a, err_msg="Indexing disagrees with numpy") -def test_fancy_indexing_doesnt_mix_with_implicit_slicing(store: StorePath): +def test_fancy_indexing_doesnt_mix_with_implicit_slicing(store: StorePath) -> None: z2 = zarr_array_from_numpy_array(store, np.zeros((5, 5, 5))) with pytest.raises(IndexError): z2[[1, 2, 3], [1, 2, 3]] = 2 @@ -526,7 +532,7 @@ def test_set_basic_selection_0d( # arr_z[..., "foo", "bar"] = v[["foo", "bar"]] -def _test_get_orthogonal_selection(a, z, selection): +def _test_get_orthogonal_selection(a, z, selection) -> None: expect = oindex(a, selection) actual = z.get_orthogonal_selection(selection) assert_array_equal(expect, actual) @@ -535,7 +541,7 @@ def _test_get_orthogonal_selection(a, z, selection): # noinspection PyStatementEffect -def test_get_orthogonal_selection_1d_bool(store: StorePath): +def test_get_orthogonal_selection_1d_bool(store: StorePath) -> None: # setup a = np.arange(1050, dtype=int) z = zarr_array_from_numpy_array(store, a, chunk_shape=(100,)) @@ -556,7 +562,7 @@ def test_get_orthogonal_selection_1d_bool(store: StorePath): # noinspection PyStatementEffect -def test_get_orthogonal_selection_1d_int(store: StorePath): +def test_get_orthogonal_selection_1d_int(store: StorePath) -> None: # setup a = np.arange(1050, dtype=int) z = zarr_array_from_numpy_array(store, a, chunk_shape=(100,)) @@ -595,7 +601,7 @@ def test_get_orthogonal_selection_1d_int(store: StorePath): z.oindex[selection] -def _test_get_orthogonal_selection_2d(a, z, ix0, ix1): +def _test_get_orthogonal_selection_2d(a, z, ix0, ix1) -> None: selections = [ # index both axes with array (ix0, ix1), @@ -613,7 +619,7 @@ def _test_get_orthogonal_selection_2d(a, z, ix0, ix1): # noinspection PyStatementEffect -def test_get_orthogonal_selection_2d(store: StorePath): +def test_get_orthogonal_selection_2d(store: StorePath) -> None: # setup a = np.arange(10000, dtype=int).reshape(1000, 10) z = zarr_array_from_numpy_array(store, a, chunk_shape=(300, 3)) @@ -655,7 +661,7 @@ def test_get_orthogonal_selection_2d(store: StorePath): z.oindex[selection] -def _test_get_orthogonal_selection_3d(a, z, ix0, ix1, ix2): +def _test_get_orthogonal_selection_3d(a, z, ix0, ix1, ix2) -> None: selections = [ # single value (84, 42, 4), @@ -690,7 +696,7 @@ def _test_get_orthogonal_selection_3d(a, z, ix0, ix1, ix2): _test_get_orthogonal_selection(a, z, selection) -def test_get_orthogonal_selection_3d(store: StorePath): +def test_get_orthogonal_selection_3d(store: StorePath) -> None: # setup a = np.arange(100000, dtype=int).reshape(200, 50, 10) z = zarr_array_from_numpy_array(store, a, chunk_shape=(60, 20, 3)) @@ -719,7 +725,7 @@ def test_get_orthogonal_selection_3d(store: StorePath): _test_get_orthogonal_selection_3d(a, z, ix0, ix1, ix2) -def test_orthogonal_indexing_edge_cases(store: StorePath): +def test_orthogonal_indexing_edge_cases(store: StorePath) -> None: a = np.arange(6).reshape(1, 2, 3) z = zarr_array_from_numpy_array(store, a, chunk_shape=(1, 2, 3)) @@ -732,7 +738,7 @@ def test_orthogonal_indexing_edge_cases(store: StorePath): assert_array_equal(expect, actual) -def _test_set_orthogonal_selection(v, a, z, selection): +def _test_set_orthogonal_selection(v, a, z, selection) -> None: for value in 42, oindex(v, selection), oindex(v, selection).tolist(): if isinstance(value, list) and value == []: # skip these cases as cannot preserve all dimensions @@ -750,7 +756,7 @@ def _test_set_orthogonal_selection(v, a, z, selection): assert_array_equal(a, z[:]) -def test_set_orthogonal_selection_1d(store: StorePath): +def test_set_orthogonal_selection_1d(store: StorePath) -> None: # setup v = np.arange(1050, dtype=int) a = np.empty(v.shape, dtype=int) @@ -776,7 +782,7 @@ def test_set_orthogonal_selection_1d(store: StorePath): _test_set_orthogonal_selection(v, a, z, selection) -def _test_set_orthogonal_selection_2d(v, a, z, ix0, ix1): +def _test_set_orthogonal_selection_2d(v, a, z, ix0, ix1) -> None: selections = [ # index both axes with array (ix0, ix1), @@ -790,7 +796,7 @@ def _test_set_orthogonal_selection_2d(v, a, z, ix0, ix1): _test_set_orthogonal_selection(v, a, z, selection) -def test_set_orthogonal_selection_2d(store: StorePath): +def test_set_orthogonal_selection_2d(store: StorePath) -> None: # setup v = np.arange(10000, dtype=int).reshape(1000, 10) a = np.empty_like(v) @@ -819,7 +825,7 @@ def test_set_orthogonal_selection_2d(store: StorePath): _test_set_orthogonal_selection(v, a, z, selection) -def _test_set_orthogonal_selection_3d(v, a, z, ix0, ix1, ix2): +def _test_set_orthogonal_selection_3d(v, a, z, ix0, ix1, ix2) -> None: selections = ( # single value (84, 42, 4), @@ -845,7 +851,7 @@ def _test_set_orthogonal_selection_3d(v, a, z, ix0, ix1, ix2): _test_set_orthogonal_selection(v, a, z, selection) -def test_set_orthogonal_selection_3d(store: StorePath): +def test_set_orthogonal_selection_3d(store: StorePath) -> None: # setup v = np.arange(100000, dtype=int).reshape(200, 50, 10) a = np.empty_like(v) @@ -879,7 +885,7 @@ def test_set_orthogonal_selection_3d(store: StorePath): _test_set_orthogonal_selection_3d(v, a, z, ix0, ix1, ix2) -def test_orthogonal_indexing_fallback_on_get_setitem(store: StorePath): +def test_orthogonal_indexing_fallback_on_get_setitem(store: StorePath) -> None: z = zarr_array_from_numpy_array(store, np.zeros((20, 20))) z[[1, 2, 3], [1, 2, 3]] = 1 np.testing.assert_array_equal( @@ -900,7 +906,7 @@ def test_orthogonal_indexing_fallback_on_get_setitem(store: StorePath): np.testing.assert_array_equal(z2[:], [0, 1, 1, 1, 0]) -def _test_get_coordinate_selection(a, z, selection): +def _test_get_coordinate_selection(a, z, selection) -> None: expect = a[selection] actual = z.get_coordinate_selection(selection) assert_array_equal(expect, actual) @@ -924,7 +930,7 @@ def _test_get_coordinate_selection(a, z, selection): # noinspection PyStatementEffect -def test_get_coordinate_selection_1d(store: StorePath): +def test_get_coordinate_selection_1d(store: StorePath) -> None: # setup a = np.arange(1050, dtype=int) z = zarr_array_from_numpy_array(store, a, chunk_shape=(100,)) @@ -966,7 +972,7 @@ def test_get_coordinate_selection_1d(store: StorePath): z.vindex[selection] -def test_get_coordinate_selection_2d(store: StorePath): +def test_get_coordinate_selection_2d(store: StorePath) -> None: # setup a = np.arange(10000, dtype=int).reshape(1000, 10) z = zarr_array_from_numpy_array(store, a, chunk_shape=(300, 3)) @@ -1020,7 +1026,7 @@ def test_get_coordinate_selection_2d(store: StorePath): z.get_coordinate_selection(selection) -def _test_set_coordinate_selection(v, a, z, selection): +def _test_set_coordinate_selection(v, a, z, selection) -> None: for value in 42, v[selection], v[selection].tolist(): # setup expectation a[:] = 0 @@ -1035,7 +1041,7 @@ def _test_set_coordinate_selection(v, a, z, selection): assert_array_equal(a, z[:]) -def test_set_coordinate_selection_1d(store: StorePath): +def test_set_coordinate_selection_1d(store: StorePath) -> None: # setup v = np.arange(1050, dtype=int) a = np.empty(v.shape, dtype=v.dtype) @@ -1059,7 +1065,7 @@ def test_set_coordinate_selection_1d(store: StorePath): z.vindex[selection] = 42 -def test_set_coordinate_selection_2d(store: StorePath): +def test_set_coordinate_selection_2d(store: StorePath) -> None: # setup v = np.arange(10000, dtype=int).reshape(1000, 10) a = np.empty_like(v) @@ -1090,7 +1096,7 @@ def test_set_coordinate_selection_2d(store: StorePath): _test_set_coordinate_selection(v, a, z, (ix0, ix1)) -def _test_get_block_selection(a, z, selection, expected_idx): +def _test_get_block_selection(a, z, selection, expected_idx) -> None: expect = a[expected_idx] actual = z.get_block_selection(selection) assert_array_equal(expect, actual) @@ -1142,7 +1148,7 @@ def _test_get_block_selection(a, z, selection, expected_idx): ] -def test_get_block_selection_1d(store: StorePath): +def test_get_block_selection_1d(store: StorePath) -> None: # setup a = np.arange(1050, dtype=int) z = zarr_array_from_numpy_array(store, a, chunk_shape=(100,)) @@ -1195,7 +1201,7 @@ def test_get_block_selection_1d(store: StorePath): ] -def test_get_block_selection_2d(store: StorePath): +def test_get_block_selection_2d(store: StorePath) -> None: # setup a = np.arange(10000, dtype=int).reshape(1000, 10) z = zarr_array_from_numpy_array(store, a, chunk_shape=(300, 3)) @@ -1216,7 +1222,9 @@ def test_get_block_selection_2d(store: StorePath): z.get_block_selection(selection) -def _test_set_block_selection(v: np.ndarray, a: np.ndarray, z: zarr.Array, selection, expected_idx): +def _test_set_block_selection( + v: np.ndarray, a: np.ndarray, z: zarr.Array, selection, expected_idx +) -> None: for value in 42, v[expected_idx], v[expected_idx].tolist(): # setup expectation a[:] = 0 @@ -1231,7 +1239,7 @@ def _test_set_block_selection(v: np.ndarray, a: np.ndarray, z: zarr.Array, selec assert_array_equal(a, z[:]) -def test_set_block_selection_1d(store: StorePath): +def test_set_block_selection_1d(store: StorePath) -> None: # setup v = np.arange(1050, dtype=int) a = np.empty(v.shape, dtype=v.dtype) @@ -1249,7 +1257,7 @@ def test_set_block_selection_1d(store: StorePath): z.blocks[selection] = 42 -def test_set_block_selection_2d(store: StorePath): +def test_set_block_selection_2d(store: StorePath) -> None: # setup v = np.arange(10000, dtype=int).reshape(1000, 10) a = np.empty(v.shape, dtype=v.dtype) @@ -1271,7 +1279,7 @@ def test_set_block_selection_2d(store: StorePath): z.set_block_selection(selection, 42) -def _test_get_mask_selection(a, z, selection): +def _test_get_mask_selection(a, z, selection) -> None: expect = a[selection] actual = z.get_mask_selection(selection) assert_array_equal(expect, actual) @@ -1297,7 +1305,7 @@ def _test_get_mask_selection(a, z, selection): # noinspection PyStatementEffect -def test_get_mask_selection_1d(store: StorePath): +def test_get_mask_selection_1d(store: StorePath) -> None: # setup a = np.arange(1050, dtype=int) z = zarr_array_from_numpy_array(store, a, chunk_shape=(100,)) @@ -1322,7 +1330,7 @@ def test_get_mask_selection_1d(store: StorePath): # noinspection PyStatementEffect -def test_get_mask_selection_2d(store: StorePath): +def test_get_mask_selection_2d(store: StorePath) -> None: # setup a = np.arange(10000, dtype=int).reshape(1000, 10) z = zarr_array_from_numpy_array(store, a, chunk_shape=(300, 3)) @@ -1342,7 +1350,7 @@ def test_get_mask_selection_2d(store: StorePath): z.vindex[[True, False]] # wrong no. dimensions -def _test_set_mask_selection(v, a, z, selection): +def _test_set_mask_selection(v, a, z, selection) -> None: a[:] = 0 z[:] = 0 a[selection] = v[selection] @@ -1356,7 +1364,7 @@ def _test_set_mask_selection(v, a, z, selection): assert_array_equal(a, z[:]) -def test_set_mask_selection_1d(store: StorePath): +def test_set_mask_selection_1d(store: StorePath) -> None: # setup v = np.arange(1050, dtype=int) a = np.empty_like(v) @@ -1375,7 +1383,7 @@ def test_set_mask_selection_1d(store: StorePath): z.vindex[selection] = 42 -def test_set_mask_selection_2d(store: StorePath): +def test_set_mask_selection_2d(store: StorePath) -> None: # setup v = np.arange(10000, dtype=int).reshape(1000, 10) a = np.empty_like(v) @@ -1388,7 +1396,7 @@ def test_set_mask_selection_2d(store: StorePath): _test_set_mask_selection(v, a, z, ix) -def test_get_selection_out(store: StorePath): +def test_get_selection_out(store: StorePath) -> None: # basic selections a = np.arange(1050) z = zarr_array_from_numpy_array(store, a, chunk_shape=(100,)) @@ -1458,7 +1466,7 @@ def test_get_selection_out(store: StorePath): @pytest.mark.xfail(reason="fields are not supported in v3") -def test_get_selections_with_fields(store: StorePath): +def test_get_selections_with_fields(store: StorePath) -> None: a = [("aaa", 1, 4.2), ("bbb", 2, 8.4), ("ccc", 3, 12.6)] a = np.array(a, dtype=[("foo", "S3"), ("bar", "i4"), ("baz", "f8")]) z = zarr_array_from_numpy_array(store, a, chunk_shape=(2,)) @@ -1564,7 +1572,7 @@ def test_get_selections_with_fields(store: StorePath): @pytest.mark.xfail(reason="fields are not supported in v3") -def test_set_selections_with_fields(store: StorePath): +def test_set_selections_with_fields(store: StorePath) -> None: v = [("aaa", 1, 4.2), ("bbb", 2, 8.4), ("ccc", 3, 12.6)] v = np.array(v, dtype=[("foo", "S3"), ("bar", "i4"), ("baz", "f8")]) a = np.empty_like(v) @@ -1647,14 +1655,14 @@ def test_set_selections_with_fields(store: StorePath): assert_array_equal(a, z[:]) -def test_slice_selection_uints(): +def test_slice_selection_uints() -> None: arr = np.arange(24).reshape((4, 6)) idx = np.uint64(3) slice_sel = make_slice_selection((idx,)) assert arr[tuple(slice_sel)].shape == (1, 6) -def test_numpy_int_indexing(store: StorePath): +def test_numpy_int_indexing(store: StorePath) -> None: a = np.arange(1050) z = zarr_array_from_numpy_array(store, a, chunk_shape=(100,)) assert a[42] == z[42] @@ -1686,7 +1694,7 @@ def test_numpy_int_indexing(store: StorePath): ), ], ) -async def test_accessed_chunks(shape, chunks, ops): +async def test_accessed_chunks(shape, chunks, ops) -> None: # Test that only the required chunks are accessed during basic selection operations # shape: array shape # chunks: chunk size @@ -1759,7 +1767,7 @@ async def test_accessed_chunks(shape, chunks, ops): [[100, 200, 300], [4, 5, 6]], ], ) -def test_indexing_equals_numpy(store, selection): +def test_indexing_equals_numpy(store, selection) -> None: a = np.arange(10000, dtype=int).reshape(1000, 10) z = zarr_array_from_numpy_array(store, a, chunk_shape=(300, 3)) # note: in python 3.10 a[*selection] is not valid unpacking syntax @@ -1777,7 +1785,7 @@ def test_indexing_equals_numpy(store, selection): [np.full(1000, True), [True, False] * 5], ], ) -def test_orthogonal_bool_indexing_like_numpy_ix(store, selection): +def test_orthogonal_bool_indexing_like_numpy_ix(store, selection) -> None: a = np.arange(10000, dtype=int).reshape(1000, 10) z = zarr_array_from_numpy_array(store, a, chunk_shape=(300, 3)) expected = a[np.ix_(*selection)] diff --git a/tests/v3/test_store/test_memory.py b/tests/v3/test_store/test_memory.py index e64f93ad95..13aaa20bda 100644 --- a/tests/v3/test_store/test_memory.py +++ b/tests/v3/test_store/test_memory.py @@ -82,7 +82,7 @@ def test_list_prefix(self, store: GpuMemoryStore) -> None: assert True -def test_uses_dict(): +def test_uses_dict() -> None: store_dict = {} store = MemoryStore(store_dict) assert store._store_dict is store_dict diff --git a/tests/v3/test_store/test_remote.py b/tests/v3/test_store/test_remote.py index 7495bec8e1..e400857c45 100644 --- a/tests/v3/test_store/test_remote.py +++ b/tests/v3/test_store/test_remote.py @@ -48,7 +48,7 @@ def get_boto3_client() -> botocore.client.BaseClient: @pytest.fixture(autouse=True, scope="function") -def s3(s3_base) -> Generator[s3fs.S3FileSystem, None, None]: +def s3(s3_base: None) -> Generator[s3fs.S3FileSystem, None, None]: """ Quoting Martin Durant: pytest-asyncio creates a new event loop for each async test. diff --git a/tests/v3/test_store/test_stateful_store.py b/tests/v3/test_store/test_stateful_store.py index d062f9235f..1ecbd87cc1 100644 --- a/tests/v3/test_store/test_stateful_store.py +++ b/tests/v3/test_store/test_stateful_store.py @@ -9,6 +9,7 @@ precondition, rule, ) +from hypothesis.strategies import DataObject import zarr from zarr.abc.store import AccessMode, Store @@ -18,7 +19,7 @@ class SyncStoreWrapper(zarr.core.sync.SyncMixin): - def __init__(self, store: Store): + def __init__(self, store: Store) -> None: """Synchronous Store wrapper This class holds synchronous methods that map to async methods of Store classes. @@ -109,7 +110,7 @@ def __init__(self) -> None: self.prototype = default_buffer_prototype() @rule(key=paths, data=st.binary(min_size=0, max_size=100)) - def set(self, key: str, data: bytes) -> None: + def set(self, key: str, data: DataObject) -> None: note(f"(set) Setting {key!r} with {data}") assert not self.store.mode.readonly data_buf = cpu.Buffer.from_bytes(data) @@ -118,7 +119,7 @@ def set(self, key: str, data: bytes) -> None: @precondition(lambda self: len(self.model.keys()) > 0) @rule(key=paths, data=st.data()) - def get(self, key: str, data: bytes) -> None: + def get(self, key: str, data: DataObject) -> None: key = data.draw( st.sampled_from(sorted(self.model.keys())) ) # hypothesis wants to sample from sorted list @@ -128,14 +129,14 @@ def get(self, key: str, data: bytes) -> None: assert self.model[key].to_bytes() == (store_value.to_bytes()) @rule(key=paths, data=st.data()) - def get_invalid_keys(self, key: str, data: bytes) -> None: + def get_invalid_keys(self, key: str, data: DataObject) -> None: note("(get_invalid)") assume(key not in self.model.keys()) assert self.store.get(key, self.prototype) is None @precondition(lambda self: len(self.model.keys()) > 0) @rule(data=st.data()) - def get_partial_values(self, data: bytes) -> None: + def get_partial_values(self, data: DataObject) -> None: key_range = data.draw(key_ranges(keys=st.sampled_from(sorted(self.model.keys())))) note(f"(get partial) {key_range=}") obs_maybe = self.store.get_partial_values(key_range, self.prototype) @@ -162,7 +163,7 @@ def get_partial_values(self, data: bytes) -> None: @precondition(lambda self: len(self.model.keys()) > 0) @rule(data=st.data()) - def delete(self, data: bytes) -> None: + def delete(self, data: DataObject) -> None: key = data.draw(st.sampled_from(sorted(self.model.keys()))) note(f"(delete) Deleting {key=}")