Skip to content

Commit fd688c4

Browse files
faymannsjhamman
andauthored
Parse chunk shape to check for float values (#2535)
* Test that shapes and chunk shapes containing floats raise a TypeError * Parse chunk shape * Move check for floats from create to normalize_chunks --------- Co-authored-by: Joe Hamman <joe@earthmover.io>
1 parent 2fe12a7 commit fd688c4

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/zarr/core/chunk_grids.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ def normalize_chunks(chunks: Any, shape: tuple[int, ...], typesize: int) -> tupl
138138
s if c == -1 or c is None else int(c) for s, c in zip(shape, chunks, strict=False)
139139
)
140140

141+
if not all(isinstance(c, numbers.Integral) for c in chunks):
142+
raise TypeError("non integer value in chunks")
143+
141144
return tuple(int(c) for c in chunks)
142145

143146

tests/test_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ def test_create_array(memory_store: Store) -> None:
4747
assert z.shape == (400,)
4848
assert z.chunks == (40,)
4949

50+
# create array with float shape
51+
with pytest.raises(TypeError):
52+
z = create(shape=(400.5, 100), store=store, overwrite=True)
53+
54+
# create array with float chunk shape
55+
with pytest.raises(TypeError):
56+
z = create(shape=(400, 100), chunks=(16, 16.5), store=store, overwrite=True)
57+
5058

5159
@pytest.mark.parametrize("path", ["foo", "/", "/foo", "///foo/bar"])
5260
@pytest.mark.parametrize("node_type", ["array", "group"])

0 commit comments

Comments
 (0)