Skip to content

Commit

Permalink
Warn user when shape or chunks contains non-integer values like floats
Browse files Browse the repository at this point in the history
  • Loading branch information
faymanns committed Dec 20, 2024
1 parent 2ab280a commit 1134be0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions zarr/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Iterable,
cast,
)
import warnings

import numpy as np
from asciitree import BoxStyle, LeftAligned
Expand Down Expand Up @@ -88,6 +89,8 @@ def normalize_shape(shape: Union[int, Tuple[int, ...], None]) -> Tuple[int, ...]

# normalize
shape = cast(Tuple[int, ...], shape)
if not all(isinstance(s, numbers.Integral) for s in shape):
warnings.warn("shape contains non-integer value(s)", UserWarning, stacklevel=2)
shape = tuple(int(s) for s in shape)
return shape

Expand Down Expand Up @@ -176,6 +179,9 @@ def normalize_chunks(chunks: Any, shape: Tuple[int, ...], typesize: int) -> Tupl
if -1 in chunks or None in chunks:
chunks = tuple(s if c == -1 or c is None else int(c) for s, c in zip(shape, chunks))

if not all(isinstance(c, numbers.Integral) for c in chunks):
warnings.warn("chunks contains non-integer value(s)", UserWarning, stacklevel=2)

chunks = tuple(int(c) for c in chunks)
return chunks

Expand Down

0 comments on commit 1134be0

Please sign in to comment.