|
30 | 30 | from collections.abc import Iterable |
31 | 31 |
|
32 | 32 | from zarr.abc.codec import Codec |
33 | | - from zarr.abc.store import StoreAccessMode |
34 | | - from zarr.core.buffer import NDArrayLike |
35 | 33 | from zarr.core.chunk_key_encodings import ChunkKeyEncoding |
36 | 34 |
|
37 | 35 | # TODO: this type could use some more thought |
|
66 | 64 | "zeros_like", |
67 | 65 | ] |
68 | 66 |
|
69 | | -# Persistence mode: 'r' means read only (must exist); 'r+' means |
70 | | -# read/write (must exist); 'a' means read/write (create if doesn't |
71 | | -# exist); 'w' means create (overwrite if exists); 'w-' means create |
72 | | -# (fail if exists). |
73 | | -persistence_to_store_modes: dict[AccessModeLiteral, StoreAccessMode] = { |
74 | | - "r": "r", |
75 | | - "r+": "w", |
76 | | - "a": "w", |
77 | | - "w": "w", |
78 | | - "w-": "w", |
79 | | -} |
80 | | - |
81 | | - |
82 | | -def _handle_store_mode(mode: AccessModeLiteral | None) -> StoreAccessMode: |
83 | | - if mode is None: |
84 | | - return "r" |
85 | | - else: |
86 | | - return persistence_to_store_modes[mode] |
87 | | - |
88 | 67 |
|
89 | 68 | def _infer_exists_ok(mode: AccessModeLiteral) -> bool: |
90 | | - if mode in ("a", "r+", "w"): |
91 | | - return True |
92 | | - return False |
| 69 | + return mode in ("a", "r+", "w") |
93 | 70 |
|
94 | 71 |
|
95 | 72 | def _get_shape_chunks(a: ArrayLike | Any) -> tuple[ChunkCoords | None, ChunkCoords | None]: |
@@ -313,11 +290,7 @@ async def open( |
313 | 290 | """ |
314 | 291 | zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format) |
315 | 292 |
|
316 | | - store_mode = _handle_store_mode(mode) |
317 | | - store_path = await make_store_path( |
318 | | - store, mode=store_mode, path=path, storage_options=storage_options |
319 | | - ) |
320 | | - await store_path._init(mode=mode) |
| 293 | + store_path = await make_store_path(store, mode=mode, path=path, storage_options=storage_options) |
321 | 294 |
|
322 | 295 | # TODO: the mode check below seems wrong! |
323 | 296 | if "shape" not in kwargs and mode in {"a", "r", "r+"}: |
@@ -427,11 +400,7 @@ async def save_array( |
427 | 400 | raise TypeError("arr argument must be numpy or other NDArrayLike array") |
428 | 401 |
|
429 | 402 | mode = kwargs.pop("mode", "a") |
430 | | - store_mode = _handle_store_mode(mode) |
431 | | - store_path = await make_store_path( |
432 | | - store, path=path, mode=store_mode, storage_options=storage_options |
433 | | - ) |
434 | | - await store_path._init(mode=mode) |
| 403 | + store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options) |
435 | 404 | if np.isscalar(arr): |
436 | 405 | arr = np.array(arr) |
437 | 406 | shape = arr.shape |
@@ -626,11 +595,7 @@ async def group( |
626 | 595 | mode = "w" |
627 | 596 | else: |
628 | 597 | mode = "r+" |
629 | | - store_mode = _handle_store_mode(mode) |
630 | | - store_path = await make_store_path( |
631 | | - store, path=path, mode=store_mode, storage_options=storage_options |
632 | | - ) |
633 | | - await store_path._init(mode=mode) |
| 598 | + store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options) |
634 | 599 |
|
635 | 600 | if chunk_store is not None: |
636 | 601 | warnings.warn("chunk_store is not yet implemented", RuntimeWarning, stacklevel=2) |
@@ -743,12 +708,8 @@ async def open_group( |
743 | 708 | if chunk_store is not None: |
744 | 709 | warnings.warn("chunk_store is not yet implemented", RuntimeWarning, stacklevel=2) |
745 | 710 |
|
746 | | - store_mode = _handle_store_mode(mode) |
747 | 711 | exists_ok = _infer_exists_ok(mode) |
748 | | - store_path = await make_store_path( |
749 | | - store, mode=store_mode, storage_options=storage_options, path=path |
750 | | - ) |
751 | | - await store_path._init(mode=mode) |
| 712 | + store_path = await make_store_path(store, mode=mode, storage_options=storage_options, path=path) |
752 | 713 |
|
753 | 714 | if attributes is None: |
754 | 715 | attributes = {} |
@@ -931,11 +892,7 @@ async def create( |
931 | 892 | mode = kwargs.pop("mode", None) |
932 | 893 | if mode is None: |
933 | 894 | mode = "a" |
934 | | - store_mode = _handle_store_mode(mode) |
935 | | - store_path = await make_store_path( |
936 | | - store, path=path, mode=store_mode, storage_options=storage_options |
937 | | - ) |
938 | | - await store_path._init(mode) |
| 895 | + store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options) |
939 | 896 | return await AsyncArray.create( |
940 | 897 | store_path, |
941 | 898 | shape=shape, |
@@ -1122,10 +1079,7 @@ async def open_array( |
1122 | 1079 | """ |
1123 | 1080 |
|
1124 | 1081 | mode = kwargs.pop("mode", None) |
1125 | | - store_mode = _handle_store_mode(mode) |
1126 | | - store_path = await make_store_path( |
1127 | | - store, path=path, mode=store_mode, storage_options=storage_options |
1128 | | - ) |
| 1082 | + store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options) |
1129 | 1083 |
|
1130 | 1084 | zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format) |
1131 | 1085 |
|
|
0 commit comments