|
2 | 2 | import os |
3 | 3 | from collections.abc import MutableMapping |
4 | 4 | from string import ascii_letters, digits |
5 | | -from typing import Any, List, Mapping, Optional, Union |
| 5 | +from typing import Any, Iterable, List, Mapping, Optional, Union |
| 6 | + |
| 7 | +from numcodecs.ndarray_like import NDArrayLike |
6 | 8 |
|
7 | 9 | from zarr.meta import Metadata2, Metadata3 |
8 | 10 | from zarr.util import normalize_storage_path |
@@ -129,6 +131,43 @@ def _ensure_store(store: Any): |
129 | 131 | f"wrap it in Zarr.storage.KVStore. Got {store}" |
130 | 132 | ) |
131 | 133 |
|
| 134 | + def getitems( |
| 135 | + self, keys: Iterable[str], meta_array: NDArrayLike, *, on_error: str = "omit" |
| 136 | + ) -> Mapping[str, Any]: |
| 137 | + """Retrieve data from multiple keys. |
| 138 | +
|
| 139 | + Parameters |
| 140 | + ---------- |
| 141 | + keys : Iterable[str] |
| 142 | + The keys to retrieve |
| 143 | + meta_array : array-like |
| 144 | + An array instance to use for determining the output type. For now, this is |
| 145 | + only a hint and can be ignore by the implementation, in which case the type |
| 146 | + of the output is the same as calling __getitem__() for each key in keys. |
| 147 | + on_error : str, optional |
| 148 | + The policy on how to handle exceptions when retrieving keys. For now, the |
| 149 | + only supported policy is "omit", which means that failing keys are omitted |
| 150 | + from the returned result. |
| 151 | +
|
| 152 | + Returns |
| 153 | + ------- |
| 154 | + Mapping |
| 155 | + A collection mapping the input keys to their results. |
| 156 | +
|
| 157 | + Developer Notes |
| 158 | + --------------- |
| 159 | + This default implementation use __getitem__() to read each key sequential and |
| 160 | + ignores the meta_array argument. Overwrite this method to implement concurrent |
| 161 | + reads of multiple keys and/or to utilize the meta_array argument. |
| 162 | + """ |
| 163 | + |
| 164 | + # Please overwrite `getitems` to support non-default values of `on_error` |
| 165 | + if on_error != "omit": |
| 166 | + raise ValueError(f"{self.__class__} doesn't support on_error='{on_error}'") |
| 167 | + |
| 168 | + # Please overwrite `getitems` to support non-default values of `meta_array` |
| 169 | + return {k: self[k] for k in keys if k in self} |
| 170 | + |
132 | 171 |
|
133 | 172 | class Store(BaseStore): |
134 | 173 | """Abstract store class used by implementations following the Zarr v2 spec. |
|
0 commit comments