Skip to content

Commit

Permalink
Type dimension separator
Browse files Browse the repository at this point in the history
  • Loading branch information
dstansby committed Dec 27, 2023
1 parent b5f79dd commit ac9a01f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 deletions.
5 changes: 4 additions & 1 deletion zarr/_storage/absstore.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""This module contains storage classes related to Azure Blob Storage (ABS)"""

from typing import Optional
import warnings

from numcodecs.compat import ensure_bytes
from zarr.util import normalize_storage_path
from zarr._storage.store import _get_metadata_suffix, data_root, meta_root, Store, StoreV3
from zarr.types import DIMENSION_SEPARATOR

__doctest_requires__ = {
("ABSStore", "ABSStore.*"): ["azure.storage.blob"],
Expand Down Expand Up @@ -67,7 +70,7 @@ def __init__(
account_name=None,
account_key=None,
blob_service_kwargs=None,
dimension_separator=None,
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
client=None,
):
self._dimension_separator = dimension_separator
Expand Down
7 changes: 5 additions & 2 deletions zarr/_storage/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
from collections import OrderedDict
from collections.abc import MutableMapping
from threading import Lock
from typing import Union, Dict, Any
from typing import Union, Dict, Any, Optional

from zarr.errors import (
MetadataError,
ReadOnlyError,
)
from zarr.util import buffer_size, json_loads, normalize_storage_path
from zarr.types import DIMENSION_SEPARATOR

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


class MemoryStoreV3(MemoryStore, StoreV3):
def __init__(self, root=None, cls=dict, dimension_separator=None):
def __init__(
self, root=None, cls=dict, dimension_separator: Optional[DIMENSION_SEPARATOR] = None
):
if root is None:
self.root = cls()
else:
Expand Down
3 changes: 2 additions & 1 deletion zarr/_storage/v3_storage_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from zarr._storage.store import StorageTransformer, StoreV3, _rmdir_from_keys_v3
from zarr.util import normalize_storage_path
from zarr.types import DIMENSION_SEPARATOR


MAX_UINT_64 = 2**64 - 1
Expand Down Expand Up @@ -118,7 +119,7 @@ def _copy_for_array(self, array, inner_store):
return transformer_copy

@property
def dimension_separator(self) -> str:
def dimension_separator(self) -> DIMENSION_SEPARATOR:
assert (
self._dimension_separator is not None
), "dimension_separator is not initialized, first get a copy via _copy_for_array."
Expand Down
2 changes: 1 addition & 1 deletion zarr/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def open_array(
write_empty_chunks=True,
*,
zarr_version=None,
dimension_separator=None,
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
meta_array=None,
**kwargs,
):
Expand Down
45 changes: 32 additions & 13 deletions zarr/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
from numcodecs.compat import ensure_bytes, ensure_text, ensure_contiguous_ndarray_like
from numcodecs.registry import codec_registry
from zarr.context import Context
from zarr.types import PathLike as Path
from zarr.types import PathLike as Path, DIMENSION_SEPARATOR
from zarr.util import NoLock

from zarr.errors import (
MetadataError,
Expand Down Expand Up @@ -326,7 +327,7 @@ def init_array(
chunk_store: Optional[StoreLike] = None,
filters=None,
object_codec=None,
dimension_separator=None,
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
storage_transformers=(),
):
"""Initialize an array store with the given configuration. Note that this is a low-level
Expand Down Expand Up @@ -480,7 +481,7 @@ def _init_array_metadata(
chunk_store: Optional[StoreLike] = None,
filters=None,
object_codec=None,
dimension_separator=None,
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
storage_transformers=(),
):
store_version = getattr(store, "_store_version", 2)
Expand Down Expand Up @@ -1053,7 +1054,9 @@ class DirectoryStore(Store):
"""

def __init__(self, path, normalize_keys=False, dimension_separator=None):
def __init__(
self, path, normalize_keys=False, dimension_separator: Optional[DIMENSION_SEPARATOR] = None
):
# guard conditions
path = os.path.abspath(path)
if os.path.exists(path) and not os.path.isdir(path):
Expand Down Expand Up @@ -1348,7 +1351,7 @@ def __init__(
key_separator=None,
mode="w",
exceptions=(KeyError, PermissionError, IOError),
dimension_separator=None,
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
fs=None,
check=False,
create=False,
Expand Down Expand Up @@ -1567,7 +1570,12 @@ class TempStore(DirectoryStore):

# noinspection PyShadowingBuiltins
def __init__(
self, suffix="", prefix="zarr", dir=None, normalize_keys=False, dimension_separator=None
self,
suffix="",
prefix="zarr",
dir=None,
normalize_keys=False,
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
):
path = tempfile.mkdtemp(suffix=suffix, prefix=prefix, dir=dir)
atexit.register(atexit_rmtree, path)
Expand Down Expand Up @@ -1651,7 +1659,9 @@ class NestedDirectoryStore(DirectoryStore):
"""

def __init__(self, path, normalize_keys=False, dimension_separator="/"):
def __init__(
self, path, normalize_keys=False, dimension_separator: Optional[DIMENSION_SEPARATOR] = "/"
):
super().__init__(path, normalize_keys=normalize_keys)
if dimension_separator is None:
dimension_separator = "/"
Expand Down Expand Up @@ -1764,7 +1774,7 @@ def __init__(
compression=zipfile.ZIP_STORED,
allowZip64=True,
mode="a",
dimension_separator=None,
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
):
# store properties
path = os.path.abspath(path)
Expand Down Expand Up @@ -2057,7 +2067,7 @@ def __init__(
mode=0o666,
open=None,
write_lock=True,
dimension_separator=None,
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
**open_kwargs,
):
if open is None:
Expand All @@ -2072,6 +2082,7 @@ def __init__(
self.mode = mode
self.open = open
self.write_lock = write_lock
self.write_mutex: Union[Lock, NoLock]
if write_lock:
# This may not be required as some dbm implementations manage their own
# locks, but err on the side of caution.
Expand Down Expand Up @@ -2228,7 +2239,13 @@ class LMDBStore(Store):
"""

def __init__(self, path, buffers=True, dimension_separator=None, **kwargs):
def __init__(
self,
path,
buffers=True,
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
**kwargs,
):
import lmdb

# set default memory map size to something larger than the lmdb default, which is
Expand Down Expand Up @@ -2579,7 +2596,7 @@ class SQLiteStore(Store):
>>> store.close() # don't forget to call this when you're done
"""

def __init__(self, path, dimension_separator=None, **kwargs):
def __init__(self, path, dimension_separator: Optional[DIMENSION_SEPARATOR] = None, **kwargs):
import sqlite3

self._dimension_separator = dimension_separator
Expand Down Expand Up @@ -2777,7 +2794,7 @@ def __init__(
self,
database="mongodb_zarr",
collection="zarr_collection",
dimension_separator=None,
dimension_separator: Optional[DIMENSION_SEPARATOR] = None,
**kwargs,
):
import pymongo
Expand Down Expand Up @@ -2852,7 +2869,9 @@ class RedisStore(Store):
"""

def __init__(self, prefix="zarr", dimension_separator=None, **kwargs):
def __init__(
self, prefix="zarr", dimension_separator: Optional[DIMENSION_SEPARATOR] = None, **kwargs
):
import redis

self._prefix = prefix
Expand Down

0 comments on commit ac9a01f

Please sign in to comment.