diff --git a/src/zarr/core/chunk_grids.py b/src/zarr/core/chunk_grids.py index afecc6824f..ea050e39ef 100644 --- a/src/zarr/core/chunk_grids.py +++ b/src/zarr/core/chunk_grids.py @@ -138,6 +138,9 @@ def normalize_chunks(chunks: Any, shape: tuple[int, ...], typesize: int) -> tupl s if c == -1 or c is None else int(c) for s, c in zip(shape, chunks, strict=False) ) + if not all(isinstance(c, numbers.Integral) for c in chunks): + raise TypeError("non integer value in chunks") + return tuple(int(c) for c in chunks) diff --git a/tests/test_api.py b/tests/test_api.py index c7fc88241f..11977e8e32 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -47,6 +47,14 @@ def test_create_array(memory_store: Store) -> None: assert z.shape == (400,) assert z.chunks == (40,) + # create array with float shape + with pytest.raises(TypeError): + z = create(shape=(400.5, 100), store=store, overwrite=True) + + # create array with float chunk shape + with pytest.raises(TypeError): + z = create(shape=(400, 100), chunks=(16, 16.5), store=store, overwrite=True) + @pytest.mark.parametrize("path", ["foo", "/", "/foo", "///foo/bar"]) @pytest.mark.parametrize("node_type", ["array", "group"])