Skip to content

Commit

Permalink
Handle zero-length slices in index function (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwhite authored Feb 29, 2024
1 parent d47b6c1 commit fda2f1e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cubed/tests/test_array_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def test_negative(spec, executor):
slice(None),
slice(10),
slice(3, None),
slice(3, 3),
slice(3, 10),
(slice(10), None), # add a new dimension
],
Expand All @@ -208,11 +209,12 @@ def test_index_1d(spec, ind):
[
(2, 3),
(None, 2, 3), # add a new dimension
(slice(None), slice(2, 2)),
(slice(None), slice(2, 4)),
(slice(3), slice(2, None)),
(slice(1, None), slice(4)),
(slice(1, 1), slice(None)),
(slice(1, 3), slice(None)),
(slice(None), slice(2, 4)),
(None, slice(None), slice(2, 4)), # add a new dimension
(slice(None), None, slice(2, 4)), # add a new dimension
(slice(None), slice(2, 4), None), # add a new dimension
Expand Down
1 change: 1 addition & 0 deletions cubed/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_block_id_to_offset():

def test_to_chunksize():
assert to_chunksize(((3, 3, 3, 1),)) == (3,)
assert to_chunksize(((0,),)) == (1,) # Zarr doesn't support zero-length chunks
with pytest.raises(ValueError):
to_chunksize(((3, 2, 3, 3, 1),))

Expand Down
2 changes: 1 addition & 1 deletion cubed/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def to_chunksize(chunkset: T_RectangularChunks) -> T_RegularChunks:
if not _check_regular_chunks(chunkset):
raise ValueError(f"Array must have regular chunks, but found chunks={chunkset}")

return tuple(c[0] for c in chunkset)
return tuple(max(c[0], 1) for c in chunkset)


@dataclass
Expand Down

0 comments on commit fda2f1e

Please sign in to comment.