Skip to content
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

fix RemoteStore.empty #2343

Merged
merged 2 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion src/zarr/storage/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ async def clear(self) -> None:
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:
return type(self)(
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed this test fails without the above fix