Skip to content

Commit

Permalink
Removed the on_error argument
Browse files Browse the repository at this point in the history
  • Loading branch information
madsbk committed Sep 13, 2022
1 parent f05ee3a commit 0eed377
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
20 changes: 2 additions & 18 deletions zarr/_storage/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ def _ensure_store(store: Any):
f"wrap it in Zarr.storage.KVStore. Got {store}"
)

def getitems(
self, keys: Iterable[str], meta_array: NDArrayLike, *, on_error: str = "omit"
) -> Mapping[str, Any]:
def getitems(self, keys: Iterable[str], meta_array: NDArrayLike) -> Mapping[str, Any]:
"""Retrieve data from multiple keys.
Parameters
Expand All @@ -144,10 +142,6 @@ def getitems(
An array instance to use for determining the output type. For now, this is
only a hint and can be ignore by the implementation, in which case the type
of the output is the same as calling __getitem__() for each key in keys.
on_error : str, optional
The policy on how to handle exceptions when retrieving keys. For now, the
only supported policy is "omit", which means that failing keys are omitted
from the returned result.
Returns
-------
Expand All @@ -161,17 +155,7 @@ def getitems(
reads of multiple keys and/or to utilize the meta_array argument.
"""

# Please overwrite `getitems` to support non-default values of `on_error`
if on_error != "omit":
raise ValueError(f"{self.__class__} doesn't support on_error='{on_error}'")

ret = {}
for k in keys:
try:
ret[k] = self[k]
except Exception:
pass # Omit keys that fails
return ret
return {k: self[k] for k in keys if k in self}


class Store(BaseStore):
Expand Down
7 changes: 2 additions & 5 deletions zarr/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,14 +1365,11 @@ def _normalize_key(self, key):
return key.lower() if self.normalize_keys else key

def getitems(
self, keys: Iterable[str], meta_array: NDArrayLike, *, on_error: str = "omit"
self, keys: Iterable[str], meta_array: NDArrayLike
) -> Mapping[str, Any]:

if on_error != "omit":
raise ValueError(f"{self.__class__} doesn't support on_error='{on_error}'")

keys_transformed = [self._normalize_key(key) for key in keys]
results = self.map.getitems(keys_transformed, on_error=on_error)
results = self.map.getitems(keys_transformed, on_error="omit")
# The function calling this method may not recognize the transformed keys
# So we send the values returned by self.map.getitems back into the original key space.
return {keys[keys_transformed.index(rk)]: rv for rk, rv in results.items()}
Expand Down

0 comments on commit 0eed377

Please sign in to comment.