Skip to content

Commit 979b6f2

Browse files
Ensure paths created (#2337)
1 parent 42ab847 commit 979b6f2

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/zarr/storage/local.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ def __init__(self, root: Path | str, *, mode: AccessModeLiteral = "r") -> None:
9494
assert isinstance(root, Path)
9595
self.root = root
9696

97+
async def _open(self) -> None:
98+
if not self.mode.readonly:
99+
self.root.mkdir(parents=True, exist_ok=True)
100+
return await super()._open()
101+
97102
async def clear(self) -> None:
98103
self._check_writable()
99104
shutil.rmtree(self.root)

tests/v3/test_store/test_local.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
from __future__ import annotations
22

3+
from typing import TYPE_CHECKING
4+
35
import pytest
46

7+
import zarr
58
from zarr.core.buffer import Buffer, cpu
69
from zarr.storage.local import LocalStore
710
from zarr.testing.store import StoreTests
811

12+
if TYPE_CHECKING:
13+
import pathlib
14+
915

1016
class TestLocalStore(StoreTests[LocalStore, cpu.Buffer]):
1117
store_cls = LocalStore
@@ -40,3 +46,10 @@ async def test_empty_with_empty_subdir(self, store: LocalStore) -> None:
4046
assert await store.empty()
4147
(store.root / "foo/bar").mkdir(parents=True)
4248
assert await store.empty()
49+
50+
def test_creates_new_directory(self, tmp_path: pathlib.Path):
51+
target = tmp_path.joinpath("a", "b", "c")
52+
assert not target.exists()
53+
54+
store = self.store_cls(root=target, mode="w")
55+
zarr.group(store=store)

0 commit comments

Comments
 (0)