Skip to content

Commit 1da36f4

Browse files
committed
normalize in codec_pipeline
1 parent edbba37 commit 1da36f4

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/zarr/core/codec_pipeline.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@
3535
U = TypeVar("U")
3636

3737

38+
def normalize_slices(
39+
idxr: tuple[int | slice, ...], shape: tuple[int, ...]
40+
) -> tuple[int | slice, ...]:
41+
# replace slice objects with stop==None with size
42+
out = []
43+
for i, size in zip(idxr, shape, strict=False):
44+
if not isinstance(i, slice):
45+
out.append(i)
46+
continue
47+
if i.step not in [1, None]:
48+
out.append(i)
49+
out.append(slice(i.start, i.stop if i.stop is not None else size, i.step))
50+
return tuple(out)
51+
52+
3853
def _unzip2(iterable: Iterable[tuple[T, U]]) -> tuple[list[T], list[U]]:
3954
out0: list[T] = []
4055
out1: list[U] = []
@@ -322,7 +337,9 @@ def _merge_chunk_array(
322337
for idx in range(chunk_spec.ndim)
323338
)
324339
chunk_value = chunk_value[item]
325-
chunk_array[chunk_selection] = chunk_value
340+
341+
normalized_selection = normalize_slices(chunk_selection, chunk_array.shape)
342+
chunk_array[normalized_selection] = chunk_value
326343
return chunk_array
327344

328345
async def write_batch(

0 commit comments

Comments
 (0)