diff --git a/zarr/storage.py b/zarr/storage.py index b36f804ebd..d6a9682f78 100644 --- a/zarr/storage.py +++ b/zarr/storage.py @@ -1417,9 +1417,14 @@ def getitems( ) -> Mapping[str, Any]: keys_transformed = [self._normalize_key(key) for key in keys] - results = self.map.getitems(keys_transformed, on_error="omit") + results = self.map.getitems(keys_transformed, on_error="return") # 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. + for k, v in results.copy().items(): + if isinstance(v, self.exceptions): + results.pop(k) + elif isinstance(v, Exception): + raise v return {keys[keys_transformed.index(rk)]: rv for rk, rv in results.items()} def __getitem__(self, key): diff --git a/zarr/tests/test_storage.py b/zarr/tests/test_storage.py index e87716fa47..76e3066045 100644 --- a/zarr/tests/test_storage.py +++ b/zarr/tests/test_storage.py @@ -1341,6 +1341,22 @@ def test_s3_complex(self): ) assert (a[:] == -np.ones((8, 8, 8))).all() + def test_exceptions(self): + import fsspec + m = fsspec.filesystem("memory") + g = zarr.open_group("memory://test/out.zarr", mode='w') + arr = g.create_dataset("data", data=[1, 2, 3, 4], + dtype="i4", compression=None, chunks=[2]) + m.store["/test/out.zarr/data/0"] = None + del m.store["/test/out.zarr/data/1"] + assert g.store.getitems(["data/1"]) == {} # not found + with pytest.raises(Exception): + # None is bad data, as opposed to missing + g.store.getitems(["data/0", "data/1"]) + with pytest.raises(Exception): + # None is bad data, as opposed to missing + arr[:] + @pytest.mark.skipif(have_fsspec is False, reason="needs fsspec") class TestFSStoreWithKeySeparator(StoreTests):