Skip to content

Commit a0e5559

Browse files
dstansbyd-v-b
andauthored
Type dimension separator (#1620)
Co-authored-by: Davis Bennett <davis.v.bennett@gmail.com>
1 parent ec4d216 commit a0e5559

File tree

5 files changed

+44
-18
lines changed

5 files changed

+44
-18
lines changed

zarr/_storage/absstore.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"""This module contains storage classes related to Azure Blob Storage (ABS)"""
22

3+
from typing import Optional
34
import warnings
5+
46
from numcodecs.compat import ensure_bytes
57
from zarr.util import normalize_storage_path
68
from zarr._storage.store import _get_metadata_suffix, data_root, meta_root, Store, StoreV3
9+
from zarr.types import DIMENSION_SEPARATOR
710

811
__doctest_requires__ = {
912
("ABSStore", "ABSStore.*"): ["azure.storage.blob"],
@@ -67,7 +70,7 @@ def __init__(
6770
account_name=None,
6871
account_key=None,
6972
blob_service_kwargs=None,
70-
dimension_separator=None,
73+
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
7174
client=None,
7275
):
7376
self._dimension_separator = dimension_separator

zarr/_storage/v3.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
from collections import OrderedDict
44
from collections.abc import MutableMapping
55
from threading import Lock
6-
from typing import Union, Dict, Any
6+
from typing import Union, Dict, Any, Optional
77

88
from zarr.errors import (
99
MetadataError,
1010
ReadOnlyError,
1111
)
1212
from zarr.util import buffer_size, json_loads, normalize_storage_path
13+
from zarr.types import DIMENSION_SEPARATOR
1314

1415
from zarr._storage.absstore import ABSStoreV3 # noqa: F401
1516
from zarr._storage.store import ( # noqa: F401
@@ -224,7 +225,9 @@ def get_partial_values(self, key_ranges):
224225

225226

226227
class MemoryStoreV3(MemoryStore, StoreV3):
227-
def __init__(self, root=None, cls=dict, dimension_separator=None):
228+
def __init__(
229+
self, root=None, cls=dict, dimension_separator: Optional[DIMENSION_SEPARATOR] = None
230+
):
228231
if root is None:
229232
self.root = cls()
230233
else:

zarr/_storage/v3_storage_transformers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from zarr._storage.store import StorageTransformer, StoreV3, _rmdir_from_keys_v3
1010
from zarr.util import normalize_storage_path
11+
from zarr.types import DIMENSION_SEPARATOR
1112

1213

1314
MAX_UINT_64 = 2**64 - 1
@@ -118,7 +119,7 @@ def _copy_for_array(self, array, inner_store):
118119
return transformer_copy
119120

120121
@property
121-
def dimension_separator(self) -> str:
122+
def dimension_separator(self) -> DIMENSION_SEPARATOR:
122123
assert (
123124
self._dimension_separator is not None
124125
), "dimension_separator is not initialized, first get a copy via _copy_for_array."

zarr/creation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def open_array(
470470
write_empty_chunks=True,
471471
*,
472472
zarr_version=None,
473-
dimension_separator=None,
473+
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
474474
meta_array=None,
475475
**kwargs,
476476
):

zarr/storage.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
from numcodecs.compat import ensure_bytes, ensure_text, ensure_contiguous_ndarray_like
4242
from numcodecs.registry import codec_registry
4343
from zarr.context import Context
44-
from zarr.types import PathLike as Path
44+
from zarr.types import PathLike as Path, DIMENSION_SEPARATOR
45+
from zarr.util import NoLock
4546

4647
from zarr.errors import (
4748
MetadataError,
@@ -327,7 +328,7 @@ def init_array(
327328
chunk_store: Optional[StoreLike] = None,
328329
filters=None,
329330
object_codec=None,
330-
dimension_separator=None,
331+
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
331332
storage_transformers=(),
332333
):
333334
"""Initialize an array store with the given configuration. Note that this is a low-level
@@ -481,7 +482,7 @@ def _init_array_metadata(
481482
chunk_store: Optional[StoreLike] = None,
482483
filters=None,
483484
object_codec=None,
484-
dimension_separator=None,
485+
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
485486
storage_transformers=(),
486487
):
487488
store_version = getattr(store, "_store_version", 2)
@@ -1054,7 +1055,9 @@ class DirectoryStore(Store):
10541055
10551056
"""
10561057

1057-
def __init__(self, path, normalize_keys=False, dimension_separator=None):
1058+
def __init__(
1059+
self, path, normalize_keys=False, dimension_separator: Optional[DIMENSION_SEPARATOR] = None
1060+
):
10581061
# guard conditions
10591062
path = os.path.abspath(path)
10601063
if os.path.exists(path) and not os.path.isdir(path):
@@ -1349,7 +1352,7 @@ def __init__(
13491352
key_separator=None,
13501353
mode="w",
13511354
exceptions=(KeyError, PermissionError, IOError),
1352-
dimension_separator=None,
1355+
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
13531356
fs=None,
13541357
check=False,
13551358
create=False,
@@ -1568,7 +1571,12 @@ class TempStore(DirectoryStore):
15681571

15691572
# noinspection PyShadowingBuiltins
15701573
def __init__(
1571-
self, suffix="", prefix="zarr", dir=None, normalize_keys=False, dimension_separator=None
1574+
self,
1575+
suffix="",
1576+
prefix="zarr",
1577+
dir=None,
1578+
normalize_keys=False,
1579+
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
15721580
):
15731581
path = tempfile.mkdtemp(suffix=suffix, prefix=prefix, dir=dir)
15741582
atexit.register(atexit_rmtree, path)
@@ -1652,7 +1660,9 @@ class NestedDirectoryStore(DirectoryStore):
16521660
16531661
"""
16541662

1655-
def __init__(self, path, normalize_keys=False, dimension_separator="/"):
1663+
def __init__(
1664+
self, path, normalize_keys=False, dimension_separator: Optional[DIMENSION_SEPARATOR] = "/"
1665+
):
16561666
super().__init__(path, normalize_keys=normalize_keys)
16571667
if dimension_separator is None:
16581668
dimension_separator = "/"
@@ -1765,7 +1775,7 @@ def __init__(
17651775
compression=zipfile.ZIP_STORED,
17661776
allowZip64=True,
17671777
mode="a",
1768-
dimension_separator=None,
1778+
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
17691779
):
17701780
# store properties
17711781
path = os.path.abspath(path)
@@ -2058,7 +2068,7 @@ def __init__(
20582068
mode=0o666,
20592069
open=None,
20602070
write_lock=True,
2061-
dimension_separator=None,
2071+
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
20622072
**open_kwargs,
20632073
):
20642074
if open is None:
@@ -2073,6 +2083,7 @@ def __init__(
20732083
self.mode = mode
20742084
self.open = open
20752085
self.write_lock = write_lock
2086+
self.write_mutex: Union[Lock, NoLock]
20762087
if write_lock:
20772088
# This may not be required as some dbm implementations manage their own
20782089
# locks, but err on the side of caution.
@@ -2229,7 +2240,13 @@ class LMDBStore(Store):
22292240
22302241
"""
22312242

2232-
def __init__(self, path, buffers=True, dimension_separator=None, **kwargs):
2243+
def __init__(
2244+
self,
2245+
path,
2246+
buffers=True,
2247+
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
2248+
**kwargs,
2249+
):
22332250
import lmdb
22342251

22352252
# set default memory map size to something larger than the lmdb default, which is
@@ -2580,7 +2597,7 @@ class SQLiteStore(Store):
25802597
>>> store.close() # don't forget to call this when you're done
25812598
"""
25822599

2583-
def __init__(self, path, dimension_separator=None, **kwargs):
2600+
def __init__(self, path, dimension_separator: Optional[DIMENSION_SEPARATOR] = None, **kwargs):
25842601
import sqlite3
25852602

25862603
self._dimension_separator = dimension_separator
@@ -2776,7 +2793,7 @@ def __init__(
27762793
self,
27772794
database="mongodb_zarr",
27782795
collection="zarr_collection",
2779-
dimension_separator=None,
2796+
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
27802797
**kwargs,
27812798
):
27822799
import pymongo
@@ -2851,7 +2868,9 @@ class RedisStore(Store):
28512868
28522869
"""
28532870

2854-
def __init__(self, prefix="zarr", dimension_separator=None, **kwargs):
2871+
def __init__(
2872+
self, prefix="zarr", dimension_separator: Optional[DIMENSION_SEPARATOR] = None, **kwargs
2873+
):
28552874
import redis
28562875

28572876
self._prefix = prefix

0 commit comments

Comments
 (0)