Skip to content

Commit 9a1580b

Browse files
committed
move zarr.store to zarr.storage
also fix failing ci
1 parent fe49f5f commit 9a1580b

35 files changed

+109
-76
lines changed

src/zarr/api/asynchronous.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
import numpy as np
88
import numpy.typing as npt
99

10+
from zarr.abc.store import Store
1011
from zarr.core.array import Array, AsyncArray
1112
from zarr.core.common import JSON, AccessModeLiteral, ChunkCoords, MemoryOrder, ZarrFormat
1213
from zarr.core.config import config
1314
from zarr.core.group import AsyncGroup
1415
from zarr.core.metadata.v2 import ArrayV2Metadata
1516
from zarr.core.metadata.v3 import ArrayV3Metadata
16-
from zarr.store import (
17+
from zarr.storage import (
1718
StoreLike,
19+
StorePath,
1820
make_store_path,
1921
)
2022

@@ -221,15 +223,16 @@ async def open(
221223
Return type depends on what exists in the given store.
222224
"""
223225
zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
226+
224227
store_path = await make_store_path(store, mode=mode)
225228

226229
if path is not None:
227230
store_path = store_path / path
228231

229232
try:
230-
return await open_array(store=store_path, zarr_format=zarr_format, mode=mode, **kwargs)
233+
return await open_array(store=store_path, zarr_format=zarr_format, **kwargs)
231234
except KeyError:
232-
return await open_group(store=store_path, zarr_format=zarr_format, mode=mode, **kwargs)
235+
return await open_group(store=store_path, zarr_format=zarr_format, **kwargs)
233236

234237

235238
async def open_consolidated(*args: Any, **kwargs: Any) -> AsyncGroup:
@@ -299,7 +302,14 @@ async def save_array(
299302
or _default_zarr_version()
300303
)
301304

302-
store_path = await make_store_path(store, mode="w")
305+
mode = kwargs.pop("mode", None)
306+
if isinstance(store, Store):
307+
if mode is not None:
308+
raise ValueError("mode cannot be specified if store is a Store")
309+
elif mode is None:
310+
mode = cast(AccessModeLiteral, "a")
311+
312+
store_path = await make_store_path(store, mode=mode)
303313
if path is not None:
304314
store_path = store_path / path
305315
new = await AsyncArray.create(
@@ -453,7 +463,9 @@ async def group(
453463

454464
zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
455465

456-
store_path = await make_store_path(store)
466+
mode = None if isinstance(store, Store) else cast(AccessModeLiteral, "a")
467+
468+
store_path = await make_store_path(store, mode=mode)
457469
if path is not None:
458470
store_path = store_path / path
459471

@@ -551,6 +563,9 @@ async def open_group(
551563
if storage_options is not None:
552564
warnings.warn("storage_options is not yet implemented", RuntimeWarning, stacklevel=2)
553565

566+
if mode is not None and isinstance(store, Store | StorePath):
567+
raise ValueError("store and mode cannot be specified at the same time")
568+
554569
store_path = await make_store_path(store, mode=mode)
555570
if path is not None:
556571
store_path = store_path / path
@@ -724,7 +739,13 @@ async def create(
724739
if meta_array is not None:
725740
warnings.warn("meta_array is not yet implemented", RuntimeWarning, stacklevel=2)
726741

727-
mode = kwargs.pop("mode", cast(AccessModeLiteral, "r" if read_only else "a"))
742+
mode = kwargs.pop("mode", None)
743+
if isinstance(store, Store | StorePath):
744+
if mode is not None:
745+
raise ValueError("mode cannot be set when store is already initialized")
746+
elif mode is None:
747+
mode = cast(AccessModeLiteral, "r" if read_only else "a")
748+
728749
store_path = await make_store_path(store, mode=mode)
729750
if path is not None:
730751
store_path = store_path / path
@@ -896,8 +917,11 @@ async def open_array(
896917
The opened array.
897918
"""
898919

899-
store_path = await make_store_path(store)
900-
if path is not None:
920+
mode = kwargs.pop("mode", None)
921+
store_path = await make_store_path(store, mode=mode)
922+
if (
923+
path is not None
924+
): # FIXME: apply path before opening store in w or risk deleting existing data
901925
store_path = store_path / path
902926

903927
zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)

src/zarr/api/synchronous.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
if TYPE_CHECKING:
1111
from zarr.core.buffer import NDArrayLike
1212
from zarr.core.common import JSON, AccessModeLiteral, ChunkCoords, ZarrFormat
13-
from zarr.store import StoreLike
13+
from zarr.storage import StoreLike
1414

1515
__all__ = [
1616
"consolidate_metadata",

src/zarr/core/array.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
from zarr.core.metadata.v3 import ArrayV3Metadata
6060
from zarr.core.sync import sync
6161
from zarr.registry import get_pipeline_class
62-
from zarr.store import StoreLike, StorePath, make_store_path
63-
from zarr.store.common import (
62+
from zarr.storage import StoreLike, StorePath, make_store_path
63+
from zarr.storage.common import (
6464
ensure_no_existing_node,
6565
)
6666

@@ -158,7 +158,7 @@ async def create(
158158
dtype = np.dtype(dtype)
159159
if chunks:
160160
_chunks = normalize_chunks(chunks, shape, dtype.itemsize)
161-
if chunk_shape:
161+
else:
162162
_chunks = normalize_chunks(chunk_shape, shape, dtype.itemsize)
163163

164164
if zarr_format == 3:

src/zarr/core/group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
)
2929
from zarr.core.config import config
3030
from zarr.core.sync import SyncMixin, sync
31-
from zarr.store import StoreLike, StorePath, make_store_path
32-
from zarr.store.common import ensure_no_existing_node
31+
from zarr.storage import StoreLike, StorePath, make_store_path
32+
from zarr.storage.common import ensure_no_existing_node
3333

3434
if TYPE_CHECKING:
3535
from collections.abc import AsyncGenerator, Iterable, Iterator

src/zarr/storage/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from zarr.storage.common import StoreLike, StorePath, make_store_path
2+
from zarr.storage.local import LocalStore
3+
from zarr.storage.memory import MemoryStore
4+
from zarr.storage.remote import RemoteStore
5+
from zarr.storage.zip import ZipStore
6+
7+
# alias for backwards compatibility
8+
FSStore = RemoteStore
9+
DirectoryStore = LocalStore
10+
11+
__all__ = [
12+
"DirectoryStore",
13+
"FSStore",
14+
"StorePath",
15+
"StoreLike",
16+
"make_store_path",
17+
"RemoteStore",
18+
"LocalStore",
19+
"MemoryStore",
20+
"ZipStore",
21+
]
File renamed without changes.

src/zarr/store/common.py renamed to src/zarr/storage/common.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from zarr.core.buffer import Buffer, default_buffer_prototype
99
from zarr.core.common import ZARR_JSON, ZARRAY_JSON, ZGROUP_JSON, ZarrFormat
1010
from zarr.errors import ContainsArrayAndGroupError, ContainsArrayError, ContainsGroupError
11-
from zarr.store.local import LocalStore
12-
from zarr.store.memory import MemoryStore
11+
from zarr.storage.local import LocalStore
12+
from zarr.storage.memory import MemoryStore
1313

1414
if TYPE_CHECKING:
1515
from zarr.core.buffer import BufferPrototype
@@ -79,11 +79,13 @@ async def make_store_path(
7979
) -> StorePath:
8080
if isinstance(store_like, StorePath):
8181
if (mode is not None) and (AccessMode.from_literal(mode) != store_like.store.mode):
82-
raise ValueError(f"mode mismatch (mode={mode} != store.mode={store_like.store.mode})")
82+
raise ValueError(
83+
f"mode mismatch (mode={mode} != store.mode={store_like.store.mode.str})"
84+
)
8385
return store_like
8486
elif isinstance(store_like, Store):
8587
if (mode is not None) and (AccessMode.from_literal(mode) != store_like.mode):
86-
raise ValueError(f"mode mismatch (mode={mode} != store.mode={store_like.mode})")
88+
raise ValueError(f"mode mismatch (mode={mode} != store.mode={store_like.mode.str})")
8789
await store_like._ensure_open()
8890
return StorePath(store_like)
8991
elif store_like is None:
File renamed without changes.

src/zarr/store/memory.py renamed to src/zarr/storage/memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from zarr.abc.store import Store
77
from zarr.core.buffer import Buffer, gpu
88
from zarr.core.common import concurrent_map
9-
from zarr.store._utils import _normalize_interval_index
9+
from zarr.storage._utils import _normalize_interval_index
1010

1111
if TYPE_CHECKING:
1212
from collections.abc import AsyncGenerator, MutableMapping

src/zarr/store/remote.py renamed to src/zarr/storage/remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import fsspec
66

77
from zarr.abc.store import Store
8-
from zarr.store.common import _dereference_path
8+
from zarr.storage.common import _dereference_path
99

1010
if TYPE_CHECKING:
1111
from collections.abc import AsyncGenerator

0 commit comments

Comments
 (0)