|
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, |
|
91 | 94 | OrthogonalSelection, |
92 | 95 | Selection, |
93 | 96 | VIndex, |
94 | | - ceildiv, |
95 | 97 | check_fields, |
96 | 98 | check_no_multi_fields, |
97 | 99 | is_pure_fancy_indexing, |
@@ -1564,6 +1566,56 @@ async def getitem( |
1564 | 1566 | ) |
1565 | 1567 | return await self._get_selection(indexer, prototype=prototype) |
1566 | 1568 |
|
| 1569 | + async def get_orthogonal_selection( |
| 1570 | + self, |
| 1571 | + selection: OrthogonalSelection, |
| 1572 | + *, |
| 1573 | + out: NDBuffer | None = None, |
| 1574 | + fields: Fields | None = None, |
| 1575 | + prototype: BufferPrototype | None = None, |
| 1576 | + ) -> NDArrayLikeOrScalar: |
| 1577 | + if prototype is None: |
| 1578 | + prototype = default_buffer_prototype() |
| 1579 | + indexer = OrthogonalIndexer(selection, self.shape, self.metadata.chunk_grid) |
| 1580 | + return await self._get_selection( |
| 1581 | + indexer=indexer, out=out, fields=fields, prototype=prototype |
| 1582 | + ) |
| 1583 | + |
| 1584 | + async def get_mask_selection( |
| 1585 | + self, |
| 1586 | + mask: MaskSelection, |
| 1587 | + *, |
| 1588 | + out: NDBuffer | None = None, |
| 1589 | + fields: Fields | None = None, |
| 1590 | + prototype: BufferPrototype | None = None, |
| 1591 | + ) -> NDArrayLikeOrScalar: |
| 1592 | + if prototype is None: |
| 1593 | + prototype = default_buffer_prototype() |
| 1594 | + indexer = MaskIndexer(mask, self.shape, self.metadata.chunk_grid) |
| 1595 | + return await self._get_selection( |
| 1596 | + indexer=indexer, out=out, fields=fields, prototype=prototype |
| 1597 | + ) |
| 1598 | + |
| 1599 | + async def get_coordinate_selection( |
| 1600 | + self, |
| 1601 | + selection: CoordinateSelection, |
| 1602 | + *, |
| 1603 | + out: NDBuffer | None = None, |
| 1604 | + fields: Fields | None = None, |
| 1605 | + prototype: BufferPrototype | None = None, |
| 1606 | + ) -> NDArrayLikeOrScalar: |
| 1607 | + if prototype is None: |
| 1608 | + prototype = default_buffer_prototype() |
| 1609 | + indexer = CoordinateIndexer(selection, self.shape, self.metadata.chunk_grid) |
| 1610 | + out_array = await self._get_selection( |
| 1611 | + indexer=indexer, out=out, fields=fields, prototype=prototype |
| 1612 | + ) |
| 1613 | + |
| 1614 | + if hasattr(out_array, "shape"): |
| 1615 | + # restore shape |
| 1616 | + out_array = np.array(out_array).reshape(indexer.sel_shape) |
| 1617 | + return out_array |
| 1618 | + |
1567 | 1619 | async def _save_metadata(self, metadata: ArrayMetadata, ensure_parents: bool = False) -> None: |
1568 | 1620 | """ |
1569 | 1621 | Asynchronously save the array metadata. |
@@ -1695,6 +1747,19 @@ async def setitem( |
1695 | 1747 | ) |
1696 | 1748 | return await self._set_selection(indexer, value, prototype=prototype) |
1697 | 1749 |
|
| 1750 | + @property |
| 1751 | + def oindex(self) -> AsyncOIndex[T_ArrayMetadata]: |
| 1752 | + """Shortcut for orthogonal (outer) indexing, see :func:`get_orthogonal_selection` and |
| 1753 | + :func:`set_orthogonal_selection` for documentation and examples.""" |
| 1754 | + return AsyncOIndex(self) |
| 1755 | + |
| 1756 | + @property |
| 1757 | + def vindex(self) -> AsyncVIndex[T_ArrayMetadata]: |
| 1758 | + """Shortcut for vectorized (inner) indexing, see :func:`get_coordinate_selection`, |
| 1759 | + :func:`set_coordinate_selection`, :func:`get_mask_selection` and |
| 1760 | + :func:`set_mask_selection` for documentation and examples.""" |
| 1761 | + return AsyncVIndex(self) |
| 1762 | + |
1698 | 1763 | async def resize(self, new_shape: ShapeLike, delete_outside_chunks: bool = True) -> None: |
1699 | 1764 | """ |
1700 | 1765 | Asynchronously resize the array to a new shape. |
|
0 commit comments