|
35 | 35 | U = TypeVar("U") |
36 | 36 |
|
37 | 37 |
|
| 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] or i.start not in [0, None]: |
| 48 | + out.append(i) |
| 49 | + continue |
| 50 | + out.append(slice(i.start, i.stop if i.stop is not None else size, i.step)) |
| 51 | + return tuple(out) |
| 52 | + |
| 53 | + |
38 | 54 | def _unzip2(iterable: Iterable[tuple[T, U]]) -> tuple[list[T], list[U]]: |
39 | 55 | out0: list[T] = [] |
40 | 56 | out1: list[U] = [] |
@@ -279,7 +295,10 @@ async def read_batch( |
279 | 295 | chunk_array_batch, batch_info, strict=False |
280 | 296 | ): |
281 | 297 | if chunk_array is not None: |
282 | | - tmp = chunk_array[chunk_selection] |
| 298 | + normalized_selection = normalize_slices( |
| 299 | + chunk_selection, out[out_selection].shape |
| 300 | + ) |
| 301 | + tmp = chunk_array[normalized_selection] |
283 | 302 | if drop_axes != (): |
284 | 303 | tmp = tmp.squeeze(axis=drop_axes) |
285 | 304 | out[out_selection] = tmp |
@@ -322,7 +341,9 @@ def _merge_chunk_array( |
322 | 341 | for idx in range(chunk_spec.ndim) |
323 | 342 | ) |
324 | 343 | chunk_value = chunk_value[item] |
325 | | - chunk_array[chunk_selection] = chunk_value |
| 344 | + |
| 345 | + normalized_selection = normalize_slices(chunk_selection, chunk_value.shape) |
| 346 | + chunk_array[normalized_selection] = chunk_value |
326 | 347 | return chunk_array |
327 | 348 |
|
328 | 349 | async def write_batch( |
|
0 commit comments