Skip to content

Commit 44f20ff

Browse files
committed
is_empty
1 parent f9dbd5b commit 44f20ff

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

src/zarr/abc/store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async def _ensure_open(self) -> None:
8282
if not self._is_open:
8383
await self._open()
8484

85-
async def empty_dir(self, prefix: str) -> bool:
85+
async def is_empty(self, prefix: str) -> bool:
8686
"""
8787
Check if the directory is empty.
8888

src/zarr/storage/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async def open(
8383

8484
match mode:
8585
case "w-":
86-
if not await self.empty_dir():
86+
if not await self.is_empty():
8787
msg = (
8888
f"{self} is not empty, but `mode` is set to 'w-'."
8989
"Either remove the existing objects in storage,"
@@ -187,7 +187,7 @@ async def exists(self) -> bool:
187187
"""
188188
return await self.store.exists(self.path)
189189

190-
async def empty_dir(self) -> bool:
190+
async def is_empty(self) -> bool:
191191
"""
192192
Check if any keys exist in the store with the given prefix.
193193
@@ -196,7 +196,7 @@ async def empty_dir(self) -> bool:
196196
bool
197197
True if no keys exist in the store with the given prefix, False otherwise.
198198
"""
199-
return await self.store.empty_dir(self.path)
199+
return await self.store.is_empty(self.path)
200200

201201
def __truediv__(self, other: str) -> StorePath:
202202
"""Combine this store path with another path"""

src/zarr/storage/logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ async def _ensure_open(self) -> None:
135135
with self.log():
136136
return await self._store._ensure_open()
137137

138-
async def empty_dir(self, prefix: str = "") -> bool:
138+
async def is_empty(self, prefix: str = "") -> bool:
139139
# docstring inherited
140140
with self.log():
141-
return await self._store.empty_dir(prefix=prefix)
141+
return await self._store.is_empty(prefix=prefix)
142142

143143
async def clear(self) -> None:
144144
# docstring inherited

src/zarr/testing/store.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,23 +230,23 @@ async def test_delete_dir(self, store: S) -> None:
230230
assert not await store.exists("foo/zarr.json")
231231
assert not await store.exists("foo/c/0")
232232

233-
async def test_empty_dir(self, store: S) -> None:
234-
assert await store.empty_dir("")
233+
async def test_is_empty(self, store: S) -> None:
234+
assert await store.is_empty("")
235235
await self.set(
236236
store, "foo/bar", self.buffer_cls.from_bytes(bytes("something", encoding="utf-8"))
237237
)
238-
assert not await store.empty_dir("")
239-
assert await store.empty_dir("fo")
240-
assert not await store.empty_dir("foo/")
241-
assert not await store.empty_dir("foo")
242-
assert await store.empty_dir("spam/")
238+
assert not await store.is_empty("")
239+
assert await store.is_empty("fo")
240+
assert not await store.is_empty("foo/")
241+
assert not await store.is_empty("foo")
242+
assert await store.is_empty("spam/")
243243

244244
async def test_clear(self, store: S) -> None:
245245
await self.set(
246246
store, "key", self.buffer_cls.from_bytes(bytes("something", encoding="utf-8"))
247247
)
248248
await store.clear()
249-
assert await store.empty_dir("")
249+
assert await store.is_empty("")
250250

251251
async def test_list(self, store: S) -> None:
252252
assert await _collect_aiterator(store.list()) == ()

tests/test_store/test_local.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ def test_store_supports_listing(self, store: LocalStore) -> None:
4343
assert store.supports_listing
4444

4545
async def test_empty_with_empty_subdir(self, store: LocalStore) -> None:
46-
assert await store.empty_dir("")
46+
assert await store.is_empty("")
4747
(store.root / "foo/bar").mkdir(parents=True)
48-
assert await store.empty_dir("")
48+
assert await store.is_empty("")
4949

5050
def test_creates_new_directory(self, tmp_path: pathlib.Path):
5151
target = tmp_path.joinpath("a", "b", "c")

tests/test_store/test_remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,4 @@ async def test_empty_nonexistent_path(self, store_kwargs) -> None:
213213
# regression test for https://github.com/zarr-developers/zarr-python/pull/2343
214214
store_kwargs["path"] += "/abc"
215215
store = await self.store_cls.open(**store_kwargs)
216-
assert await store.empty_dir("")
216+
assert await store.is_empty("")

tests/test_store/test_stateful_store.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def get_partial_values(
5555
def delete(self, path: str) -> None:
5656
return self._sync(self.store.delete(path))
5757

58-
def empty_dir(self, prefix: str = "") -> bool:
59-
return self._sync(self.store.empty_dir(prefix=prefix))
58+
def is_empty(self, prefix: str) -> bool:
59+
return self._sync(self.store.is_empty(prefix=prefix))
6060

6161
def clear(self) -> None:
6262
return self._sync(self.store.clear())
@@ -184,18 +184,18 @@ def clear(self) -> None:
184184
self.store.clear()
185185
self.model.clear()
186186

187-
assert self.store.empty_dir()
187+
assert self.store.is_empty("")
188188

189189
assert len(self.model.keys()) == len(list(self.store.list())) == 0
190190

191191
@rule()
192192
# Local store can be non-empty when there are subdirectories but no files
193193
@precondition(lambda self: not isinstance(self.store.store, LocalStore))
194-
def empty_dir(self) -> None:
195-
note("(empty_dir)")
194+
def is_empty(self) -> None:
195+
note("(is_empty)")
196196

197197
# make sure they either both are or both aren't empty (same state)
198-
assert self.store.empty_dir() == (not self.model)
198+
assert self.store.is_empty("") == (not self.model)
199199

200200
@rule(key=zarr_keys)
201201
def exists(self, key: str) -> None:
@@ -228,10 +228,10 @@ def check_zarr_keys(self) -> None:
228228
keys = list(self.store.list())
229229

230230
if not keys:
231-
assert self.store.empty_dir() is True
231+
assert self.store.is_empty("") is True
232232

233233
else:
234-
assert self.store.empty_dir() is False
234+
assert self.store.is_empty("") is False
235235

236236
for key in keys:
237237
assert self.store.exists(key) is True

0 commit comments

Comments
 (0)