Skip to content

Commit 1134be0

Browse files
committed
Warn user when shape or chunks contains non-integer values like floats
1 parent 2ab280a commit 1134be0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

zarr/util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Iterable,
1919
cast,
2020
)
21+
import warnings
2122

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

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

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

182+
if not all(isinstance(c, numbers.Integral) for c in chunks):
183+
warnings.warn("chunks contains non-integer value(s)", UserWarning, stacklevel=2)
184+
179185
chunks = tuple(int(c) for c in chunks)
180186
return chunks
181187

0 commit comments

Comments
 (0)