Skip to content

Commit a9b68d8

Browse files
committed
fix: handle 0-length arrays
1 parent c40c5ff commit a9b68d8

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

src/zarr/core/chunk_grids.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ def normalize_chunks_1d(chunks: int | None | Iterable[int], span: int) -> tuple[
695695
if isinstance(chunks, int):
696696
if chunks <= 0:
697697
raise ValueError(f"Chunk size must be positive, got {chunks}")
698+
if span == 0:
699+
return (chunks,)
698700
n = ceildiv(span, chunks)
699701
return tuple(chunks for _ in range(n))
700702
else:

tests/test_chunk_grids.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ def test_guess_chunks(shape: tuple[int, ...], itemsize: int) -> None:
4545
# sentinel values
4646
(-1, (100,), ((100,),)),
4747
((30, -1, None), (100, 20, 10), ((30, 30, 30, 30), (20,), (10,))),
48+
# zero-length dimensions preserve the declared chunk size
49+
(10, (0,), ((10,),)),
50+
((5, 10), (0, 100), ((5,), (10,) * 10)),
51+
((5, 10), (20, 0), ((5, 5, 5, 5), (10,))),
4852
],
4953
)
5054
def test_normalize_chunks(

0 commit comments

Comments
 (0)