Skip to content

Commit a8da920

Browse files
slowjazzd-v-b
andauthored
obstore delete_dir (#3310)
* obstore delete_dir * add cl * add a delete test * use obstore list and collect_async * delete test --------- Co-authored-by: Davis Bennett <[email protected]>
1 parent 3d0e40e commit a8da920

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

changes/3310.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add obstore implementation of delete_dir.

src/zarr/storage/_obstore.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Store,
1414
SuffixByteRequest,
1515
)
16+
from zarr.core.common import concurrent_map
1617
from zarr.core.config import config
1718

1819
if TYPE_CHECKING:
@@ -195,6 +196,18 @@ async def delete(self, key: str) -> None:
195196
with contextlib.suppress(FileNotFoundError):
196197
await obs.delete_async(self.store, key)
197198

199+
async def delete_dir(self, prefix: str) -> None:
200+
# docstring inherited
201+
import obstore as obs
202+
203+
self._check_writable()
204+
if prefix != "" and not prefix.endswith("/"):
205+
prefix += "/"
206+
207+
metas = await obs.list(self.store, prefix).collect_async()
208+
keys = [(m["path"],) for m in metas]
209+
await concurrent_map(keys, self.delete, limit=config.get("async.concurrency"))
210+
198211
@property
199212
def supports_listing(self) -> bool:
200213
# docstring inherited

0 commit comments

Comments
 (0)