Skip to content

Faster delitems #1524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions zarr/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1464,11 +1464,21 @@ def __delitem__(self, key):
def delitems(self, keys):
if self.mode == "r":
raise ReadOnlyError()
# only remove the keys that exist in the store
nkeys = [self._normalize_key(key) for key in keys if key in self]
# rm errors if you pass an empty collection
if len(nkeys) > 0:
self.map.delitems(nkeys)
try:
# First try to remove keys without checking if they exist. For high latency
# storage, this is much faster than first checking if they keys exist.
nkeys = [self._normalize_key(key) for key in keys]
# rm errors if you pass an empty collection
if len(nkeys) > 0:
self.map.delitems(nkeys)
except FileNotFoundError:
# FileNotFounderror will be raised when a storage backend interprets
# deleting a file that does not exist as an error (e.g., LocalFileSystem).
# In this case, we must first check if keys exist, then delete those keys.
nkeys = [self._normalize_key(key) for key in keys if key in self]
# rm errors if you pass an empty collection
if len(nkeys) > 0:
self.map.delitems(nkeys)

def __contains__(self, key):
key = self._normalize_key(key)
Expand Down