Skip to content

Commit 9bbfd88

Browse files
authored
Merge pull request #2343 from rabernat/ryan/fix-remote-store-exists
fix RemoteStore.empty
2 parents ad68a33 + 5ec909a commit 9bbfd88

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/zarr/storage/remote.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ async def empty(self) -> bool:
148148

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

153156
def with_mode(self, mode: AccessModeLiteral) -> Self:
154157
# docstring inherited

tests/v3/test_store/test_remote.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,10 @@ def test_from_upath(self) -> None:
186186
path = UPath(f"s3://{test_bucket_name}", endpoint_url=endpoint_url, anon=False)
187187
result = RemoteStore.from_upath(path)
188188
assert result.fs.endpoint_url == endpoint_url
189+
190+
async def test_empty_nonexistent_path(self, store_kwargs) -> None:
191+
# regression test for https://github.com/zarr-developers/zarr-python/pull/2343
192+
store_kwargs["mode"] = "w-"
193+
store_kwargs["path"] += "/abc"
194+
store = await self.store_cls.open(**store_kwargs)
195+
assert await store.empty()

0 commit comments

Comments
 (0)