Skip to content

Commit 02e4c6f

Browse files
committed
polish(zarr-indexing): re-review minors — step-zero ValueError, kw-only Partition, strides docs
- slice step zero now raises ValueError, matching NumPy in the wrapper's positional dialect (was IndexError) - Partition is keyword-only: box was inserted mid-field-list, so positional construction would silently misbind - strides() documents the empty-box case (bounding_box None, strides still defined) Assisted-by: ClaudeCode:claude-fable-5
1 parent 7266a45 commit 02e4c6f

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎packages/zarr-indexing/src/zarr_indexing/boundary.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _normalize_slice(sel: slice, size: int, axis: int) -> tuple[int, int, int]:
9393
raise IndexError(f"slice step must be an integer; got {sel.step!r}")
9494
step = 1 if sel.step is None else int(sel.step)
9595
if step == 0:
96-
raise IndexError(f"slice step cannot be zero (axis {axis})")
96+
raise ValueError(f"slice step cannot be zero (axis {axis})") # ValueError: NumPy parity
9797
start, stop, step = sel.indices(size)
9898
stop = max(stop, start) if step > 0 else min(stop, start)
9999
return start, stop, step

‎packages/zarr-indexing/src/zarr_indexing/lazy_array.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def _covers_whole_part(local_transform: IndexTransform, part_shape: tuple[int, .
538538
return True
539539

540540

541-
@dataclass(frozen=True)
541+
@dataclass(frozen=True, kw_only=True)
542542
class Partition:
543543
"""One box of a `LazyArray`'s partitioning, as it falls through the view.
544544
@@ -838,7 +838,11 @@ def strides(self) -> tuple[int, ...] | None:
838838
tuple of int, or None
839839
One positive stride per storage dimension, or `None` when
840840
[`is_box`][zarr_indexing.lazy_array.LazyArray.is_box] is false: a
841-
query's coordinates are a lookup table and have no step.
841+
query's coordinates are a lookup table and have no step. An
842+
**empty** box still reports its strides even though
843+
[`bounding_box`][zarr_indexing.lazy_array.LazyArray.bounding_box]
844+
returns `None` — the step is a property of the selection's shape,
845+
not of the (empty) region it touches.
842846
843847
Notes
844848
-----

‎packages/zarr-indexing/tests/test_lazy_array.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ def test_a_reversed_view_is_re_based_to_origin_zero() -> None:
11731173

11741174

11751175
def test_zero_step_is_rejected() -> None:
1176-
with pytest.raises(IndexError, match="step cannot be zero"):
1176+
with pytest.raises(ValueError, match="step cannot be zero"):
11771177
make_source("numpy-whole").lazy[::0]
11781178

11791179

0 commit comments

Comments
 (0)