|
61 | 61 | ZarrFormat, |
62 | 62 | _default_zarr_format, |
63 | 63 | _warn_order_kwarg, |
| 64 | + ceildiv, |
64 | 65 | concurrent_map, |
65 | 66 | parse_shapelike, |
66 | 67 | product, |
|
76 | 77 | ) |
77 | 78 | from zarr.core.dtype.common import HasEndianness, HasItemSize, HasObjectCodec |
78 | 79 | from zarr.core.indexing import ( |
| 80 | + AsyncOIndex, |
| 81 | + AsyncVIndex, |
79 | 82 | BasicIndexer, |
80 | 83 | BasicSelection, |
81 | 84 | BlockIndex, |
|
92 | 95 | Selection, |
93 | 96 | VIndex, |
94 | 97 | _iter_grid, |
95 | | - ceildiv, |
96 | 98 | check_fields, |
97 | 99 | check_no_multi_fields, |
98 | 100 | is_pure_fancy_indexing, |
@@ -1425,6 +1427,56 @@ async def getitem( |
1425 | 1427 | ) |
1426 | 1428 | return await self._get_selection(indexer, prototype=prototype) |
1427 | 1429 |
|
| 1430 | + async def get_orthogonal_selection( |
| 1431 | + self, |
| 1432 | + selection: OrthogonalSelection, |
| 1433 | + *, |
| 1434 | + out: NDBuffer | None = None, |
| 1435 | + fields: Fields | None = None, |
| 1436 | + prototype: BufferPrototype | None = None, |
| 1437 | + ) -> NDArrayLikeOrScalar: |
| 1438 | + if prototype is None: |
| 1439 | + prototype = default_buffer_prototype() |
| 1440 | + indexer = OrthogonalIndexer(selection, self.shape, self.metadata.chunk_grid) |
| 1441 | + return await self._get_selection( |
| 1442 | + indexer=indexer, out=out, fields=fields, prototype=prototype |
| 1443 | + ) |
| 1444 | + |
| 1445 | + async def get_mask_selection( |
| 1446 | + self, |
| 1447 | + mask: MaskSelection, |
| 1448 | + *, |
| 1449 | + out: NDBuffer | None = None, |
| 1450 | + fields: Fields | None = None, |
| 1451 | + prototype: BufferPrototype | None = None, |
| 1452 | + ) -> NDArrayLikeOrScalar: |
| 1453 | + if prototype is None: |
| 1454 | + prototype = default_buffer_prototype() |
| 1455 | + indexer = MaskIndexer(mask, self.shape, self.metadata.chunk_grid) |
| 1456 | + return await self._get_selection( |
| 1457 | + indexer=indexer, out=out, fields=fields, prototype=prototype |
| 1458 | + ) |
| 1459 | + |
| 1460 | + async def get_coordinate_selection( |
| 1461 | + self, |
| 1462 | + selection: CoordinateSelection, |
| 1463 | + *, |
| 1464 | + out: NDBuffer | None = None, |
| 1465 | + fields: Fields | None = None, |
| 1466 | + prototype: BufferPrototype | None = None, |
| 1467 | + ) -> NDArrayLikeOrScalar: |
| 1468 | + if prototype is None: |
| 1469 | + prototype = default_buffer_prototype() |
| 1470 | + indexer = CoordinateIndexer(selection, self.shape, self.metadata.chunk_grid) |
| 1471 | + out_array = await self._get_selection( |
| 1472 | + indexer=indexer, out=out, fields=fields, prototype=prototype |
| 1473 | + ) |
| 1474 | + |
| 1475 | + if hasattr(out_array, "shape"): |
| 1476 | + # restore shape |
| 1477 | + out_array = np.array(out_array).reshape(indexer.sel_shape) |
| 1478 | + return out_array |
| 1479 | + |
1428 | 1480 | async def _save_metadata(self, metadata: ArrayMetadata, ensure_parents: bool = False) -> None: |
1429 | 1481 | """ |
1430 | 1482 | Asynchronously save the array metadata. |
@@ -1556,6 +1608,19 @@ async def setitem( |
1556 | 1608 | ) |
1557 | 1609 | return await self._set_selection(indexer, value, prototype=prototype) |
1558 | 1610 |
|
| 1611 | + @property |
| 1612 | + def oindex(self) -> AsyncOIndex[T_ArrayMetadata]: |
| 1613 | + """Shortcut for orthogonal (outer) indexing, see :func:`get_orthogonal_selection` and |
| 1614 | + :func:`set_orthogonal_selection` for documentation and examples.""" |
| 1615 | + return AsyncOIndex(self) |
| 1616 | + |
| 1617 | + @property |
| 1618 | + def vindex(self) -> AsyncVIndex[T_ArrayMetadata]: |
| 1619 | + """Shortcut for vectorized (inner) indexing, see :func:`get_coordinate_selection`, |
| 1620 | + :func:`set_coordinate_selection`, :func:`get_mask_selection` and |
| 1621 | + :func:`set_mask_selection` for documentation and examples.""" |
| 1622 | + return AsyncVIndex(self) |
| 1623 | + |
1559 | 1624 | async def resize(self, new_shape: ShapeLike, delete_outside_chunks: bool = True) -> None: |
1560 | 1625 | """ |
1561 | 1626 | Asynchronously resize the array to a new shape. |
|
0 commit comments