Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse chunk shape to check for float values #2535

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/zarr/core/chunk_grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
8 changes: 8 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
Loading