Skip to content

Commit

Permalink
Merge pull request #2343 from rabernat/ryan/fix-remote-store-exists
Browse files Browse the repository at this point in the history
fix RemoteStore.empty
  • Loading branch information
jhamman authored Oct 13, 2024
2 parents ad68a33 + 5ec909a commit 9bbfd88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/zarr/storage/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ async def empty(self) -> bool:

# TODO: it would be nice if we didn't have to list all keys here
# it should be possible to stop after the first key is discovered
return not await self.fs._ls(self.path)
try:
return not await self.fs._ls(self.path)
except FileNotFoundError:
return True

def with_mode(self, mode: AccessModeLiteral) -> Self:
# docstring inherited
Expand Down
7 changes: 7 additions & 0 deletions tests/v3/test_store/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,10 @@ def test_from_upath(self) -> None:
path = UPath(f"s3://{test_bucket_name}", endpoint_url=endpoint_url, anon=False)
result = RemoteStore.from_upath(path)
assert result.fs.endpoint_url == endpoint_url

async def test_empty_nonexistent_path(self, store_kwargs) -> None:
# regression test for https://github.com/zarr-developers/zarr-python/pull/2343
store_kwargs["mode"] = "w-"
store_kwargs["path"] += "/abc"
store = await self.store_cls.open(**store_kwargs)
assert await store.empty()

0 comments on commit 9bbfd88

Please sign in to comment.