From ee09dec09afce88cf593c0e8c0ce0907a3397b66 Mon Sep 17 00:00:00 2001 From: Joseph Hamman Date: Mon, 22 Apr 2024 21:08:41 -0700 Subject: [PATCH 1/4] move v2 code/tests to v2 directories --- docs/api.rst | 1 - docs/api/attrs.rst | 6 +- docs/api/codecs.rst | 8 +- docs/api/convenience.rst | 6 +- docs/api/core.rst | 6 +- docs/api/creation.rst | 6 +- docs/api/hierarchy.rst | 6 +- docs/api/n5.rst | 6 +- docs/api/storage.rst | 6 +- docs/api/sync.rst | 6 +- docs/api/v3.rst | 77 -------------- src/zarr/{ => v2}/__init__.py | 18 ++-- src/zarr/{ => v2}/_storage/__init__.py | 0 src/zarr/{ => v2}/_storage/absstore.py | 4 +- src/zarr/{ => v2}/_storage/store.py | 10 +- src/zarr/{ => v2}/attrs.py | 4 +- src/zarr/{ => v2}/codecs.py | 0 src/zarr/{ => v2}/context.py | 0 src/zarr/{ => v2}/convenience.py | 142 ++++++++++++------------- src/zarr/{ => v2}/core.py | 94 ++++++++-------- src/zarr/{ => v2}/creation.py | 62 +++++------ src/zarr/{ => v2}/errors.py | 0 src/zarr/{ => v2}/hierarchy.py | 138 ++++++++++++------------ src/zarr/{ => v2}/indexing.py | 2 +- src/zarr/{ => v2}/meta.py | 4 +- src/zarr/{ => v2}/meta_v1.py | 2 +- src/zarr/{ => v2}/n5.py | 12 +-- src/zarr/{ => v2}/storage.py | 114 ++++++++++---------- src/zarr/{ => v2}/sync.py | 0 src/zarr/{ => v2}/util.py | 0 tests/{ => v2}/__init__.py | 0 tests/{ => v2}/conftest.py | 5 + tests/{ => v2}/data/store.zip | Bin tests/{ => v2}/data/store/foo | 0 tests/{ => v2}/test_attrs.py | 11 +- tests/{ => v2}/test_convenience.py | 12 +-- tests/{ => v2}/test_core.py | 20 ++-- tests/{ => v2}/test_creation.py | 14 +-- tests/{ => v2}/test_dim_separator.py | 18 ++-- tests/{ => v2}/test_filters.py | 2 +- tests/{ => v2}/test_hierarchy.py | 12 +-- tests/{ => v2}/test_indexing.py | 94 ++++++++-------- tests/{ => v2}/test_info.py | 6 +- tests/{ => v2}/test_meta.py | 8 +- tests/{ => v2}/test_meta_array.py | 12 +-- tests/{ => v2}/test_n5.py | 6 +- tests/{ => v2}/test_storage.py | 2 +- tests/{ => v2}/test_storage_v3.py | 0 tests/{ => v2}/test_sync.py | 10 +- tests/{ => v2}/test_util.py | 4 +- tests/{ => v2}/util.py | 4 +- tests/v3/test_codecs.py | 14 +-- tests/v3/test_common.py | 4 +- 53 files changed, 462 insertions(+), 536 deletions(-) delete mode 100644 docs/api/v3.rst rename src/zarr/{ => v2}/__init__.py (66%) rename src/zarr/{ => v2}/_storage/__init__.py (100%) rename src/zarr/{ => v2}/_storage/absstore.py (98%) rename src/zarr/{ => v2}/_storage/store.py (96%) rename src/zarr/{ => v2}/attrs.py (98%) rename src/zarr/{ => v2}/codecs.py (100%) rename src/zarr/{ => v2}/context.py (100%) rename src/zarr/{ => v2}/convenience.py (91%) rename src/zarr/{ => v2}/core.py (97%) rename src/zarr/{ => v2}/creation.py (92%) rename src/zarr/{ => v2}/errors.py (100%) rename src/zarr/{ => v2}/hierarchy.py (93%) rename src/zarr/{ => v2}/indexing.py (99%) rename src/zarr/{ => v2}/meta.py (99%) rename src/zarr/{ => v2}/meta_v1.py (97%) rename src/zarr/{ => v2}/n5.py (98%) rename src/zarr/{ => v2}/storage.py (96%) rename src/zarr/{ => v2}/sync.py (100%) rename src/zarr/{ => v2}/util.py (100%) rename tests/{ => v2}/__init__.py (100%) rename tests/{ => v2}/conftest.py (60%) rename tests/{ => v2}/data/store.zip (100%) rename tests/{ => v2}/data/store/foo (100%) rename tests/{ => v2}/test_attrs.py (97%) rename tests/{ => v2}/test_convenience.py (99%) rename tests/{ => v2}/test_core.py (99%) rename tests/{ => v2}/test_creation.py (98%) rename tests/{ => v2}/test_dim_separator.py (87%) rename tests/{ => v2}/test_filters.py (99%) rename tests/{ => v2}/test_hierarchy.py (99%) rename tests/{ => v2}/test_indexing.py (95%) rename tests/{ => v2}/test_info.py (91%) rename tests/{ => v2}/test_meta.py (98%) rename tests/{ => v2}/test_meta_array.py (95%) rename tests/{ => v2}/test_n5.py (93%) rename tests/{ => v2}/test_storage.py (99%) rename tests/{ => v2}/test_storage_v3.py (100%) rename tests/{ => v2}/test_sync.py (97%) rename tests/{ => v2}/test_util.py (99%) rename tests/{ => v2}/util.py (97%) diff --git a/docs/api.rst b/docs/api.rst index e200dd908d..2b6e7ea516 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -13,7 +13,6 @@ API reference api/codecs api/attrs api/sync - api/v3 Indices and tables ------------------ diff --git a/docs/api/attrs.rst b/docs/api/attrs.rst index f95e63af3a..067b45fac6 100644 --- a/docs/api/attrs.rst +++ b/docs/api/attrs.rst @@ -1,6 +1,6 @@ -The Attributes class (``zarr.attrs``) -===================================== -.. module:: zarr.attrs +The Attributes class (``zarr.v2.attrs``) +======================================== +.. module:: zarr.v2.attrs .. autoclass:: Attributes diff --git a/docs/api/codecs.rst b/docs/api/codecs.rst index b50f747d74..454c5ccd20 100644 --- a/docs/api/codecs.rst +++ b/docs/api/codecs.rst @@ -1,5 +1,5 @@ -Compressors and filters (``zarr.codecs``) -========================================= +Compressors and filters (``zarr.v2.codecs``) +============================================ .. module:: zarr.codecs This module contains compressor and filter classes for use with Zarr. Please note that this module @@ -8,9 +8,9 @@ onwards, all codec classes have been moved to a separate package called Numcodec packages (Zarr and Numcodecs_) are designed to be used together. For example, a Numcodecs_ codec class can be used as a compressor for a Zarr array:: - >>> import zarr + >>> import zarr.v2 >>> from numcodecs import Blosc - >>> z = zarr.zeros(1000000, compressor=Blosc(cname='zstd', clevel=1, shuffle=Blosc.SHUFFLE)) + >>> z = zarr.v2.zeros(1000000, compressor=Blosc(cname='zstd', clevel=1, shuffle=Blosc.SHUFFLE)) Codec classes can also be used as filters. See the tutorial section on :ref:`tutorial_filters` for more information. diff --git a/docs/api/convenience.rst b/docs/api/convenience.rst index a70a90ce7c..1ff26452fa 100644 --- a/docs/api/convenience.rst +++ b/docs/api/convenience.rst @@ -1,6 +1,6 @@ -Convenience functions (``zarr.convenience``) -============================================ -.. automodule:: zarr.convenience +Convenience functions (``zarr.v2.convenience``) +=============================================== +.. automodule:: zarr.v2.convenience .. autofunction:: open .. autofunction:: save .. autofunction:: load diff --git a/docs/api/core.rst b/docs/api/core.rst index b310460e51..aacd03e2a5 100644 --- a/docs/api/core.rst +++ b/docs/api/core.rst @@ -1,5 +1,5 @@ -The Array class (``zarr.core``) -=============================== +The Array class (``zarr.v2.core``) +================================== -.. automodapi:: zarr.core +.. automodapi:: zarr.v2.core :no-heading: diff --git a/docs/api/creation.rst b/docs/api/creation.rst index 66422c0670..ad0a2ead49 100644 --- a/docs/api/creation.rst +++ b/docs/api/creation.rst @@ -1,6 +1,6 @@ -Array creation (``zarr.creation``) -================================== -.. module:: zarr.creation +Array creation (``zarr.v2.creation``) +===================================== +.. module:: zarr.v2.creation .. autofunction:: create .. autofunction:: empty .. autofunction:: zeros diff --git a/docs/api/hierarchy.rst b/docs/api/hierarchy.rst index 11a5575144..5d9280af1e 100644 --- a/docs/api/hierarchy.rst +++ b/docs/api/hierarchy.rst @@ -1,6 +1,6 @@ -Groups (``zarr.hierarchy``) -=========================== -.. module:: zarr.hierarchy +Groups (``zarr.v2.hierarchy``) +============================== +.. module:: zarr.v2.hierarchy .. autofunction:: group .. autofunction:: open_group diff --git a/docs/api/n5.rst b/docs/api/n5.rst index b6a8d8c61e..22e490bad4 100644 --- a/docs/api/n5.rst +++ b/docs/api/n5.rst @@ -1,5 +1,5 @@ -N5 (``zarr.n5``) -================ -.. automodule:: zarr.n5 +N5 (``zarr.v2.n5``) +=================== +.. automodule:: zarr.v2.n5 .. autoclass:: N5Store diff --git a/docs/api/storage.rst b/docs/api/storage.rst index 4321837449..d0ebd8a429 100644 --- a/docs/api/storage.rst +++ b/docs/api/storage.rst @@ -1,6 +1,6 @@ -Storage (``zarr.storage``) -========================== -.. automodule:: zarr.storage +Storage (``zarr.v2.storage``) +============================= +.. automodule:: zarr.v2.storage .. autoclass:: MemoryStore .. autoclass:: DirectoryStore diff --git a/docs/api/sync.rst b/docs/api/sync.rst index a139805e78..ff961543af 100644 --- a/docs/api/sync.rst +++ b/docs/api/sync.rst @@ -1,6 +1,6 @@ -Synchronization (``zarr.sync``) -=============================== -.. module:: zarr.sync +Synchronization (``zarr.v2.sync``) +================================== +.. module:: zarr.v2.sync .. autoclass:: ThreadSynchronizer .. autoclass:: ProcessSynchronizer diff --git a/docs/api/v3.rst b/docs/api/v3.rst deleted file mode 100644 index 7665b2ddd1..0000000000 --- a/docs/api/v3.rst +++ /dev/null @@ -1,77 +0,0 @@ -V3 Specification Implementation(``zarr._storage.v3``) -===================================================== - -This module contains the implementation of the `Zarr V3 Specification `_. - -.. warning:: - Since Zarr Python 2.12 release, this module provides experimental infrastructure for reading and - writing the upcoming V3 spec of the Zarr format. Users wishing to prepare for the migration can set - the environment variable ``ZARR_V3_EXPERIMENTAL_API=1`` to begin experimenting, however data - written with this API should be expected to become stale, as the implementation will still change. - -The new ``zarr._store.v3`` package has the necessary classes and functions for evaluating Zarr V3. -Since the design is not finalised, the classes and functions are not automatically imported into -the regular Zarr namespace. - -Code snippet for creating Zarr V3 arrays:: - - >>> import zarr - >>> z = zarr.create((10000, 10000), - >>> chunks=(100, 100), - >>> dtype='f8', - >>> compressor='default', - >>> path='path-where-you-want-zarr-v3-array', - >>> zarr_version=3) - -Further, you can use `z.info` to see details about the array you just created:: - - >>> z.info - Name : path-where-you-want-zarr-v3-array - Type : zarr.core.Array - Data type : float64 - Shape : (10000, 10000) - Chunk shape : (100, 100) - Order : C - Read-only : False - Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0) - Store type : zarr._storage.v3.KVStoreV3 - No. bytes : 800000000 (762.9M) - No. bytes stored : 557 - Storage ratio : 1436265.7 - Chunks initialized : 0/10000 - -You can also check ``Store type`` here (which indicates Zarr V3). - -.. module:: zarr._storage.v3 - -.. autoclass:: RmdirV3 -.. autoclass:: KVStoreV3 -.. autoclass:: FSStoreV3 -.. autoclass:: MemoryStoreV3 -.. autoclass:: DirectoryStoreV3 -.. autoclass:: ZipStoreV3 -.. autoclass:: RedisStoreV3 -.. autoclass:: MongoDBStoreV3 -.. autoclass:: DBMStoreV3 -.. autoclass:: LMDBStoreV3 -.. autoclass:: SQLiteStoreV3 -.. autoclass:: LRUStoreCacheV3 -.. autoclass:: ConsolidatedMetadataStoreV3 - -In v3 `storage transformers `_ -can be set via ``zarr.create(…, storage_transformers=[…])``. -The experimental sharding storage transformer can be tested by setting -the environment variable ``ZARR_V3_SHARDING=1``. Data written with this flag -enabled should be expected to become stale until -`ZEP 2 `_ is approved -and fully implemented. - -.. module:: zarr._storage.v3_storage_transformers - -.. autoclass:: ShardingStorageTransformer - -The abstract base class for storage transformers is - -.. module:: zarr._storage.store - -.. autoclass:: StorageTransformer diff --git a/src/zarr/__init__.py b/src/zarr/v2/__init__.py similarity index 66% rename from src/zarr/__init__.py rename to src/zarr/v2/__init__.py index 601b1295ab..27c7595580 100644 --- a/src/zarr/__init__.py +++ b/src/zarr/v2/__init__.py @@ -1,6 +1,6 @@ # flake8: noqa -from zarr.codecs import * -from zarr.convenience import ( +from zarr.v2.codecs import * +from zarr.v2.convenience import ( consolidate_metadata, copy, copy_all, @@ -13,8 +13,8 @@ save_group, tree, ) -from zarr.core import Array -from zarr.creation import ( +from zarr.v2.core import Array +from zarr.v2.creation import ( array, create, empty, @@ -28,10 +28,10 @@ zeros, zeros_like, ) -from zarr.errors import CopyError, MetadataError -from zarr.hierarchy import Group, group, open_group -from zarr.n5 import N5Store, N5FSStore -from zarr.storage import ( +from zarr.v2.errors import CopyError, MetadataError +from zarr.v2.hierarchy import Group, group, open_group +from zarr.v2.n5 import N5Store, N5FSStore +from zarr.v2.storage import ( ABSStore, DBMStore, DictStore, @@ -47,7 +47,7 @@ TempStore, ZipStore, ) -from zarr.sync import ProcessSynchronizer, ThreadSynchronizer +from zarr.v2.sync import ProcessSynchronizer, ThreadSynchronizer from zarr._version import version as __version__ # in case setuptools scm screw up and find version to be 0.0.0 diff --git a/src/zarr/_storage/__init__.py b/src/zarr/v2/_storage/__init__.py similarity index 100% rename from src/zarr/_storage/__init__.py rename to src/zarr/v2/_storage/__init__.py diff --git a/src/zarr/_storage/absstore.py b/src/zarr/v2/_storage/absstore.py similarity index 98% rename from src/zarr/_storage/absstore.py rename to src/zarr/v2/_storage/absstore.py index d8e292535c..ee03d44bd4 100644 --- a/src/zarr/_storage/absstore.py +++ b/src/zarr/v2/_storage/absstore.py @@ -2,8 +2,8 @@ import warnings from numcodecs.compat import ensure_bytes -from zarr.util import normalize_storage_path -from zarr._storage.store import Store +from zarr.v2.util import normalize_storage_path +from zarr.v2._storage.store import Store __doctest_requires__ = { ("ABSStore", "ABSStore.*"): ["azure.storage.blob"], diff --git a/src/zarr/_storage/store.py b/src/zarr/v2/_storage/store.py similarity index 96% rename from src/zarr/_storage/store.py rename to src/zarr/v2/_storage/store.py index 6e13b08cc7..ec1dbf0565 100644 --- a/src/zarr/_storage/store.py +++ b/src/zarr/v2/_storage/store.py @@ -1,9 +1,9 @@ from collections.abc import MutableMapping from typing import Any, List, Mapping, Optional, Sequence, Union -from zarr.meta import Metadata2 -from zarr.util import normalize_storage_path -from zarr.context import Context +from zarr.v2.meta import Metadata2 +from zarr.v2.util import normalize_storage_path +from zarr.v2.context import Context # v2 store keys @@ -83,7 +83,7 @@ def _ensure_store(store: Any): We'll do this conversion in a few places automatically """ - from zarr.storage import KVStore # avoid circular import + from zarr.v2.storage import KVStore # avoid circular import if isinstance(store, BaseStore): if not store._store_version == 2: @@ -111,7 +111,7 @@ def _ensure_store(store: Any): raise ValueError( "Starting with Zarr 2.11.0, stores must be subclasses of " "BaseStore, if your store exposes the MutableMapping interface " - f"wrap it in Zarr.storage.KVStore. Got {store}" + f"wrap it in zarr.v2.storage.KVStore. Got {store}" ) def getitems( diff --git a/src/zarr/attrs.py b/src/zarr/v2/attrs.py similarity index 98% rename from src/zarr/attrs.py rename to src/zarr/v2/attrs.py index 89cfefc22e..af23d43b9e 100644 --- a/src/zarr/attrs.py +++ b/src/zarr/v2/attrs.py @@ -2,8 +2,8 @@ import warnings from collections.abc import MutableMapping -from zarr._storage.store import Store -from zarr.util import json_dumps +from zarr.v2._storage.store import Store +from zarr.v2.util import json_dumps class Attributes(MutableMapping[str, Any]): diff --git a/src/zarr/codecs.py b/src/zarr/v2/codecs.py similarity index 100% rename from src/zarr/codecs.py rename to src/zarr/v2/codecs.py diff --git a/src/zarr/context.py b/src/zarr/v2/context.py similarity index 100% rename from src/zarr/context.py rename to src/zarr/v2/context.py diff --git a/src/zarr/convenience.py b/src/zarr/v2/convenience.py similarity index 91% rename from src/zarr/convenience.py rename to src/zarr/v2/convenience.py index e4bbade527..6355a11af9 100644 --- a/src/zarr/convenience.py +++ b/src/zarr/v2/convenience.py @@ -4,22 +4,22 @@ import os import re from collections.abc import Mapping, MutableMapping -from zarr.core import Array -from zarr.creation import array as _create_array -from zarr.creation import open_array -from zarr.errors import CopyError, PathNotFoundError -from zarr.hierarchy import Group -from zarr.hierarchy import group as _create_group -from zarr.hierarchy import open_group -from zarr.meta import json_dumps, json_loads -from zarr.storage import ( +from zarr.v2.core import Array +from zarr.v2.creation import array as _create_array +from zarr.v2.creation import open_array +from zarr.v2.errors import CopyError, PathNotFoundError +from zarr.v2.hierarchy import Group +from zarr.v2.hierarchy import group as _create_group +from zarr.v2.hierarchy import open_group +from zarr.v2.meta import json_dumps, json_loads +from zarr.v2.storage import ( contains_array, contains_group, normalize_store_arg, BaseStore, ConsolidatedMetadataStore, ) -from zarr.util import TreeViewer, buffer_size, normalize_storage_path +from zarr.v2.util import TreeViewer, buffer_size, normalize_storage_path from typing import Any, Union @@ -50,17 +50,17 @@ def open(store: StoreLike = None, mode: str = "a", *, path=None, **kwargs): path : str or None, optional The path within the store to open. **kwargs - Additional parameters are passed through to :func:`zarr.creation.open_array` or - :func:`zarr.hierarchy.open_group`. + Additional parameters are passed through to :func:`zarr.v2.creation.open_array` or + :func:`zarr.v2.hierarchy.open_group`. Returns ------- - z : :class:`zarr.core.Array` or :class:`zarr.hierarchy.Group` + z : :class:`zarr.v2.core.Array` or :class:`zarr.v2.hierarchy.Group` Array or group, depending on what exists in the given store. See Also -------- - zarr.creation.open_array, zarr.hierarchy.open_group + zarr.v2.creation.open_array, zarr.v2.hierarchy.open_group Examples -------- @@ -69,24 +69,24 @@ def open(store: StoreLike = None, mode: str = "a", *, path=None, **kwargs): >>> import zarr >>> store = 'data/example.zarr' - >>> zw = zarr.open(store, mode='w', shape=100, dtype='i4') # open new array + >>> zw = zarr.v2.open(store, mode='w', shape=100, dtype='i4') # open new array >>> zw - - >>> za = zarr.open(store, mode='a') # open existing array for reading and writing + + >>> za = zarr.v2.open(store, mode='a') # open existing array for reading and writing >>> za - - >>> zr = zarr.open(store, mode='r') # open existing array read-only + + >>> zr = zarr.v2.open(store, mode='r') # open existing array read-only >>> zr - - >>> gw = zarr.open(store, mode='w') # open new group, overwriting previous data + + >>> gw = zarr.v2.open(store, mode='w') # open new group, overwriting previous data >>> gw - - >>> ga = zarr.open(store, mode='a') # open existing group for reading and writing + + >>> ga = zarr.v2.open(store, mode='a') # open existing group for reading and writing >>> ga - - >>> gr = zarr.open(store, mode='r') # open existing group read-only + + >>> gr = zarr.v2.open(store, mode='r') # open existing group read-only >>> gr - + """ @@ -147,14 +147,14 @@ def save_array(store: StoreLike, arr, *, path=None, **kwargs): >>> import zarr >>> import numpy as np >>> arr = np.arange(10000) - >>> zarr.save_array('data/example.zarr', arr) - >>> zarr.load('data/example.zarr') + >>> zarr.v2.save_array('data/example.zarr', arr) + >>> zarr.v2.load('data/example.zarr') array([ 0, 1, 2, ..., 9997, 9998, 9999]) Save an array to a single file (uses a :class:`ZipStore`):: - >>> zarr.save_array('data/example.zip', arr) - >>> zarr.load('data/example.zip') + >>> zarr.v2.save_array('data/example.zip', arr) + >>> zarr.v2.load('data/example.zip') array([ 0, 1, 2, ..., 9997, 9998, 9999]) """ @@ -193,8 +193,8 @@ def save_group(store: StoreLike, *args, path=None, **kwargs): >>> import numpy as np >>> a1 = np.arange(10000) >>> a2 = np.arange(10000, 0, -1) - >>> zarr.save_group('data/example.zarr', a1, a2) - >>> loader = zarr.load('data/example.zarr') + >>> zarr.v2.save_group('data/example.zarr', a1, a2) + >>> loader = zarr.v2.load('data/example.zarr') >>> loader >>> loader['arr_0'] @@ -204,8 +204,8 @@ def save_group(store: StoreLike, *args, path=None, **kwargs): Save several arrays using named keyword arguments:: - >>> zarr.save_group('data/example.zarr', foo=a1, bar=a2) - >>> loader = zarr.load('data/example.zarr') + >>> zarr.v2.save_group('data/example.zarr', foo=a1, bar=a2) + >>> loader = zarr.v2.load('data/example.zarr') >>> loader >>> loader['foo'] @@ -215,8 +215,8 @@ def save_group(store: StoreLike, *args, path=None, **kwargs): Store several arrays in a single zip file (uses a :class:`ZipStore`):: - >>> zarr.save_group('data/example.zip', foo=a1, bar=a2) - >>> loader = zarr.load('data/example.zip') + >>> zarr.v2.save_group('data/example.zip', foo=a1, bar=a2) + >>> loader = zarr.v2.load('data/example.zip') >>> loader >>> loader['foo'] @@ -269,14 +269,14 @@ def save(store: StoreLike, *args, path=None, **kwargs): >>> import zarr >>> import numpy as np >>> arr = np.arange(10000) - >>> zarr.save('data/example.zarr', arr) - >>> zarr.load('data/example.zarr') + >>> zarr.v2.save('data/example.zarr', arr) + >>> zarr.v2.load('data/example.zarr') array([ 0, 1, 2, ..., 9997, 9998, 9999]) Save an array to a Zip file (uses a :class:`ZipStore`):: - >>> zarr.save('data/example.zip', arr) - >>> zarr.load('data/example.zip') + >>> zarr.v2.save('data/example.zip', arr) + >>> zarr.v2.load('data/example.zip') array([ 0, 1, 2, ..., 9997, 9998, 9999]) Save several arrays to a directory on the file system (uses a @@ -286,8 +286,8 @@ def save(store: StoreLike, *args, path=None, **kwargs): >>> import numpy as np >>> a1 = np.arange(10000) >>> a2 = np.arange(10000, 0, -1) - >>> zarr.save('data/example.zarr', a1, a2) - >>> loader = zarr.load('data/example.zarr') + >>> zarr.v2.save('data/example.zarr', a1, a2) + >>> loader = zarr.v2.load('data/example.zarr') >>> loader >>> loader['arr_0'] @@ -297,8 +297,8 @@ def save(store: StoreLike, *args, path=None, **kwargs): Save several arrays using named keyword arguments:: - >>> zarr.save('data/example.zarr', foo=a1, bar=a2) - >>> loader = zarr.load('data/example.zarr') + >>> zarr.v2.save('data/example.zarr', foo=a1, bar=a2) + >>> loader = zarr.v2.load('data/example.zarr') >>> loader >>> loader['foo'] @@ -308,8 +308,8 @@ def save(store: StoreLike, *args, path=None, **kwargs): Store several arrays in a single zip file (uses a :class:`ZipStore`):: - >>> zarr.save('data/example.zip', foo=a1, bar=a2) - >>> loader = zarr.load('data/example.zip') + >>> zarr.v2.save('data/example.zip', foo=a1, bar=a2) + >>> loader = zarr.v2.load('data/example.zip') >>> loader >>> loader['foo'] @@ -413,7 +413,7 @@ def tree(grp, expand=False, level=None): Examples -------- >>> import zarr - >>> g1 = zarr.group() + >>> g1 = zarr.v2.group() >>> g2 = g1.create_group('foo') >>> g3 = g1.create_group('bar') >>> g4 = g3.create_group('baz') @@ -428,9 +428,9 @@ def tree(grp, expand=False, level=None): └── foo >>> import h5py >>> h5f = h5py.File('data/example.h5', mode='w') - >>> zarr.copy_all(g1, h5f) + >>> zarr.v2.copy_all(g1, h5f) (5, 0, 800) - >>> zarr.tree(h5f) + >>> zarr.v2.tree(h5f) / ├── bar │ ├── baz @@ -440,7 +440,7 @@ def tree(grp, expand=False, level=None): See Also -------- - zarr.hierarchy.Group.tree + zarr.v2.hierarchy.Group.tree Notes ----- @@ -564,8 +564,8 @@ def copy_store( -------- >>> import zarr - >>> store1 = zarr.DirectoryStore('data/example.zarr') - >>> root = zarr.group(store1, overwrite=True) + >>> store1 = zarr.v2.DirectoryStore('data/example.zarr') + >>> root = zarr.v2.group(store1, overwrite=True) >>> foo = root.create_group('foo') >>> bar = foo.create_group('bar') >>> baz = bar.create_dataset('baz', shape=100, chunks=50, dtype='i8') @@ -577,8 +577,8 @@ def copy_store( └── bar └── baz (100,) int64 >>> from sys import stdout - >>> store2 = zarr.ZipStore('data/example.zip', mode='w') - >>> zarr.copy_store(store1, store2, log=stdout) + >>> store2 = zarr.v2.ZipStore('data/example.zip', mode='w') + >>> zarr.v2.copy_store(store1, store2, log=stdout) copy .zgroup copy foo/.zgroup copy foo/bar/.zgroup @@ -587,7 +587,7 @@ def copy_store( copy foo/bar/baz/1 all done: 6 copied, 0 skipped, 566 bytes copied (6, 0, 566) - >>> new_root = zarr.group(store2) + >>> new_root = zarr.v2.group(store2) >>> new_root.tree() / └── foo @@ -772,15 +772,15 @@ def copy( >>> foo = source.create_group('foo') >>> baz = foo.create_dataset('bar/baz', data=np.arange(100), chunks=(50,)) >>> spam = source.create_dataset('spam', data=np.arange(100, 200), chunks=(30,)) - >>> zarr.tree(source) + >>> zarr.v2.tree(source) / ├── foo │ └── bar │ └── baz (100,) int64 └── spam (100,) int64 - >>> dest = zarr.group() + >>> dest = zarr.v2.group() >>> from sys import stdout - >>> zarr.copy(source['foo'], dest, log=stdout) + >>> zarr.v2.copy(source['foo'], dest, log=stdout) copy /foo copy /foo/bar copy /foo/bar/baz (100,) int64 @@ -797,29 +797,29 @@ def copy( the destination. Here are some examples of these options, also using ``dry_run=True`` to find out what would happen without actually copying anything:: - >>> source = zarr.group() - >>> dest = zarr.group() + >>> source = zarr.v2.group() + >>> dest = zarr.v2.group() >>> baz = source.create_dataset('foo/bar/baz', data=np.arange(100)) >>> spam = source.create_dataset('foo/spam', data=np.arange(1000)) >>> existing_spam = dest.create_dataset('foo/spam', data=np.arange(1000)) >>> from sys import stdout >>> try: - ... zarr.copy(source['foo'], dest, log=stdout, dry_run=True) - ... except zarr.CopyError as e: + ... zarr.v2.copy(source['foo'], dest, log=stdout, dry_run=True) + ... except zarr.v2.CopyError as e: ... print(e) ... copy /foo copy /foo/bar copy /foo/bar/baz (100,) int64 an object 'spam' already exists in destination '/foo' - >>> zarr.copy(source['foo'], dest, log=stdout, if_exists='replace', dry_run=True) + >>> zarr.v2.copy(source['foo'], dest, log=stdout, if_exists='replace', dry_run=True) copy /foo copy /foo/bar copy /foo/bar/baz (100,) int64 copy /foo/spam (1000,) int64 dry run: 4 copied, 0 skipped (4, 0, 0) - >>> zarr.copy(source['foo'], dest, log=stdout, if_exists='skip', dry_run=True) + >>> zarr.v2.copy(source['foo'], dest, log=stdout, if_exists='skip', dry_run=True) copy /foo copy /foo/bar copy /foo/bar/baz (100,) int64 @@ -1104,15 +1104,15 @@ def copy_all( >>> foo = source.create_group('foo') >>> baz = foo.create_dataset('bar/baz', data=np.arange(100), chunks=(50,)) >>> spam = source.create_dataset('spam', data=np.arange(100, 200), chunks=(30,)) - >>> zarr.tree(source) + >>> zarr.v2.tree(source) / ├── foo │ └── bar │ └── baz (100,) int64 └── spam (100,) int64 - >>> dest = zarr.group() + >>> dest = zarr.v2.group() >>> import sys - >>> zarr.copy_all(source, dest, log=sys.stdout) + >>> zarr.v2.copy_all(source, dest, log=sys.stdout) copy /foo copy /foo/bar copy /foo/bar/baz (100,) int64 @@ -1197,7 +1197,7 @@ def consolidate_metadata(store: BaseStore, metadata_key=".zmetadata", *, path="" Returns ------- - g : :class:`zarr.hierarchy.Group` + g : :class:`zarr.v2.hierarchy.Group` Group instance, opened with the new consolidated metadata. See Also @@ -1252,12 +1252,12 @@ def open_consolidated(store: StoreLike, metadata_key=".zmetadata", mode="r+", ** changes to metadata including creation of new arrays or group are not allowed. **kwargs - Additional parameters are passed through to :func:`zarr.creation.open_array` or - :func:`zarr.hierarchy.open_group`. + Additional parameters are passed through to :func:`zarr.v2.creation.open_array` or + :func:`zarr.v2.hierarchy.open_group`. Returns ------- - g : :class:`zarr.hierarchy.Group` + g : :class:`zarr.v2.hierarchy.Group` Group instance, opened with the consolidated metadata. See Also diff --git a/src/zarr/core.py b/src/zarr/v2/core.py similarity index 97% rename from src/zarr/core.py rename to src/zarr/v2/core.py index 06dcb32063..273d2857e8 100644 --- a/src/zarr/core.py +++ b/src/zarr/v2/core.py @@ -10,12 +10,12 @@ import numpy as np from numcodecs.compat import ensure_bytes -from zarr._storage.store import _prefix_to_attrs_key -from zarr.attrs import Attributes -from zarr.codecs import AsType, get_codec -from zarr.context import Context -from zarr.errors import ArrayNotFoundError, ReadOnlyError, ArrayIndexError -from zarr.indexing import ( +from zarr.v2._storage.store import _prefix_to_attrs_key +from zarr.v2.attrs import Attributes +from zarr.v2.codecs import AsType, get_codec +from zarr.v2.context import Context +from zarr.v2.errors import ArrayNotFoundError, ReadOnlyError, ArrayIndexError +from zarr.v2.indexing import ( BasicIndexer, CoordinateIndexer, MaskIndexer, @@ -35,14 +35,14 @@ is_scalar, pop_fields, ) -from zarr.storage import ( +from zarr.v2.storage import ( _prefix_to_array_key, KVStore, getsize, listdir, normalize_store_arg, ) -from zarr.util import ( +from zarr.v2.util import ( ConstantMap, UncompressedPartialReadBufferV3, all_equal, @@ -535,7 +535,7 @@ def islice(self, start=None, end=None): >>> import zarr >>> import numpy as np - >>> z = zarr.array(np.arange(100)) + >>> z = zarr.v2.array(np.arange(100)) Iterate over part of the array: >>> for value in z.islice(25, 30): value; @@ -604,7 +604,7 @@ def __getitem__(self, selection): >>> import zarr >>> import numpy as np - >>> z = zarr.array(np.arange(100)) + >>> z = zarr.v2.array(np.arange(100)) Retrieve a single item:: @@ -631,7 +631,7 @@ def __getitem__(self, selection): Setup a 2-dimensional array:: - >>> z = zarr.array(np.arange(100).reshape(10, 10)) + >>> z = zarr.v2.array(np.arange(100).reshape(10, 10)) Retrieve an item:: @@ -688,7 +688,7 @@ def __getitem__(self, selection): ... (b'bbb', 2, 8.4), ... (b'ccc', 3, 12.6)], ... dtype=[('foo', 'S3'), ('bar', 'i4'), ('baz', 'f8')]) - >>> z = zarr.array(a) + >>> z = zarr.v2.array(a) >>> z['foo'] array([b'aaa', b'bbb', b'ccc'], dtype='|S3') @@ -755,7 +755,7 @@ def get_basic_selection(self, selection=Ellipsis, out=None, fields=None): >>> import zarr >>> import numpy as np - >>> z = zarr.array(np.arange(100)) + >>> z = zarr.v2.array(np.arange(100)) Retrieve a single item:: @@ -777,7 +777,7 @@ def get_basic_selection(self, selection=Ellipsis, out=None, fields=None): Setup a 2-dimensional array:: - >>> z = zarr.array(np.arange(100).reshape(10, 10)) + >>> z = zarr.v2.array(np.arange(100).reshape(10, 10)) Retrieve an item:: @@ -820,7 +820,7 @@ def get_basic_selection(self, selection=Ellipsis, out=None, fields=None): ... (b'bbb', 2, 8.4), ... (b'ccc', 3, 12.6)], ... dtype=[('foo', 'S3'), ('bar', 'i4'), ('baz', 'f8')]) - >>> z = zarr.array(a) + >>> z = zarr.v2.array(a) >>> z.get_basic_selection(slice(2), fields='foo') array([b'aaa', b'bbb'], dtype='|S3') @@ -926,7 +926,7 @@ def get_orthogonal_selection(self, selection, out=None, fields=None): >>> import zarr >>> import numpy as np - >>> z = zarr.array(np.arange(100).reshape(10, 10)) + >>> z = zarr.v2.array(np.arange(100).reshape(10, 10)) Retrieve rows and columns via any combination of int, slice, integer array and/or Boolean array:: @@ -1034,7 +1034,7 @@ def get_coordinate_selection(self, selection, out=None, fields=None): >>> import zarr >>> import numpy as np - >>> z = zarr.array(np.arange(100).reshape(10, 10)) + >>> z = zarr.v2.array(np.arange(100).reshape(10, 10)) Retrieve items by specifying their coordinates:: @@ -1115,7 +1115,7 @@ def get_block_selection(self, selection, out=None, fields=None): >>> import zarr >>> import numpy as np - >>> z = zarr.array(np.arange(100).reshape(10, 10), chunks=(3, 3)) + >>> z = zarr.v2.array(np.arange(100).reshape(10, 10), chunks=(3, 3)) Retrieve items by specifying their block coordinates:: @@ -1201,7 +1201,7 @@ def get_mask_selection(self, selection, out=None, fields=None): >>> import zarr >>> import numpy as np - >>> z = zarr.array(np.arange(100).reshape(10, 10)) + >>> z = zarr.v2.array(np.arange(100).reshape(10, 10)) Retrieve items by specifying a mask:: @@ -1299,7 +1299,7 @@ def __setitem__(self, selection, value): Setup a 1-dimensional array:: >>> import zarr - >>> z = zarr.zeros(100, dtype=int) + >>> z = zarr.v2.zeros(100, dtype=int) Set all array elements to the same scalar value:: @@ -1316,7 +1316,7 @@ def __setitem__(self, selection, value): Setup a 2-dimensional array:: - >>> z = zarr.zeros((5, 5), dtype=int) + >>> z = zarr.v2.zeros((5, 5), dtype=int) Set all array elements to the same scalar value:: @@ -1339,7 +1339,7 @@ def __setitem__(self, selection, value): ... (b'bbb', 2, 8.4), ... (b'ccc', 3, 12.6)], ... dtype=[('foo', 'S3'), ('bar', 'i4'), ('baz', 'f8')]) - >>> z = zarr.array(a) + >>> z = zarr.v2.array(a) >>> z['foo'] = b'zzz' >>> z[...] array([(b'zzz', 1, 4.2), (b'zzz', 2, 8.4), (b'zzz', 3, 12.6)], @@ -1401,7 +1401,7 @@ def set_basic_selection(self, selection, value, fields=None): >>> import zarr >>> import numpy as np - >>> z = zarr.zeros(100, dtype=int) + >>> z = zarr.v2.zeros(100, dtype=int) Set all array elements to the same scalar value:: @@ -1418,7 +1418,7 @@ def set_basic_selection(self, selection, value, fields=None): Setup a 2-dimensional array:: - >>> z = zarr.zeros((5, 5), dtype=int) + >>> z = zarr.v2.zeros((5, 5), dtype=int) Set all array elements to the same scalar value:: @@ -1442,7 +1442,7 @@ def set_basic_selection(self, selection, value, fields=None): ... (b'bbb', 2, 8.4), ... (b'ccc', 3, 12.6)], ... dtype=[('foo', 'S3'), ('bar', 'i4'), ('baz', 'f8')]) - >>> z = zarr.array(a) + >>> z = zarr.v2.array(a) >>> z.set_basic_selection(slice(0, 2), b'zzz', fields='foo') >>> z[:] array([(b'zzz', 1, 4.2), (b'zzz', 2, 8.4), (b'ccc', 3, 12.6)], @@ -1497,7 +1497,7 @@ def set_orthogonal_selection(self, selection, value, fields=None): >>> import zarr >>> import numpy as np - >>> z = zarr.zeros((5, 5), dtype=int) + >>> z = zarr.v2.zeros((5, 5), dtype=int) Set data for a selection of rows:: @@ -1588,7 +1588,7 @@ def set_coordinate_selection(self, selection, value, fields=None): >>> import zarr >>> import numpy as np - >>> z = zarr.zeros((5, 5), dtype=int) + >>> z = zarr.v2.zeros((5, 5), dtype=int) Set data for a selection of items:: @@ -1671,7 +1671,7 @@ def set_block_selection(self, selection, value, fields=None): >>> import zarr >>> import numpy as np - >>> z = zarr.zeros((6, 6), dtype=int, chunks=2) + >>> z = zarr.v2.zeros((6, 6), dtype=int, chunks=2) Set data for a selection of items:: @@ -1756,7 +1756,7 @@ def set_mask_selection(self, selection, value, fields=None): >>> import zarr >>> import numpy as np - >>> z = zarr.zeros((5, 5), dtype=int) + >>> z = zarr.v2.zeros((5, 5), dtype=int) Set data for a selection of items:: @@ -2323,16 +2323,16 @@ def info(self): Examples -------- >>> import zarr - >>> z = zarr.zeros(1000000, chunks=100000, dtype='i4') + >>> z = zarr.v2.zeros(1000000, chunks=100000, dtype='i4') >>> z.info - Type : zarr.core.Array + Type : zarr.v2.core.Array Data type : int32 Shape : (1000000,) Chunk shape : (100000,) Order : C Read-only : False Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0) - Store type : zarr.storage.KVStore + Store type : zarr.v2.storage.KVStore No. bytes : 4000000 (3.8M) No. bytes stored : 320 Storage ratio : 12500.0 @@ -2402,13 +2402,13 @@ def digest(self, hashname="sha1"): -------- >>> import binascii >>> import zarr - >>> z = zarr.empty(shape=(10000, 10000), chunks=(1000, 1000)) + >>> z = zarr.v2.empty(shape=(10000, 10000), chunks=(1000, 1000)) >>> binascii.hexlify(z.digest()) b'041f90bc7a571452af4f850a8ca2c6cddfa8a1ac' - >>> z = zarr.zeros(shape=(10000, 10000), chunks=(1000, 1000)) + >>> z = zarr.v2.zeros(shape=(10000, 10000), chunks=(1000, 1000)) >>> binascii.hexlify(z.digest()) b'7162d416d26a68063b66ed1f30e0a866e4abed60' - >>> z = zarr.zeros(shape=(10000, 10000), dtype="u1", chunks=(1000, 1000)) + >>> z = zarr.v2.zeros(shape=(10000, 10000), dtype="u1", chunks=(1000, 1000)) >>> binascii.hexlify(z.digest()) b'cb387af37410ae5a3222e893cf3373e4e4f22816' """ @@ -2434,13 +2434,13 @@ def hexdigest(self, hashname="sha1"): Examples -------- >>> import zarr - >>> z = zarr.empty(shape=(10000, 10000), chunks=(1000, 1000)) + >>> z = zarr.v2.empty(shape=(10000, 10000), chunks=(1000, 1000)) >>> z.hexdigest() '041f90bc7a571452af4f850a8ca2c6cddfa8a1ac' - >>> z = zarr.zeros(shape=(10000, 10000), chunks=(1000, 1000)) + >>> z = zarr.v2.zeros(shape=(10000, 10000), chunks=(1000, 1000)) >>> z.hexdigest() '7162d416d26a68063b66ed1f30e0a866e4abed60' - >>> z = zarr.zeros(shape=(10000, 10000), dtype="u1", chunks=(1000, 1000)) + >>> z = zarr.v2.zeros(shape=(10000, 10000), dtype="u1", chunks=(1000, 1000)) >>> z.hexdigest() 'cb387af37410ae5a3222e893cf3373e4e4f22816' """ @@ -2500,7 +2500,7 @@ def resize(self, *args): Examples -------- >>> import zarr - >>> z = zarr.zeros(shape=(10000, 10000), chunks=(1000, 1000)) + >>> z = zarr.v2.zeros(shape=(10000, 10000), chunks=(1000, 1000)) >>> z.shape (10000, 10000) >>> z.resize(20000, 10000) @@ -2590,7 +2590,7 @@ def append(self, data, axis=0): >>> import numpy as np >>> import zarr >>> a = np.arange(10000000, dtype='i4').reshape(10000, 1000) - >>> z = zarr.array(a, chunks=(1000, 100)) + >>> z = zarr.v2.array(a, chunks=(1000, 100)) >>> z.shape (10000, 1000) >>> z.append(a) @@ -2686,10 +2686,10 @@ def view( >>> np.random.seed(42) >>> labels = ['female', 'male'] >>> data = np.random.choice(labels, size=10000) - >>> filters = [zarr.Categorize(labels=labels, + >>> filters = [zarr.v2.Categorize(labels=labels, ... dtype=data.dtype, ... astype='u1')] - >>> a = zarr.array(data, chunks=1000, filters=filters) + >>> a = zarr.v2.array(data, chunks=1000, filters=filters) >>> a[:] array(['female', 'male', 'female', ..., 'male', 'male', 'female'], dtype='>> data = np.random.randint(0, 2, size=10000, dtype='u1') - >>> a = zarr.array(data, chunks=1000) + >>> a = zarr.v2.array(data, chunks=1000) >>> a[:] array([0, 0, 1, ..., 1, 0, 0], dtype=uint8) >>> v = a.view(dtype=bool) @@ -2727,7 +2727,7 @@ def view( data is interpreted correctly: >>> data = np.arange(10000, dtype='u2') - >>> a = zarr.array(data, chunks=1000) + >>> a = zarr.v2.array(data, chunks=1000) >>> a[:10] array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=uint16) >>> v = a.view(dtype='u1', shape=20000, chunks=2000) @@ -2738,7 +2738,7 @@ def view( Change fill value for uninitialized chunks: - >>> a = zarr.full(10000, chunks=1000, fill_value=-1, dtype='i1') + >>> a = zarr.v2.full(10000, chunks=1000, fill_value=-1, dtype='i1') >>> a[:] array([-1, -1, -1, ..., -1, -1, -1], dtype=int8) >>> v = a.view(fill_value=42) @@ -2747,7 +2747,7 @@ def view( Note that resizing or appending to views is not permitted: - >>> a = zarr.empty(10000) + >>> a = zarr.v2.empty(10000) >>> v = a.view() >>> try: ... v.resize(20000) @@ -2820,7 +2820,7 @@ def astype(self, dtype): >>> import zarr >>> import numpy as np >>> data = np.arange(100, dtype=np.uint8) - >>> a = zarr.array(data, chunks=10) + >>> a = zarr.v2.array(data, chunks=10) >>> a[:] array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, diff --git a/src/zarr/creation.py b/src/zarr/v2/creation.py similarity index 92% rename from src/zarr/creation.py rename to src/zarr/v2/creation.py index c93178c0e7..d0ba00603d 100644 --- a/src/zarr/creation.py +++ b/src/zarr/v2/creation.py @@ -4,13 +4,13 @@ import numpy as np from numcodecs.registry import codec_registry -from zarr.core import Array -from zarr.errors import ( +from zarr.v2.core import Array +from zarr.v2.errors import ( ArrayNotFoundError, ContainsArrayError, ContainsGroupError, ) -from zarr.storage import ( +from zarr.v2.storage import ( contains_array, contains_group, default_compressor, @@ -18,7 +18,7 @@ normalize_storage_path, normalize_store_arg, ) -from zarr.util import normalize_dimension_separator +from zarr.v2.util import normalize_dimension_separator def create( @@ -114,7 +114,7 @@ def create( Returns ------- - z : zarr.core.Array + z : zarr.v2.core.Array Examples -------- @@ -122,37 +122,37 @@ def create( Create an array with default settings:: >>> import zarr - >>> z = zarr.create((10000, 10000), chunks=(1000, 1000)) + >>> z = zarr.v2.create((10000, 10000), chunks=(1000, 1000)) >>> z - + Create an array with different some different configuration options:: >>> from numcodecs import Blosc >>> compressor = Blosc(cname='zstd', clevel=1, shuffle=Blosc.BITSHUFFLE) - >>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype='i1', order='F', + >>> z = zarr.v2.create((10000, 10000), chunks=(1000, 1000), dtype='i1', order='F', ... compressor=compressor) >>> z - + To create an array with object dtype requires a filter that can handle Python object encoding, e.g., `MsgPack` or `Pickle` from `numcodecs`:: >>> from numcodecs import MsgPack - >>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype=object, + >>> z = zarr.v2.create((10000, 10000), chunks=(1000, 1000), dtype=object, ... object_codec=MsgPack()) >>> z - + Example with some filters, and also storing chunks separately from metadata:: >>> from numcodecs import Quantize, Adler32 >>> store, chunk_store = dict(), dict() - >>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype='f8', + >>> z = zarr.v2.create((10000, 10000), chunks=(1000, 1000), dtype='f8', ... filters=[Quantize(digits=2, dtype='f8'), Adler32()], ... store=store, chunk_store=chunk_store) >>> z - + """ @@ -274,7 +274,7 @@ def _kwargs_compat(compressor, fill_value, kwargs): def empty(shape, **kwargs): """Create an empty array. - For parameter definitions see :func:`zarr.creation.create`. + For parameter definitions see :func:`zarr.v2.creation.create`. Notes ----- @@ -290,14 +290,14 @@ def zeros(shape, **kwargs): """Create an array, with zero being used as the default value for uninitialized portions of the array. - For parameter definitions see :func:`zarr.creation.create`. + For parameter definitions see :func:`zarr.v2.creation.create`. Examples -------- >>> import zarr - >>> z = zarr.zeros((10000, 10000), chunks=(1000, 1000)) + >>> z = zarr.v2.zeros((10000, 10000), chunks=(1000, 1000)) >>> z - + >>> z[:2, :2] array([[0., 0.], [0., 0.]]) @@ -311,14 +311,14 @@ def ones(shape, **kwargs): """Create an array, with one being used as the default value for uninitialized portions of the array. - For parameter definitions see :func:`zarr.creation.create`. + For parameter definitions see :func:`zarr.v2.creation.create`. Examples -------- >>> import zarr - >>> z = zarr.ones((10000, 10000), chunks=(1000, 1000)) + >>> z = zarr.v2.ones((10000, 10000), chunks=(1000, 1000)) >>> z - + >>> z[:2, :2] array([[1., 1.], [1., 1.]]) @@ -332,14 +332,14 @@ def full(shape, fill_value, **kwargs): """Create an array, with `fill_value` being used as the default value for uninitialized portions of the array. - For parameter definitions see :func:`zarr.creation.create`. + For parameter definitions see :func:`zarr.v2.creation.create`. Examples -------- >>> import zarr - >>> z = zarr.full((10000, 10000), chunks=(1000, 1000), fill_value=42) + >>> z = zarr.v2.full((10000, 10000), chunks=(1000, 1000), fill_value=42) >>> z - + >>> z[:2, :2] array([[42., 42.], [42., 42.]]) @@ -370,16 +370,16 @@ def array(data, **kwargs): """Create an array filled with `data`. The `data` argument should be a NumPy array or array-like object. For - other parameter definitions see :func:`zarr.creation.create`. + other parameter definitions see :func:`zarr.v2.creation.create`. Examples -------- >>> import numpy as np >>> import zarr >>> a = np.arange(100000000).reshape(10000, 10000) - >>> z = zarr.array(a, chunks=(1000, 1000)) + >>> z = zarr.v2.array(a, chunks=(1000, 1000)) >>> z - + """ @@ -517,20 +517,20 @@ def open_array( Returns ------- - z : zarr.core.Array + z : zarr.v2.core.Array Examples -------- >>> import numpy as np >>> import zarr - >>> z1 = zarr.open_array('data/example.zarr', mode='w', shape=(10000, 10000), + >>> z1 = zarr.v2.open_array('data/example.zarr', mode='w', shape=(10000, 10000), ... chunks=(1000, 1000), fill_value=0) >>> z1[:] = np.arange(100000000).reshape(10000, 10000) >>> z1 - - >>> z2 = zarr.open_array('data/example.zarr', mode='r') + + >>> z2 = zarr.v2.open_array('data/example.zarr', mode='r') >>> z2 - + >>> np.all(z1[:] == z2[:]) True diff --git a/src/zarr/errors.py b/src/zarr/v2/errors.py similarity index 100% rename from src/zarr/errors.py rename to src/zarr/v2/errors.py diff --git a/src/zarr/hierarchy.py b/src/zarr/v2/hierarchy.py similarity index 93% rename from src/zarr/hierarchy.py rename to src/zarr/v2/hierarchy.py index 9044c1681e..acd65750e3 100644 --- a/src/zarr/hierarchy.py +++ b/src/zarr/v2/hierarchy.py @@ -4,9 +4,9 @@ import numpy as np -from zarr.attrs import Attributes -from zarr.core import Array -from zarr.creation import ( +from zarr.v2.attrs import Attributes +from zarr.v2.core import Array +from zarr.v2.creation import ( array, create, empty, @@ -18,13 +18,13 @@ zeros, zeros_like, ) -from zarr.errors import ( +from zarr.v2.errors import ( ContainsArrayError, ContainsGroupError, GroupNotFoundError, ReadOnlyError, ) -from zarr.storage import ( +from zarr.v2.storage import ( _prefix_to_group_key, BaseStore, MemoryStore, @@ -39,7 +39,7 @@ rmdir, ) -from zarr.util import ( +from zarr.v2.util import ( InfoReporter, TreeViewer, is_valid_python_name, @@ -259,7 +259,7 @@ def __iter__(self): Examples -------- >>> import zarr - >>> g1 = zarr.group() + >>> g1 = zarr.v2.group() >>> g2 = g1.create_group('foo') >>> g3 = g1.create_group('bar') >>> d1 = g1.create_dataset('baz', shape=100, chunks=10) @@ -363,7 +363,7 @@ def __contains__(self, item): Examples -------- >>> import zarr - >>> g1 = zarr.group() + >>> g1 = zarr.v2.group() >>> g2 = g1.create_group('foo') >>> d1 = g1.create_dataset('bar', shape=100, chunks=10) >>> 'foo' in g1 @@ -390,14 +390,14 @@ def __getitem__(self, item): Examples -------- >>> import zarr - >>> g1 = zarr.group() + >>> g1 = zarr.v2.group() >>> d1 = g1.create_dataset('foo/bar/baz', shape=100, chunks=10) >>> g1['foo'] - + >>> g1['foo/bar'] - + >>> g1['foo/bar/baz'] - + """ path = self._item_path(item) @@ -462,7 +462,7 @@ def group_keys(self): Examples -------- >>> import zarr - >>> g1 = zarr.group() + >>> g1 = zarr.v2.group() >>> g2 = g1.create_group('foo') >>> g3 = g1.create_group('bar') >>> d1 = g1.create_dataset('baz', shape=100, chunks=10) @@ -483,15 +483,15 @@ def groups(self): Examples -------- >>> import zarr - >>> g1 = zarr.group() + >>> g1 = zarr.v2.group() >>> g2 = g1.create_group('foo') >>> g3 = g1.create_group('bar') >>> d1 = g1.create_dataset('baz', shape=100, chunks=10) >>> d2 = g1.create_dataset('quux', shape=200, chunks=20) >>> for n, v in g1.groups(): ... print(n, type(v)) - bar - foo + bar + foo """ @@ -523,7 +523,7 @@ def array_keys(self, recurse=False): Examples -------- >>> import zarr - >>> g1 = zarr.group() + >>> g1 = zarr.v2.group() >>> g2 = g1.create_group('foo') >>> g3 = g1.create_group('bar') >>> d1 = g1.create_dataset('baz', shape=100, chunks=10) @@ -547,15 +547,15 @@ def arrays(self, recurse=False): Examples -------- >>> import zarr - >>> g1 = zarr.group() + >>> g1 = zarr.v2.group() >>> g2 = g1.create_group('foo') >>> g3 = g1.create_group('bar') >>> d1 = g1.create_dataset('baz', shape=100, chunks=10) >>> d2 = g1.create_dataset('quux', shape=200, chunks=20) >>> for n, v in g1.arrays(): ... print(n, type(v)) - baz - quux + baz + quux """ return self._array_iter(keys_only=False, method="arrays", recurse=recurse) @@ -580,7 +580,7 @@ def visitvalues(self, func): Examples -------- >>> import zarr - >>> g1 = zarr.group() + >>> g1 = zarr.v2.group() >>> g2 = g1.create_group('foo') >>> g3 = g1.create_group('bar') >>> g4 = g3.create_group('baz') @@ -588,13 +588,13 @@ def visitvalues(self, func): >>> def print_visitor(obj): ... print(obj) >>> g1.visitvalues(print_visitor) - - - - + + + + >>> g3.visitvalues(print_visitor) - - + + """ @@ -619,7 +619,7 @@ def visit(self, func): Examples -------- >>> import zarr - >>> g1 = zarr.group() + >>> g1 = zarr.v2.group() >>> g2 = g1.create_group('foo') >>> g3 = g1.create_group('bar') >>> g4 = g3.create_group('baz') @@ -649,11 +649,11 @@ def visit(self, func): It is created as follows: - >>> root = zarr.group() + >>> root = zarr.v2.group() >>> foo = root.create_group("foo") >>> bar = root.create_group("bar") >>> root.create_group("aaa").create_group("bbb").create_group("ccc").create_group("aaa") - + For ``find``, the first path that matches a given pattern (for example "aaa") is returned. Note that a non-None value is returned in the visit @@ -725,7 +725,7 @@ def visititems(self, func): Examples -------- >>> import zarr - >>> g1 = zarr.group() + >>> g1 = zarr.v2.group() >>> g2 = g1.create_group('foo') >>> g3 = g1.create_group('bar') >>> g4 = g3.create_group('baz') @@ -733,13 +733,13 @@ def visititems(self, func): >>> def print_visitor(name, obj): ... print((name, obj)) >>> g1.visititems(print_visitor) - ('bar', ) - ('bar/baz', ) - ('bar/quux', ) - ('foo', ) + ('bar', ) + ('bar/baz', ) + ('bar/quux', ) + ('foo', ) >>> g3.visititems(print_visitor) - ('baz', ) - ('quux', ) + ('baz', ) + ('quux', ) """ @@ -759,7 +759,7 @@ def tree(self, expand=False, level=None): Examples -------- >>> import zarr - >>> g1 = zarr.group() + >>> g1 = zarr.v2.group() >>> g2 = g1.create_group('foo') >>> g3 = g1.create_group('bar') >>> g4 = g3.create_group('baz') @@ -821,12 +821,12 @@ def create_group(self, name, overwrite=False): Returns ------- - g : zarr.hierarchy.Group + g : zarr.v2.hierarchy.Group Examples -------- >>> import zarr - >>> g1 = zarr.group() + >>> g1 = zarr.v2.group() >>> g2 = g1.create_group('foo') >>> g3 = g1.create_group('bar') >>> g4 = g1.create_group('baz/quux') @@ -866,12 +866,12 @@ def require_group(self, name, overwrite=False): Returns ------- - g : zarr.hierarchy.Group + g : zarr.v2.hierarchy.Group Examples -------- >>> import zarr - >>> g1 = zarr.group() + >>> g1 = zarr.v2.group() >>> g2 = g1.require_group('foo') >>> g3 = g1.require_group('foo') >>> g2 == g3 @@ -929,7 +929,7 @@ def create_dataset(self, name, **kwargs): Default value to use for uninitialized portions of the array. order : {'C', 'F'}, optional Memory layout to be used within each chunk. - synchronizer : zarr.sync.ArraySynchronizer, optional + synchronizer : zarr.v2.sync.ArraySynchronizer, optional Array synchronizer. filters : sequence of Codecs, optional Sequence of filters to use to encode chunk data prior to @@ -946,20 +946,20 @@ def create_dataset(self, name, **kwargs): Returns ------- - a : zarr.core.Array + a : zarr.v2.core.Array Examples -------- >>> import zarr - >>> g1 = zarr.group() + >>> g1 = zarr.v2.group() >>> d1 = g1.create_dataset('foo', shape=(10000, 10000), ... chunks=(1000, 1000)) >>> d1 - + >>> d2 = g1.create_dataset('bar/baz/qux', shape=(100, 100, 100), ... chunks=(100, 10, 10)) >>> d2 - + """ assert "mode" not in kwargs @@ -989,7 +989,7 @@ def require_dataset(self, name, shape, dtype=None, exact=False, **kwargs): Arrays are known as "datasets" in HDF5 terminology. For compatibility with h5py, Zarr groups also implement the create_dataset() method. - Other `kwargs` are as per :func:`zarr.hierarchy.Group.create_dataset`. + Other `kwargs` are as per :func:`zarr.v2.hierarchy.Group.create_dataset`. Parameters ---------- @@ -1049,7 +1049,7 @@ def _require_dataset_nosync(self, name, shape, dtype=None, exact=False, **kwargs def create(self, name, **kwargs): """Create an array. Keyword arguments as per - :func:`zarr.creation.create`.""" + :func:`zarr.v2.creation.create`.""" return self._write_op(self._create_nosync, name, **kwargs) def _create_nosync(self, name, **kwargs): @@ -1060,7 +1060,7 @@ def _create_nosync(self, name, **kwargs): def empty(self, name, **kwargs): """Create an array. Keyword arguments as per - :func:`zarr.creation.empty`.""" + :func:`zarr.v2.creation.empty`.""" return self._write_op(self._empty_nosync, name, **kwargs) def _empty_nosync(self, name, **kwargs): @@ -1071,7 +1071,7 @@ def _empty_nosync(self, name, **kwargs): def zeros(self, name, **kwargs): """Create an array. Keyword arguments as per - :func:`zarr.creation.zeros`.""" + :func:`zarr.v2.creation.zeros`.""" return self._write_op(self._zeros_nosync, name, **kwargs) def _zeros_nosync(self, name, **kwargs): @@ -1082,7 +1082,7 @@ def _zeros_nosync(self, name, **kwargs): def ones(self, name, **kwargs): """Create an array. Keyword arguments as per - :func:`zarr.creation.ones`.""" + :func:`zarr.v2.creation.ones`.""" return self._write_op(self._ones_nosync, name, **kwargs) def _ones_nosync(self, name, **kwargs): @@ -1093,7 +1093,7 @@ def _ones_nosync(self, name, **kwargs): def full(self, name, fill_value, **kwargs): """Create an array. Keyword arguments as per - :func:`zarr.creation.full`.""" + :func:`zarr.v2.creation.full`.""" return self._write_op(self._full_nosync, name, fill_value, **kwargs) def _full_nosync(self, name, fill_value, **kwargs): @@ -1110,7 +1110,7 @@ def _full_nosync(self, name, fill_value, **kwargs): def array(self, name, data, **kwargs): """Create an array. Keyword arguments as per - :func:`zarr.creation.array`.""" + :func:`zarr.v2.creation.array`.""" return self._write_op(self._array_nosync, name, data, **kwargs) def _array_nosync(self, name, data, **kwargs): @@ -1121,7 +1121,7 @@ def _array_nosync(self, name, data, **kwargs): def empty_like(self, name, data, **kwargs): """Create an array. Keyword arguments as per - :func:`zarr.creation.empty_like`.""" + :func:`zarr.v2.creation.empty_like`.""" return self._write_op(self._empty_like_nosync, name, data, **kwargs) def _empty_like_nosync(self, name, data, **kwargs): @@ -1134,7 +1134,7 @@ def _empty_like_nosync(self, name, data, **kwargs): def zeros_like(self, name, data, **kwargs): """Create an array. Keyword arguments as per - :func:`zarr.creation.zeros_like`.""" + :func:`zarr.v2.creation.zeros_like`.""" return self._write_op(self._zeros_like_nosync, name, data, **kwargs) def _zeros_like_nosync(self, name, data, **kwargs): @@ -1147,7 +1147,7 @@ def _zeros_like_nosync(self, name, data, **kwargs): def ones_like(self, name, data, **kwargs): """Create an array. Keyword arguments as per - :func:`zarr.creation.ones_like`.""" + :func:`zarr.v2.creation.ones_like`.""" return self._write_op(self._ones_like_nosync, name, data, **kwargs) def _ones_like_nosync(self, name, data, **kwargs): @@ -1160,7 +1160,7 @@ def _ones_like_nosync(self, name, data, **kwargs): def full_like(self, name, data, **kwargs): """Create an array. Keyword arguments as per - :func:`zarr.creation.full_like`.""" + :func:`zarr.v2.creation.full_like`.""" return self._write_op(self._full_like_nosync, name, data, **kwargs) def _full_like_nosync(self, name, data, **kwargs): @@ -1252,23 +1252,23 @@ def group( Returns ------- - g : zarr.hierarchy.Group + g : zarr.v2.hierarchy.Group Examples -------- Create a group in memory:: >>> import zarr - >>> g = zarr.group() + >>> g = zarr.v2.group() >>> g - + Create a group with a different store:: - >>> store = zarr.DirectoryStore('data/example.zarr') - >>> g = zarr.group(store=store, overwrite=True) + >>> store = zarr.v2.DirectoryStore('data/example.zarr') + >>> g = zarr.v2.group(store=store, overwrite=True) >>> g - + """ @@ -1336,19 +1336,19 @@ def open_group( Returns ------- - g : zarr.hierarchy.Group + g : zarr.v2.hierarchy.Group Examples -------- >>> import zarr - >>> root = zarr.open_group('data/example.zarr', mode='w') + >>> root = zarr.v2.open_group('data/example.zarr', mode='w') >>> foo = root.create_group('foo') >>> bar = root.create_group('bar') >>> root - - >>> root2 = zarr.open_group('data/example.zarr', mode='a') + + >>> root2 = zarr.v2.open_group('data/example.zarr', mode='a') >>> root2 - + >>> root == root2 True diff --git a/src/zarr/indexing.py b/src/zarr/v2/indexing.py similarity index 99% rename from src/zarr/indexing.py rename to src/zarr/v2/indexing.py index b72d5a255d..1c11409d05 100644 --- a/src/zarr/indexing.py +++ b/src/zarr/v2/indexing.py @@ -6,7 +6,7 @@ import numpy as np -from zarr.errors import ( +from zarr.v2.errors import ( ArrayIndexError, NegativeStepError, err_too_many_indices, diff --git a/src/zarr/meta.py b/src/zarr/v2/meta.py similarity index 99% rename from src/zarr/meta.py rename to src/zarr/v2/meta.py index 7cca228a14..ee9cc57389 100644 --- a/src/zarr/meta.py +++ b/src/zarr/v2/meta.py @@ -4,8 +4,8 @@ import numpy as np -from zarr.errors import MetadataError -from zarr.util import json_dumps, json_loads +from zarr.v2.errors import MetadataError +from zarr.v2.util import json_dumps, json_loads from typing import cast, Union, Any, List, Mapping as MappingType, TYPE_CHECKING diff --git a/src/zarr/meta_v1.py b/src/zarr/v2/meta_v1.py similarity index 97% rename from src/zarr/meta_v1.py rename to src/zarr/v2/meta_v1.py index 4ac381f2ca..881b9191eb 100644 --- a/src/zarr/meta_v1.py +++ b/src/zarr/v2/meta_v1.py @@ -2,7 +2,7 @@ import numpy as np -from zarr.errors import MetadataError +from zarr.v2.errors import MetadataError def decode_metadata(b): diff --git a/src/zarr/n5.py b/src/zarr/v2/n5.py similarity index 98% rename from src/zarr/n5.py rename to src/zarr/v2/n5.py index 1293d1739b..92b0f37924 100644 --- a/src/zarr/n5.py +++ b/src/zarr/v2/n5.py @@ -11,12 +11,12 @@ from numcodecs.compat import ndarray_copy from numcodecs.registry import get_codec, register_codec -from .meta import ZARR_FORMAT, json_dumps, json_loads -from .storage import FSStore -from .storage import NestedDirectoryStore, _prog_ckey, _prog_number, normalize_storage_path -from .storage import array_meta_key as zarr_array_meta_key -from .storage import attrs_key as zarr_attrs_key -from .storage import group_meta_key as zarr_group_meta_key +from zarr.v2.meta import ZARR_FORMAT, json_dumps, json_loads +from zarr.v2.storage import FSStore +from zarr.v2.storage import NestedDirectoryStore, _prog_ckey, _prog_number, normalize_storage_path +from zarr.v2.storage import array_meta_key as zarr_array_meta_key +from zarr.v2.storage import attrs_key as zarr_attrs_key +from zarr.v2.storage import group_meta_key as zarr_group_meta_key N5_FORMAT = "2.0.0" diff --git a/src/zarr/storage.py b/src/zarr/v2/storage.py similarity index 96% rename from src/zarr/storage.py rename to src/zarr/v2/storage.py index ae596756f8..56deeeb555 100644 --- a/src/zarr/storage.py +++ b/src/zarr/v2/storage.py @@ -38,9 +38,9 @@ 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.v2.context import Context -from zarr.errors import ( +from zarr.v2.errors import ( MetadataError, BadCompressorError, ContainsArrayError, @@ -48,8 +48,8 @@ FSPathExistNotDir, ReadOnlyError, ) -from zarr.meta import encode_array_metadata, encode_group_metadata -from zarr.util import ( +from zarr.v2.meta import encode_array_metadata, encode_group_metadata +from zarr.v2.util import ( buffer_size, json_loads, nolock, @@ -64,8 +64,8 @@ ensure_contiguous_ndarray_or_bytes, ) -from zarr._storage.absstore import ABSStore # noqa: F401 -from zarr._storage.store import ( # noqa: F401 +from zarr.v2._storage.absstore import ABSStore # noqa: F401 +from zarr.v2._storage.store import ( # noqa: F401 _listdir_from_keys, _rename_from_keys, _rmdir_from_keys, @@ -89,11 +89,11 @@ try: # noinspection PyUnresolvedReferences - from zarr.codecs import Blosc + from zarr.v2.codecs import Blosc default_compressor = Blosc() except ImportError: # pragma: no cover - from zarr.codecs import Zlib + from zarr.v2.codecs import Zlib default_compressor = Zlib() @@ -146,7 +146,7 @@ def normalize_store_arg(store: Any, storage_options=None, mode="r") -> BaseStore if store.endswith(".zip"): return ZipStore(store, mode=mode) elif store.endswith(".n5"): - from zarr.n5 import N5Store + from zarr.v2.n5 import N5Store return N5Store(store) else: @@ -310,7 +310,7 @@ def init_array( -------- Initialize an array store:: - >>> from zarr.storage import init_array, KVStore + >>> from zarr.v2.storage import init_array, KVStore >>> store = KVStore(dict()) >>> init_array(store, shape=(10000, 10000), chunks=(1000, 1000)) >>> sorted(store.keys()) @@ -649,16 +649,16 @@ class MemoryStore(Store): This is the default class used when creating a group. E.g.:: >>> import zarr - >>> g = zarr.group() + >>> g = zarr.v2.group() >>> type(g.store) - + Note that the default class when creating an array is the built-in :class:`KVStore` class, i.e.:: - >>> z = zarr.zeros(100) + >>> z = zarr.v2.zeros(100) >>> type(z.store) - + Notes ----- @@ -860,8 +860,8 @@ class DirectoryStore(Store): Store a single array:: >>> import zarr - >>> store = zarr.DirectoryStore('data/array.zarr') - >>> z = zarr.zeros((10, 10), chunks=(5, 5), store=store, overwrite=True) + >>> store = zarr.v2.DirectoryStore('data/array.zarr') + >>> z = zarr.v2.zeros((10, 10), chunks=(5, 5), store=store, overwrite=True) >>> z[...] = 42 Each chunk of the array is stored as a separate file on the file system, @@ -873,8 +873,8 @@ class DirectoryStore(Store): Store a group:: - >>> store = zarr.DirectoryStore('data/group.zarr') - >>> root = zarr.group(store=store, overwrite=True) + >>> store = zarr.v2.DirectoryStore('data/group.zarr') + >>> root = zarr.v2.group(store=store, overwrite=True) >>> foo = root.create_group('foo') >>> bar = foo.zeros('bar', shape=(10, 10), chunks=(5, 5)) >>> bar[...] = 42 @@ -1447,8 +1447,8 @@ class NestedDirectoryStore(DirectoryStore): Store a single array:: >>> import zarr - >>> store = zarr.NestedDirectoryStore('data/array.zarr') - >>> z = zarr.zeros((10, 10), chunks=(5, 5), store=store, overwrite=True) + >>> store = zarr.v2.NestedDirectoryStore('data/array.zarr') + >>> z = zarr.v2.zeros((10, 10), chunks=(5, 5), store=store, overwrite=True) >>> z[...] = 42 Each chunk of the array is stored as a separate file on the file system, @@ -1464,8 +1464,8 @@ class NestedDirectoryStore(DirectoryStore): Store a group:: - >>> store = zarr.NestedDirectoryStore('data/group.zarr') - >>> root = zarr.group(store=store, overwrite=True) + >>> store = zarr.v2.NestedDirectoryStore('data/group.zarr') + >>> root = zarr.v2.group(store=store, overwrite=True) >>> foo = root.create_group('foo') >>> bar = foo.zeros('bar', shape=(10, 10), chunks=(5, 5)) >>> bar[...] = 42 @@ -1536,15 +1536,15 @@ class ZipStore(Store): Store a single array:: >>> import zarr - >>> store = zarr.ZipStore('data/array.zip', mode='w') - >>> z = zarr.zeros((10, 10), chunks=(5, 5), store=store) + >>> store = zarr.v2.ZipStore('data/array.zip', mode='w') + >>> z = zarr.v2.zeros((10, 10), chunks=(5, 5), store=store) >>> z[...] = 42 >>> store.close() # don't forget to call this when you're done Store a group:: - >>> store = zarr.ZipStore('data/group.zip', mode='w') - >>> root = zarr.group(store=store) + >>> store = zarr.v2.ZipStore('data/group.zip', mode='w') + >>> root = zarr.v2.group(store=store) >>> foo = root.create_group('foo') >>> bar = foo.zeros('bar', shape=(10, 10), chunks=(5, 5)) >>> bar[...] = 42 @@ -1555,8 +1555,8 @@ class ZipStore(Store): class also supports the context manager protocol, which ensures the ``close()`` method is called on leaving the context, e.g.:: - >>> with zarr.ZipStore('data/array.zip', mode='w') as store: - ... z = zarr.zeros((10, 10), chunks=(5, 5), store=store) + >>> with zarr.v2.ZipStore('data/array.zip', mode='w') as store: + ... z = zarr.v2.zeros((10, 10), chunks=(5, 5), store=store) ... z[...] = 42 ... # no need to call store.close() @@ -1569,8 +1569,8 @@ class also supports the context manager protocol, which ensures the ``close()`` triggered if you attempt to write data to a Zarr array more than once, e.g.:: - >>> store = zarr.ZipStore('data/example.zip', mode='w') - >>> z = zarr.zeros(100, chunks=10, store=store) + >>> store = zarr.v2.ZipStore('data/example.zip', mode='w') + >>> z = zarr.v2.zeros(100, chunks=10, store=store) >>> # first write OK ... z[...] = 42 >>> # second write generates warnings @@ -1581,22 +1581,22 @@ class also supports the context manager protocol, which ensures the ``close()`` once to a Zarr array, but the write operations are not aligned with chunk boundaries, e.g.:: - >>> store = zarr.ZipStore('data/example.zip', mode='w') - >>> z = zarr.zeros(100, chunks=10, store=store) + >>> store = zarr.v2.ZipStore('data/example.zip', mode='w') + >>> z = zarr.v2.zeros(100, chunks=10, store=store) >>> z[5:15] = 42 >>> # write overlaps chunk previously written, generates warnings ... z[15:25] = 42 # doctest: +SKIP To avoid creating duplicate entries, only write data once, and align writes with chunk boundaries. This alignment is done automatically if you call - ``z[...] = ...`` or create an array from existing data via :func:`zarr.array`. + ``z[...] = ...`` or create an array from existing data via :func:`zarr.v2.array`. Alternatively, use a :class:`DirectoryStore` when writing the data, then manually Zip the directory and use the Zip file for subsequent reads. Take note that the files in the Zip file must be relative to the root of the Zarr archive. You may find it easier to create such a Zip file with ``7z``, e.g.:: - 7z a -tzip archive.zarr.zip archive.zarr/. + 7z a -tzip archive.zarr.v2.zip archive.zarr/. Safe to write in multiple threads but not in multiple processes. @@ -1841,15 +1841,15 @@ class DBMStore(Store): Store a single array:: >>> import zarr - >>> store = zarr.DBMStore('data/array.db') - >>> z = zarr.zeros((10, 10), chunks=(5, 5), store=store, overwrite=True) + >>> store = zarr.v2.DBMStore('data/array.db') + >>> z = zarr.v2.zeros((10, 10), chunks=(5, 5), store=store, overwrite=True) >>> z[...] = 42 >>> store.close() # don't forget to call this when you're done Store a group:: - >>> store = zarr.DBMStore('data/group.db') - >>> root = zarr.group(store=store, overwrite=True) + >>> store = zarr.v2.DBMStore('data/group.db') + >>> root = zarr.v2.group(store=store, overwrite=True) >>> foo = root.create_group('foo') >>> bar = foo.zeros('bar', shape=(10, 10), chunks=(5, 5)) >>> bar[...] = 42 @@ -1860,8 +1860,8 @@ class DBMStore(Store): DBMStore class also supports the context manager protocol, which ensures the ``close()`` method is called on leaving the context, e.g.:: - >>> with zarr.DBMStore('data/array.db') as store: - ... z = zarr.zeros((10, 10), chunks=(5, 5), store=store, overwrite=True) + >>> with zarr.v2.DBMStore('data/array.db') as store: + ... z = zarr.v2.zeros((10, 10), chunks=(5, 5), store=store, overwrite=True) ... z[...] = 42 ... # no need to call store.close() @@ -1871,8 +1871,8 @@ class DBMStore(Store): Berkeley DB database can be used:: >>> import bsddb3 - >>> store = zarr.DBMStore('data/array.bdb', open=bsddb3.btopen) - >>> z = zarr.zeros((10, 10), chunks=(5, 5), store=store, overwrite=True) + >>> store = zarr.v2.DBMStore('data/array.bdb', open=bsddb3.btopen) + >>> z = zarr.v2.zeros((10, 10), chunks=(5, 5), store=store, overwrite=True) >>> z[...] = 42 >>> store.close() @@ -2040,15 +2040,15 @@ class LMDBStore(Store): Store a single array:: >>> import zarr - >>> store = zarr.LMDBStore('data/array.mdb') - >>> z = zarr.zeros((10, 10), chunks=(5, 5), store=store, overwrite=True) + >>> store = zarr.v2.LMDBStore('data/array.mdb') + >>> z = zarr.v2.zeros((10, 10), chunks=(5, 5), store=store, overwrite=True) >>> z[...] = 42 >>> store.close() # don't forget to call this when you're done Store a group:: - >>> store = zarr.LMDBStore('data/group.mdb') - >>> root = zarr.group(store=store, overwrite=True) + >>> store = zarr.v2.LMDBStore('data/group.mdb') + >>> root = zarr.v2.group(store=store, overwrite=True) >>> foo = root.create_group('foo') >>> bar = foo.zeros('bar', shape=(10, 10), chunks=(5, 5)) >>> bar[...] = 42 @@ -2059,8 +2059,8 @@ class LMDBStore(Store): DBMStore class also supports the context manager protocol, which ensures the ``close()`` method is called on leaving the context, e.g.:: - >>> with zarr.LMDBStore('data/array.mdb') as store: - ... z = zarr.zeros((10, 10), chunks=(5, 5), store=store, overwrite=True) + >>> with zarr.v2.LMDBStore('data/array.mdb') as store: + ... z = zarr.v2.zeros((10, 10), chunks=(5, 5), store=store, overwrite=True) ... z[...] = 42 ... # no need to call store.close() @@ -2216,8 +2216,8 @@ class LRUStoreCache(Store): >>> import zarr >>> s3 = s3fs.S3FileSystem(anon=True, client_kwargs=dict(region_name='eu-west-2')) >>> store = s3fs.S3Map(root='zarr-demo/store', s3=s3, check=False) - >>> cache = zarr.LRUStoreCache(store, max_size=2**28) - >>> root = zarr.group(store=cache) # doctest: +REMOTE_DATA + >>> cache = zarr.v2.LRUStoreCache(store, max_size=2**28) + >>> root = zarr.v2.group(store=cache) # doctest: +REMOTE_DATA >>> z = root['foo/bar/baz'] # doctest: +REMOTE_DATA >>> from timeit import timeit >>> # first data access is relatively slow, retrieved from store @@ -2410,15 +2410,15 @@ class SQLiteStore(Store): Store a single array:: >>> import zarr - >>> store = zarr.SQLiteStore('data/array.sqldb') - >>> z = zarr.zeros((10, 10), chunks=(5, 5), store=store, overwrite=True) + >>> store = zarr.v2.SQLiteStore('data/array.sqldb') + >>> z = zarr.v2.zeros((10, 10), chunks=(5, 5), store=store, overwrite=True) >>> z[...] = 42 >>> store.close() # don't forget to call this when you're done Store a group:: - >>> store = zarr.SQLiteStore('data/group.sqldb') - >>> root = zarr.group(store=store, overwrite=True) + >>> store = zarr.v2.SQLiteStore('data/group.sqldb') + >>> root = zarr.v2.group(store=store, overwrite=True) >>> foo = root.create_group('foo') >>> bar = foo.zeros('bar', shape=(10, 10), chunks=(5, 5)) >>> bar[...] = 42 @@ -2751,7 +2751,7 @@ class ConsolidatedMetadataStore(Store): The purpose of this class, is to be able to get all of the metadata for a given array in a single read operation from the underlying storage. - See :func:`zarr.convenience.consolidate_metadata` for how to create this + See :func:`zarr.v2.convenience.consolidate_metadata` for how to create this single metadata key. This class loads from the one key, and stores the data in a dict, so that @@ -2760,7 +2760,7 @@ class ConsolidatedMetadataStore(Store): This class is read-only, and attempts to change the array metadata will fail, but changing the data is possible. If the backend storage is changed directly, then the metadata stored here could become obsolete, and - :func:`zarr.convenience.consolidate_metadata` should be called again and the class + :func:`zarr.v2.convenience.consolidate_metadata` should be called again and the class re-invoked. The use case is for write once, read many times. .. versionadded:: 2.3 @@ -2777,7 +2777,7 @@ class ConsolidatedMetadataStore(Store): See Also -------- - zarr.convenience.consolidate_metadata, zarr.convenience.open_consolidated + zarr.v2.convenience.consolidate_metadata, zarr.v2.convenience.open_consolidated """ diff --git a/src/zarr/sync.py b/src/zarr/v2/sync.py similarity index 100% rename from src/zarr/sync.py rename to src/zarr/v2/sync.py diff --git a/src/zarr/util.py b/src/zarr/v2/util.py similarity index 100% rename from src/zarr/util.py rename to src/zarr/v2/util.py diff --git a/tests/__init__.py b/tests/v2/__init__.py similarity index 100% rename from tests/__init__.py rename to tests/v2/__init__.py diff --git a/tests/conftest.py b/tests/v2/conftest.py similarity index 60% rename from tests/conftest.py rename to tests/v2/conftest.py index aa73b8691e..a7a445c640 100644 --- a/tests/conftest.py +++ b/tests/v2/conftest.py @@ -6,3 +6,8 @@ @pytest.fixture(params=[str, pathlib.Path]) def path_type(request): return request.param + + +@pytest.fixture +def project_root(request): + return request.config.rootpath diff --git a/tests/data/store.zip b/tests/v2/data/store.zip similarity index 100% rename from tests/data/store.zip rename to tests/v2/data/store.zip diff --git a/tests/data/store/foo b/tests/v2/data/store/foo similarity index 100% rename from tests/data/store/foo rename to tests/v2/data/store/foo diff --git a/tests/test_attrs.py b/tests/v2/test_attrs.py similarity index 97% rename from tests/test_attrs.py rename to tests/v2/test_attrs.py index 2575163840..b477b8befe 100644 --- a/tests/test_attrs.py +++ b/tests/v2/test_attrs.py @@ -1,13 +1,11 @@ import json -import pathlib import pytest -import zarr -from zarr.attrs import Attributes -from zarr.storage import KVStore, DirectoryStore +from zarr.v2.attrs import Attributes +from zarr.v2.storage import KVStore, DirectoryStore from .util import CountingDict -from zarr.hierarchy import group +from zarr.v2.hierarchy import group def _init_store(): @@ -36,8 +34,7 @@ def test_storage(self): d = json.loads(str(store[attrs_key], "utf-8")) assert dict(foo="bar", baz=42) == d - def test_utf8_encoding(self): - project_root = pathlib.Path(zarr.__file__).resolve().parent.parent + def test_utf8_encoding(self, project_root): fixdir = project_root / "fixture" testdir = fixdir / "utf8attrs" if not testdir.exists(): # pragma: no cover diff --git a/tests/test_convenience.py b/tests/v2/test_convenience.py similarity index 99% rename from tests/test_convenience.py rename to tests/v2/test_convenience.py index d50533e847..f558a8800f 100644 --- a/tests/test_convenience.py +++ b/tests/v2/test_convenience.py @@ -8,8 +8,8 @@ from numcodecs import Adler32, Zlib from numpy.testing import assert_array_equal -import zarr -from zarr.convenience import ( +import zarr.v2 as zarr +from zarr.v2.convenience import ( consolidate_metadata, copy, copy_store, @@ -21,10 +21,10 @@ save_array, copy_all, ) -from zarr.core import Array -from zarr.errors import CopyError -from zarr.hierarchy import Group, group -from zarr.storage import ( +from zarr.v2.core import Array +from zarr.v2.errors import CopyError +from zarr.v2.hierarchy import Group, group +from zarr.v2.storage import ( ConsolidatedMetadataStore, FSStore, MemoryStore, diff --git a/tests/test_core.py b/tests/v2/test_core.py similarity index 99% rename from tests/test_core.py rename to tests/v2/test_core.py index 6303371793..197461d129 100644 --- a/tests/test_core.py +++ b/tests/v2/test_core.py @@ -30,15 +30,15 @@ from numcodecs.tests.common import greetings from numpy.testing import assert_array_almost_equal, assert_array_equal -import zarr -from zarr._storage.store import ( +import zarr.v2 +from zarr.v2._storage.store import ( BaseStore, ) -from zarr.core import Array -from zarr.meta import json_loads -from zarr.n5 import N5Store, N5FSStore, n5_keywords -from zarr.storage import ( +from zarr.v2.core import Array +from zarr.v2.meta import json_loads +from zarr.v2.n5 import N5Store, N5FSStore, n5_keywords +from zarr.v2.storage import ( ABSStore, DBMStore, DirectoryStore, @@ -55,7 +55,7 @@ normalize_store_arg, ) -from zarr.util import buffer_size +from zarr.v2.util import buffer_size from .util import abs_container, skip_test_env_var, have_fsspec, mktemp # noinspection PyMethodMayBeStatic @@ -721,7 +721,7 @@ def test_resize_2d(self): # checks that resizing preserves metadata if self.dimension_separator == "/": - z_ = zarr.open(z.store) + z_ = zarr.v2.open(z.store) if hasattr(z_, "dimension_separator"): assert z_.dimension_separator == self.dimension_separator z_.store.close() @@ -2495,7 +2495,7 @@ def test_issue_1279(tmpdir): """See """ data = np.arange(25).reshape((5, 5)) - ds = zarr.create( + ds = zarr.v2.create( shape=data.shape, chunks=(5, 5), dtype=data.dtype, @@ -2506,7 +2506,7 @@ def test_issue_1279(tmpdir): ds[:] = data - ds_reopened = zarr.open_array(store=FSStore(url=str(tmpdir), mode="r")) + ds_reopened = zarr.v2.open_array(store=FSStore(url=str(tmpdir), mode="r")) written_data = ds_reopened[:] assert_array_equal(data, written_data) diff --git a/tests/test_creation.py b/tests/v2/test_creation.py similarity index 98% rename from tests/test_creation.py rename to tests/v2/test_creation.py index 369d755700..08073a8ac3 100644 --- a/tests/test_creation.py +++ b/tests/v2/test_creation.py @@ -7,9 +7,9 @@ import pytest from numpy.testing import assert_array_equal -from zarr.codecs import Zlib -from zarr.core import Array -from zarr.creation import ( +from zarr.v2.codecs import Zlib +from zarr.v2.core import Array +from zarr.v2.creation import ( array, create, empty, @@ -23,10 +23,10 @@ zeros, zeros_like, ) -from zarr.hierarchy import open_group -from zarr.n5 import N5Store -from zarr.storage import DirectoryStore, KVStore -from zarr.sync import ThreadSynchronizer +from zarr.v2.hierarchy import open_group +from zarr.v2.n5 import N5Store +from zarr.v2.storage import DirectoryStore, KVStore +from zarr.v2.sync import ThreadSynchronizer from .util import mktemp, have_fsspec diff --git a/tests/test_dim_separator.py b/tests/v2/test_dim_separator.py similarity index 87% rename from tests/test_dim_separator.py rename to tests/v2/test_dim_separator.py index 4276d1829d..b0e9d0ecc8 100644 --- a/tests/test_dim_separator.py +++ b/tests/v2/test_dim_separator.py @@ -4,9 +4,9 @@ from numpy.testing import assert_array_equal from functools import partial -import zarr -from zarr.core import Array -from zarr.storage import DirectoryStore, NestedDirectoryStore, FSStore +import zarr.v2 +from zarr.v2.core import Array +from zarr.v2.storage import DirectoryStore, NestedDirectoryStore, FSStore from .util import have_fsspec @@ -41,7 +41,7 @@ def dataset(tmpdir, request): kwargs = {} if which.startswith("static"): - project_root = pathlib.Path(zarr.__file__).resolve().parent.parent + project_root = pathlib.Path(zarr.v2.__file__).resolve().parent.parent suffix = which[len("static_") :] static = project_root / "fixture" / suffix @@ -59,7 +59,7 @@ def dataset(tmpdir, request): # store the data - should be one-time operation s = generator(str(static)) - a = zarr.open(store=s, mode="w", shape=(2, 2), dtype=" CuPyCPUCompressor: if compressor: - compressor = getattr(zarr.codecs, compressor)() + compressor = getattr(zarr.v2.codecs, compressor)() return CuPyCPUCompressor(compressor) diff --git a/tests/test_n5.py b/tests/v2/test_n5.py similarity index 93% rename from tests/test_n5.py rename to tests/v2/test_n5.py index 755d60b607..238e9b2c6e 100644 --- a/tests/test_n5.py +++ b/tests/v2/test_n5.py @@ -1,8 +1,8 @@ import pytest -from zarr.n5 import N5ChunkWrapper, N5FSStore -from zarr.creation import create -from zarr.storage import atexit_rmtree +from zarr.v2.n5 import N5ChunkWrapper, N5FSStore +from zarr.v2.creation import create +from zarr.v2.storage import atexit_rmtree from numcodecs import GZip import numpy as np from typing import Tuple diff --git a/tests/test_storage.py b/tests/v2/test_storage.py similarity index 99% rename from tests/test_storage.py rename to tests/v2/test_storage.py index 5d82b879ad..4746a30e37 100644 --- a/tests/test_storage.py +++ b/tests/v2/test_storage.py @@ -31,7 +31,7 @@ # from zarr.meta import ZARR_FORMAT, decode_array_metadata # from zarr.n5 import N5Store, N5FSStore, N5_FORMAT, n5_attrs_key -from zarr.storage import ( +from zarr.v2.storage import ( # ABSStore, # ConsolidatedMetadataStore, # DBMStore, diff --git a/tests/test_storage_v3.py b/tests/v2/test_storage_v3.py similarity index 100% rename from tests/test_storage_v3.py rename to tests/v2/test_storage_v3.py diff --git a/tests/test_sync.py b/tests/v2/test_sync.py similarity index 97% rename from tests/test_sync.py rename to tests/v2/test_sync.py index 9d805ee2c1..8bf1304dc2 100644 --- a/tests/test_sync.py +++ b/tests/v2/test_sync.py @@ -9,11 +9,11 @@ import numpy as np from numpy.testing import assert_array_equal -from zarr.attrs import Attributes -from zarr.core import Array -from zarr.hierarchy import Group -from zarr.storage import DirectoryStore, KVStore, atexit_rmtree, init_array, init_group -from zarr.sync import ProcessSynchronizer, ThreadSynchronizer +from zarr.v2.attrs import Attributes +from zarr.v2.core import Array +from zarr.v2.hierarchy import Group +from zarr.v2.storage import DirectoryStore, KVStore, atexit_rmtree, init_array, init_group +from zarr.v2.sync import ProcessSynchronizer, ThreadSynchronizer # zarr_version fixture must be imported although not used directly here from .test_attrs import TestAttributes # noqa diff --git a/tests/test_util.py b/tests/v2/test_util.py similarity index 99% rename from tests/test_util.py rename to tests/v2/test_util.py index 1f7efc9214..35c355693a 100644 --- a/tests/test_util.py +++ b/tests/v2/test_util.py @@ -4,8 +4,8 @@ import numpy as np import pytest -from zarr.core import Array -from zarr.util import ( +from zarr.v2.core import Array +from zarr.v2.util import ( ConstantMap, all_equal, flatten, diff --git a/tests/util.py b/tests/v2/util.py similarity index 97% rename from tests/util.py rename to tests/v2/util.py index 8e53bf3b63..12c5e379f6 100644 --- a/tests/util.py +++ b/tests/v2/util.py @@ -2,9 +2,9 @@ import os import tempfile from typing import Any, Mapping, Sequence -from zarr.context import Context +from zarr.v2.context import Context -from zarr.storage import Store +from zarr.v2.storage import Store import pytest diff --git a/tests/v3/test_codecs.py b/tests/v3/test_codecs.py index 333c2094bf..dba28cd995 100644 --- a/tests/v3/test_codecs.py +++ b/tests/v3/test_codecs.py @@ -7,7 +7,7 @@ import numpy as np import pytest -import zarr +import zarr.v2 from zarr.v3.abc.codec import Codec from zarr.v3.array import Array, AsyncArray from zarr.v3.common import Selection @@ -286,7 +286,7 @@ async def test_order( if not with_sharding: # Compare with zarr-python - z = zarr.create( + z = zarr.v2.create( shape=data.shape, chunks=(32, 8), dtype=" Date: Mon, 22 Apr 2024 21:22:16 -0700 Subject: [PATCH 2/4] move zarr v3 code to root --- pyproject.toml | 38 ++++++++++++------------ src/zarr/{v3 => }/__init__.py | 16 +++++----- src/zarr/{v3 => }/abc/__init__.py | 0 src/zarr/{v3 => }/abc/codec.py | 12 ++++---- src/zarr/{v3 => }/abc/metadata.py | 2 +- src/zarr/{v3 => }/abc/store.py | 0 src/zarr/{v3 => }/array.py | 24 +++++++-------- src/zarr/{v3 => }/array_v2.py | 28 ++++++++--------- src/zarr/{v3 => }/attributes.py | 4 +-- src/zarr/{v3 => }/chunk_grids.py | 4 +-- src/zarr/{v3 => }/chunk_key_encodings.py | 4 +-- src/zarr/codecs/__init__.py | 9 ++++++ src/zarr/{v3 => }/codecs/blosc.py | 10 +++---- src/zarr/{v3 => }/codecs/bytes.py | 10 +++---- src/zarr/{v3 => }/codecs/crc32c_.py | 10 +++---- src/zarr/{v3 => }/codecs/gzip.py | 10 +++---- src/zarr/{v3 => }/codecs/pipeline.py | 18 +++++------ src/zarr/{v3 => }/codecs/registry.py | 2 +- src/zarr/{v3 => }/codecs/sharding.py | 24 +++++++-------- src/zarr/{v3 => }/codecs/transpose.py | 10 +++---- src/zarr/{v3 => }/codecs/zstd.py | 10 +++---- src/zarr/{v3 => }/common.py | 0 src/zarr/{v3 => }/config.py | 0 src/zarr/{v3 => }/group.py | 16 +++++----- src/zarr/{v3 => }/indexing.py | 2 +- src/zarr/{v3 => }/metadata.py | 16 +++++----- src/zarr/store/__init__.py | 5 ++++ src/zarr/{v3 => }/store/core.py | 6 ++-- src/zarr/{v3 => }/store/local.py | 4 +-- src/zarr/{v3 => }/store/memory.py | 4 +-- src/zarr/{v3 => }/store/remote.py | 6 ++-- src/zarr/{v3 => }/sync.py | 2 +- src/zarr/v3/codecs/__init__.py | 9 ------ src/zarr/v3/store/__init__.py | 5 ---- tests/v2/test_storage.py | 4 +-- tests/v3/test_codecs.py | 16 +++++----- tests/v3/test_common.py | 6 ++-- tests/v3/test_group.py | 6 ++-- tests/v3/test_metadata.py | 2 +- 39 files changed, 177 insertions(+), 177 deletions(-) rename src/zarr/{v3 => }/__init__.py (71%) rename src/zarr/{v3 => }/abc/__init__.py (100%) rename src/zarr/{v3 => }/abc/codec.py (90%) rename src/zarr/{v3 => }/abc/metadata.py (97%) rename src/zarr/{v3 => }/abc/store.py (100%) rename src/zarr/{v3 => }/array.py (97%) rename src/zarr/{v3 => }/array_v2.py (96%) rename src/zarr/{v3 => }/attributes.py (92%) rename src/zarr/{v3 => }/chunk_grids.py (94%) rename src/zarr/{v3 => }/chunk_key_encodings.py (97%) create mode 100644 src/zarr/codecs/__init__.py rename src/zarr/{v3 => }/codecs/blosc.py (95%) rename src/zarr/{v3 => }/codecs/bytes.py (92%) rename src/zarr/{v3 => }/codecs/crc32c_.py (86%) rename src/zarr/{v3 => }/codecs/gzip.py (87%) rename src/zarr/{v3 => }/codecs/pipeline.py (95%) rename src/zarr/{v3 => }/codecs/registry.py (96%) rename src/zarr/{v3 => }/codecs/sharding.py (97%) rename src/zarr/{v3 => }/codecs/transpose.py (92%) rename src/zarr/{v3 => }/codecs/zstd.py (89%) rename src/zarr/{v3 => }/common.py (100%) rename src/zarr/{v3 => }/config.py (100%) rename src/zarr/{v3 => }/group.py (97%) rename src/zarr/{v3 => }/indexing.py (98%) rename src/zarr/{v3 => }/metadata.py (96%) create mode 100644 src/zarr/store/__init__.py rename src/zarr/{v3 => }/store/core.py (94%) rename src/zarr/{v3 => }/store/local.py (98%) rename src/zarr/{v3 => }/store/memory.py (97%) rename src/zarr/{v3 => }/store/remote.py (96%) rename src/zarr/{v3 => }/sync.py (98%) delete mode 100644 src/zarr/v3/codecs/__init__.py delete mode 100644 src/zarr/v3/store/__init__.py diff --git a/pyproject.toml b/pyproject.toml index 00c6333aa5..5771f7b972 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -164,31 +164,31 @@ disallow_any_generics = true [[tool.mypy.overrides]] module = [ - "zarr._storage.store", - "zarr._storage.v3_storage_transformers", - "zarr.v3.group", - "zarr.core", - "zarr.hierarchy", - "zarr.indexing", - "zarr.storage", - "zarr.sync", - "zarr.util", + "zarr.v2._storage.store", + "zarr.v2._storage.v3_storage_transformers", + "zarr.group", + "zarr.v2.core", + "zarr.v2.hierarchy", + "zarr.v2.indexing", + "zarr.v2.storage", + "zarr.v2.sync", + "zarr.v2.util", "tests.*", ] check_untyped_defs = false [[tool.mypy.overrides]] module = [ - "zarr.v3.abc.codec", - "zarr.v3.codecs.bytes", - "zarr.v3.codecs.pipeline", - "zarr.v3.codecs.sharding", - "zarr.v3.codecs.transpose", - "zarr.v3.array_v2", - "zarr.v3.array", - "zarr.v3.sync", - "zarr.convenience", - "zarr.meta", + "zarr.abc.codec", + "zarr.codecs.bytes", + "zarr.codecs.pipeline", + "zarr.codecs.sharding", + "zarr.codecs.transpose", + "zarr.array_v2", + "zarr.array", + "zarr.sync", + "zarr.v2.convenience", + "zarr.v2.meta", ] disallow_any_generics = false diff --git a/src/zarr/v3/__init__.py b/src/zarr/__init__.py similarity index 71% rename from src/zarr/v3/__init__.py rename to src/zarr/__init__.py index 3441fa67be..5be8f9764b 100644 --- a/src/zarr/v3/__init__.py +++ b/src/zarr/__init__.py @@ -2,17 +2,17 @@ from typing import Union -import zarr.v3.codecs # noqa: F401 -from zarr.v3.array import Array, AsyncArray # noqa: F401 -from zarr.v3.array_v2 import ArrayV2 -from zarr.v3.config import RuntimeConfiguration # noqa: F401 -from zarr.v3.group import AsyncGroup, Group # noqa: F401 -from zarr.v3.metadata import runtime_configuration # noqa: F401 -from zarr.v3.store import ( # noqa: F401 +import zarr.codecs # noqa: F401 +from zarr.array import Array, AsyncArray # noqa: F401 +from zarr.array_v2 import ArrayV2 +from zarr.config import RuntimeConfiguration # noqa: F401 +from zarr.group import AsyncGroup, Group # noqa: F401 +from zarr.metadata import runtime_configuration # noqa: F401 +from zarr.store import ( # noqa: F401 StoreLike, make_store_path, ) -from zarr.v3.sync import sync as _sync +from zarr.sync import sync as _sync async def open_auto_async( diff --git a/src/zarr/v3/abc/__init__.py b/src/zarr/abc/__init__.py similarity index 100% rename from src/zarr/v3/abc/__init__.py rename to src/zarr/abc/__init__.py diff --git a/src/zarr/v3/abc/codec.py b/src/zarr/abc/codec.py similarity index 90% rename from src/zarr/v3/abc/codec.py rename to src/zarr/abc/codec.py index d0e51ff894..1abc21b30b 100644 --- a/src/zarr/v3/abc/codec.py +++ b/src/zarr/abc/codec.py @@ -4,17 +4,17 @@ from typing import TYPE_CHECKING, Optional import numpy as np -from zarr.v3.abc.metadata import Metadata +from zarr.abc.metadata import Metadata -from zarr.v3.common import ArraySpec -from zarr.v3.store import StorePath +from zarr.common import ArraySpec +from zarr.store import StorePath if TYPE_CHECKING: from typing_extensions import Self - from zarr.v3.common import BytesLike, SliceSelection - from zarr.v3.metadata import ArrayMetadata - from zarr.v3.config import RuntimeConfiguration + from zarr.common import BytesLike, SliceSelection + from zarr.metadata import ArrayMetadata + from zarr.config import RuntimeConfiguration class Codec(Metadata): diff --git a/src/zarr/v3/abc/metadata.py b/src/zarr/abc/metadata.py similarity index 97% rename from src/zarr/v3/abc/metadata.py rename to src/zarr/abc/metadata.py index 4fcabf72a1..f27b37cba4 100644 --- a/src/zarr/v3/abc/metadata.py +++ b/src/zarr/abc/metadata.py @@ -7,7 +7,7 @@ from dataclasses import fields, dataclass -from zarr.v3.common import JSON +from zarr.common import JSON @dataclass(frozen=True) diff --git a/src/zarr/v3/abc/store.py b/src/zarr/abc/store.py similarity index 100% rename from src/zarr/v3/abc/store.py rename to src/zarr/abc/store.py diff --git a/src/zarr/v3/array.py b/src/zarr/array.py similarity index 97% rename from src/zarr/v3/array.py rename to src/zarr/array.py index c0a00a624e..b739b310d4 100644 --- a/src/zarr/v3/array.py +++ b/src/zarr/array.py @@ -16,12 +16,12 @@ from typing import Any, Dict, Iterable, Literal, Optional, Tuple, Union import numpy as np -from zarr.v3.abc.codec import Codec +from zarr.abc.codec import Codec -# from zarr.v3.array_v2 import ArrayV2 -from zarr.v3.codecs import BytesCodec -from zarr.v3.common import ( +# from zarr.array_v2 import ArrayV2 +from zarr.codecs import BytesCodec +from zarr.common import ( ZARR_JSON, ArraySpec, ChunkCoords, @@ -29,14 +29,14 @@ SliceSelection, concurrent_map, ) -from zarr.v3.config import RuntimeConfiguration - -from zarr.v3.indexing import BasicIndexer, all_chunk_coords, is_total_slice -from zarr.v3.chunk_grids import RegularChunkGrid -from zarr.v3.chunk_key_encodings import DefaultChunkKeyEncoding, V2ChunkKeyEncoding -from zarr.v3.metadata import ArrayMetadata -from zarr.v3.store import StoreLike, StorePath, make_store_path -from zarr.v3.sync import sync +from zarr.config import RuntimeConfiguration + +from zarr.indexing import BasicIndexer, all_chunk_coords, is_total_slice +from zarr.chunk_grids import RegularChunkGrid +from zarr.chunk_key_encodings import DefaultChunkKeyEncoding, V2ChunkKeyEncoding +from zarr.metadata import ArrayMetadata +from zarr.store import StoreLike, StorePath, make_store_path +from zarr.sync import sync def parse_array_metadata(data: Any): diff --git a/src/zarr/v3/array_v2.py b/src/zarr/array_v2.py similarity index 96% rename from src/zarr/v3/array_v2.py rename to src/zarr/array_v2.py index f150d2dbd2..8c2cd3faec 100644 --- a/src/zarr/v3/array_v2.py +++ b/src/zarr/array_v2.py @@ -10,7 +10,7 @@ from numcodecs.compat import ensure_bytes, ensure_ndarray -from zarr.v3.common import ( +from zarr.common import ( ZARRAY_JSON, ZATTRS_JSON, BytesLike, @@ -20,14 +20,14 @@ concurrent_map, to_thread, ) -from zarr.v3.config import RuntimeConfiguration -from zarr.v3.indexing import BasicIndexer, all_chunk_coords, is_total_slice -from zarr.v3.metadata import ArrayV2Metadata -from zarr.v3.store import StoreLike, StorePath, make_store_path -from zarr.v3.sync import sync +from zarr.config import RuntimeConfiguration +from zarr.indexing import BasicIndexer, all_chunk_coords, is_total_slice +from zarr.metadata import ArrayV2Metadata +from zarr.store import StoreLike, StorePath, make_store_path +from zarr.sync import sync if TYPE_CHECKING: - from zarr.v3.array import Array + from zarr.array import Array @dataclass(frozen=True) @@ -441,14 +441,14 @@ def resize(self, new_shape: ChunkCoords) -> ArrayV2: async def convert_to_v3_async(self) -> Array: from sys import byteorder as sys_byteorder - from zarr.v3.abc.codec import Codec - from zarr.v3.array import Array - from zarr.v3.common import ZARR_JSON - from zarr.v3.chunk_grids import RegularChunkGrid - from zarr.v3.chunk_key_encodings import V2ChunkKeyEncoding - from zarr.v3.metadata import ArrayMetadata, DataType + from zarr.abc.codec import Codec + from zarr.array import Array + from zarr.common import ZARR_JSON + from zarr.chunk_grids import RegularChunkGrid + from zarr.chunk_key_encodings import V2ChunkKeyEncoding + from zarr.metadata import ArrayMetadata, DataType - from zarr.v3.codecs import ( + from zarr.codecs import ( BloscCodec, BloscShuffle, BytesCodec, diff --git a/src/zarr/v3/attributes.py b/src/zarr/attributes.py similarity index 92% rename from src/zarr/v3/attributes.py rename to src/zarr/attributes.py index edbc84d8aa..8086e18d7b 100644 --- a/src/zarr/v3/attributes.py +++ b/src/zarr/attributes.py @@ -3,8 +3,8 @@ from typing import TYPE_CHECKING, Any, Union if TYPE_CHECKING: - from zarr.v3.group import Group - from zarr.v3.array import Array + from zarr.group import Group + from zarr.array import Array class Attributes(MutableMapping[str, Any]): diff --git a/src/zarr/v3/chunk_grids.py b/src/zarr/chunk_grids.py similarity index 94% rename from src/zarr/v3/chunk_grids.py rename to src/zarr/chunk_grids.py index b0a2a7bb36..73557f6e4b 100644 --- a/src/zarr/v3/chunk_grids.py +++ b/src/zarr/chunk_grids.py @@ -1,9 +1,9 @@ from __future__ import annotations from typing import TYPE_CHECKING, Any, Dict from dataclasses import dataclass -from zarr.v3.abc.metadata import Metadata +from zarr.abc.metadata import Metadata -from zarr.v3.common import ( +from zarr.common import ( JSON, ChunkCoords, ChunkCoordsLike, diff --git a/src/zarr/v3/chunk_key_encodings.py b/src/zarr/chunk_key_encodings.py similarity index 97% rename from src/zarr/v3/chunk_key_encodings.py rename to src/zarr/chunk_key_encodings.py index 9889a2f04a..ebc7654dde 100644 --- a/src/zarr/v3/chunk_key_encodings.py +++ b/src/zarr/chunk_key_encodings.py @@ -2,9 +2,9 @@ from abc import abstractmethod from typing import TYPE_CHECKING, Dict, Literal, cast from dataclasses import dataclass -from zarr.v3.abc.metadata import Metadata +from zarr.abc.metadata import Metadata -from zarr.v3.common import ( +from zarr.common import ( JSON, ChunkCoords, parse_named_configuration, diff --git a/src/zarr/codecs/__init__.py b/src/zarr/codecs/__init__.py new file mode 100644 index 0000000000..8fa0c9f7b0 --- /dev/null +++ b/src/zarr/codecs/__init__.py @@ -0,0 +1,9 @@ +from __future__ import annotations + +from zarr.codecs.blosc import BloscCodec, BloscCname, BloscShuffle # noqa: F401 +from zarr.codecs.bytes import BytesCodec, Endian # noqa: F401 +from zarr.codecs.crc32c_ import Crc32cCodec # noqa: F401 +from zarr.codecs.gzip import GzipCodec # noqa: F401 +from zarr.codecs.sharding import ShardingCodec, ShardingCodecIndexLocation # noqa: F401 +from zarr.codecs.transpose import TransposeCodec # noqa: F401 +from zarr.codecs.zstd import ZstdCodec # noqa: F401 diff --git a/src/zarr/v3/codecs/blosc.py b/src/zarr/codecs/blosc.py similarity index 95% rename from src/zarr/v3/codecs/blosc.py rename to src/zarr/codecs/blosc.py index 479865241f..374375e6c2 100644 --- a/src/zarr/v3/codecs/blosc.py +++ b/src/zarr/codecs/blosc.py @@ -9,15 +9,15 @@ import numpy as np from numcodecs.blosc import Blosc -from zarr.v3.abc.codec import BytesBytesCodec -from zarr.v3.codecs.registry import register_codec -from zarr.v3.common import parse_enum, parse_named_configuration, to_thread +from zarr.abc.codec import BytesBytesCodec +from zarr.codecs.registry import register_codec +from zarr.common import parse_enum, parse_named_configuration, to_thread if TYPE_CHECKING: from typing import Dict, Optional from typing_extensions import Self - from zarr.v3.common import JSON, ArraySpec, BytesLike - from zarr.v3.config import RuntimeConfiguration + from zarr.common import JSON, ArraySpec, BytesLike + from zarr.config import RuntimeConfiguration class BloscShuffle(Enum): diff --git a/src/zarr/v3/codecs/bytes.py b/src/zarr/codecs/bytes.py similarity index 92% rename from src/zarr/v3/codecs/bytes.py rename to src/zarr/codecs/bytes.py index f92fe5606d..1b872ac6c6 100644 --- a/src/zarr/v3/codecs/bytes.py +++ b/src/zarr/codecs/bytes.py @@ -7,13 +7,13 @@ import numpy as np -from zarr.v3.abc.codec import ArrayBytesCodec -from zarr.v3.codecs.registry import register_codec -from zarr.v3.common import parse_enum, parse_named_configuration +from zarr.abc.codec import ArrayBytesCodec +from zarr.codecs.registry import register_codec +from zarr.common import parse_enum, parse_named_configuration if TYPE_CHECKING: - from zarr.v3.common import JSON, ArraySpec, BytesLike - from zarr.v3.config import RuntimeConfiguration + from zarr.common import JSON, ArraySpec, BytesLike + from zarr.config import RuntimeConfiguration from typing_extensions import Self diff --git a/src/zarr/v3/codecs/crc32c_.py b/src/zarr/codecs/crc32c_.py similarity index 86% rename from src/zarr/v3/codecs/crc32c_.py rename to src/zarr/codecs/crc32c_.py index 555bdeae3b..04d5b88d70 100644 --- a/src/zarr/v3/codecs/crc32c_.py +++ b/src/zarr/codecs/crc32c_.py @@ -7,15 +7,15 @@ from crc32c import crc32c -from zarr.v3.abc.codec import BytesBytesCodec -from zarr.v3.codecs.registry import register_codec -from zarr.v3.common import parse_named_configuration +from zarr.abc.codec import BytesBytesCodec +from zarr.codecs.registry import register_codec +from zarr.common import parse_named_configuration if TYPE_CHECKING: from typing import Dict, Optional from typing_extensions import Self - from zarr.v3.common import JSON, BytesLike, ArraySpec - from zarr.v3.config import RuntimeConfiguration + from zarr.common import JSON, BytesLike, ArraySpec + from zarr.config import RuntimeConfiguration @dataclass(frozen=True) diff --git a/src/zarr/v3/codecs/gzip.py b/src/zarr/codecs/gzip.py similarity index 87% rename from src/zarr/v3/codecs/gzip.py rename to src/zarr/codecs/gzip.py index 478eee90c1..f75f5b743e 100644 --- a/src/zarr/v3/codecs/gzip.py +++ b/src/zarr/codecs/gzip.py @@ -4,15 +4,15 @@ from typing import TYPE_CHECKING from numcodecs.gzip import GZip -from zarr.v3.abc.codec import BytesBytesCodec -from zarr.v3.codecs.registry import register_codec -from zarr.v3.common import parse_named_configuration, to_thread +from zarr.abc.codec import BytesBytesCodec +from zarr.codecs.registry import register_codec +from zarr.common import parse_named_configuration, to_thread if TYPE_CHECKING: from typing import Optional, Dict from typing_extensions import Self - from zarr.v3.common import JSON, ArraySpec, BytesLike - from zarr.v3.config import RuntimeConfiguration + from zarr.common import JSON, ArraySpec, BytesLike + from zarr.config import RuntimeConfiguration def parse_gzip_level(data: JSON) -> int: diff --git a/src/zarr/v3/codecs/pipeline.py b/src/zarr/codecs/pipeline.py similarity index 95% rename from src/zarr/v3/codecs/pipeline.py rename to src/zarr/codecs/pipeline.py index 7bb872eb79..4908ee8057 100644 --- a/src/zarr/v3/codecs/pipeline.py +++ b/src/zarr/codecs/pipeline.py @@ -5,7 +5,7 @@ from dataclasses import dataclass from warnings import warn -from zarr.v3.abc.codec import ( +from zarr.abc.codec import ( ArrayArrayCodec, ArrayBytesCodec, ArrayBytesCodecPartialDecodeMixin, @@ -13,16 +13,16 @@ BytesBytesCodec, Codec, ) -from zarr.v3.abc.metadata import Metadata -from zarr.v3.codecs.registry import get_codec_class -from zarr.v3.common import parse_named_configuration +from zarr.abc.metadata import Metadata +from zarr.codecs.registry import get_codec_class +from zarr.common import parse_named_configuration if TYPE_CHECKING: from typing import Iterator, List, Optional, Tuple, Union - from zarr.v3.store import StorePath - from zarr.v3.metadata import ArrayMetadata - from zarr.v3.config import RuntimeConfiguration - from zarr.v3.common import JSON, ArraySpec, BytesLike, SliceSelection + from zarr.store import StorePath + from zarr.metadata import ArrayMetadata + from zarr.config import RuntimeConfiguration + from zarr.common import JSON, ArraySpec, BytesLike, SliceSelection @dataclass(frozen=True) @@ -53,7 +53,7 @@ def evolve(self, array_spec: ArraySpec) -> CodecPipeline: @classmethod def from_list(cls, codecs: List[Codec]) -> CodecPipeline: - from zarr.v3.codecs.sharding import ShardingCodec + from zarr.codecs.sharding import ShardingCodec if not any(isinstance(codec, ArrayBytesCodec) for codec in codecs): raise ValueError("Exactly one array-to-bytes codec is required.") diff --git a/src/zarr/v3/codecs/registry.py b/src/zarr/codecs/registry.py similarity index 96% rename from src/zarr/v3/codecs/registry.py rename to src/zarr/codecs/registry.py index 4cf2736685..140e1372ef 100644 --- a/src/zarr/v3/codecs/registry.py +++ b/src/zarr/codecs/registry.py @@ -3,7 +3,7 @@ if TYPE_CHECKING: from typing import Dict, Type - from zarr.v3.abc.codec import Codec + from zarr.abc.codec import Codec from importlib.metadata import EntryPoint, entry_points as get_entry_points diff --git a/src/zarr/v3/codecs/sharding.py b/src/zarr/codecs/sharding.py similarity index 97% rename from src/zarr/v3/codecs/sharding.py rename to src/zarr/codecs/sharding.py index 0385154c0f..948e46f132 100644 --- a/src/zarr/v3/codecs/sharding.py +++ b/src/zarr/codecs/sharding.py @@ -6,17 +6,17 @@ import numpy as np -from zarr.v3.abc.codec import ( +from zarr.abc.codec import ( Codec, ArrayBytesCodec, ArrayBytesCodecPartialDecodeMixin, ArrayBytesCodecPartialEncodeMixin, ) -from zarr.v3.codecs.bytes import BytesCodec -from zarr.v3.codecs.crc32c_ import Crc32cCodec -from zarr.v3.codecs.pipeline import CodecPipeline -from zarr.v3.codecs.registry import register_codec -from zarr.v3.common import ( +from zarr.codecs.bytes import BytesCodec +from zarr.codecs.crc32c_ import Crc32cCodec +from zarr.codecs.pipeline import CodecPipeline +from zarr.codecs.registry import register_codec +from zarr.common import ( ArraySpec, ChunkCoordsLike, concurrent_map, @@ -25,14 +25,14 @@ parse_shapelike, product, ) -from zarr.v3.chunk_grids import RegularChunkGrid -from zarr.v3.indexing import ( +from zarr.chunk_grids import RegularChunkGrid +from zarr.indexing import ( BasicIndexer, c_order_iter, is_total_slice, morton_order_iter, ) -from zarr.v3.metadata import ( +from zarr.metadata import ( ArrayMetadata, runtime_configuration as make_runtime_configuration, parse_codecs, @@ -42,14 +42,14 @@ from typing import Awaitable, Callable, Dict, Iterator, List, Optional, Set, Tuple from typing_extensions import Self - from zarr.v3.store import StorePath - from zarr.v3.common import ( + from zarr.store import StorePath + from zarr.common import ( JSON, ChunkCoords, BytesLike, SliceSelection, ) - from zarr.v3.config import RuntimeConfiguration + from zarr.config import RuntimeConfiguration MAX_UINT_64 = 2**64 - 1 diff --git a/src/zarr/v3/codecs/transpose.py b/src/zarr/codecs/transpose.py similarity index 92% rename from src/zarr/v3/codecs/transpose.py rename to src/zarr/codecs/transpose.py index b663230e35..c63327f6fc 100644 --- a/src/zarr/v3/codecs/transpose.py +++ b/src/zarr/codecs/transpose.py @@ -3,17 +3,17 @@ from dataclasses import dataclass, replace -from zarr.v3.common import JSON, ArraySpec, ChunkCoordsLike, parse_named_configuration +from zarr.common import JSON, ArraySpec, ChunkCoordsLike, parse_named_configuration if TYPE_CHECKING: - from zarr.v3.config import RuntimeConfiguration + from zarr.config import RuntimeConfiguration from typing import TYPE_CHECKING, Optional, Tuple from typing_extensions import Self import numpy as np -from zarr.v3.abc.codec import ArrayArrayCodec -from zarr.v3.codecs.registry import register_codec +from zarr.abc.codec import ArrayArrayCodec +from zarr.codecs.registry import register_codec def parse_transpose_order(data: Union[JSON, Iterable[int]]) -> Tuple[int, ...]: @@ -65,7 +65,7 @@ def evolve(self, array_spec: ArraySpec) -> Self: return self def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec: - from zarr.v3.common import ArraySpec + from zarr.common import ArraySpec return ArraySpec( shape=tuple(chunk_spec.shape[self.order[i]] for i in range(chunk_spec.ndim)), diff --git a/src/zarr/v3/codecs/zstd.py b/src/zarr/codecs/zstd.py similarity index 89% rename from src/zarr/v3/codecs/zstd.py rename to src/zarr/codecs/zstd.py index 774bb8bdbb..41db850ab6 100644 --- a/src/zarr/v3/codecs/zstd.py +++ b/src/zarr/codecs/zstd.py @@ -5,15 +5,15 @@ from zstandard import ZstdCompressor, ZstdDecompressor -from zarr.v3.abc.codec import BytesBytesCodec -from zarr.v3.codecs.registry import register_codec -from zarr.v3.common import parse_named_configuration, to_thread +from zarr.abc.codec import BytesBytesCodec +from zarr.codecs.registry import register_codec +from zarr.common import parse_named_configuration, to_thread if TYPE_CHECKING: from typing import Dict, Optional from typing_extensions import Self - from zarr.v3.config import RuntimeConfiguration - from zarr.v3.common import BytesLike, JSON, ArraySpec + from zarr.config import RuntimeConfiguration + from zarr.common import BytesLike, JSON, ArraySpec def parse_zstd_level(data: JSON) -> int: diff --git a/src/zarr/v3/common.py b/src/zarr/common.py similarity index 100% rename from src/zarr/v3/common.py rename to src/zarr/common.py diff --git a/src/zarr/v3/config.py b/src/zarr/config.py similarity index 100% rename from src/zarr/v3/config.py rename to src/zarr/config.py diff --git a/src/zarr/v3/group.py b/src/zarr/group.py similarity index 97% rename from src/zarr/v3/group.py rename to src/zarr/group.py index fcd2fea215..aff24ed0d9 100644 --- a/src/zarr/v3/group.py +++ b/src/zarr/group.py @@ -5,14 +5,14 @@ import json import logging from typing import Any, Dict, Literal, Optional, Union, AsyncIterator, List -from zarr.v3.abc.metadata import Metadata - -from zarr.v3.array import AsyncArray, Array -from zarr.v3.attributes import Attributes -from zarr.v3.common import ZARR_JSON, ZARRAY_JSON, ZATTRS_JSON, ZGROUP_JSON -from zarr.v3.config import RuntimeConfiguration, SyncConfiguration -from zarr.v3.store import StoreLike, StorePath, make_store_path -from zarr.v3.sync import SyncMixin, sync +from zarr.abc.metadata import Metadata + +from zarr.array import AsyncArray, Array +from zarr.attributes import Attributes +from zarr.common import ZARR_JSON, ZARRAY_JSON, ZATTRS_JSON, ZGROUP_JSON +from zarr.config import RuntimeConfiguration, SyncConfiguration +from zarr.store import StoreLike, StorePath, make_store_path +from zarr.sync import SyncMixin, sync logger = logging.getLogger("zarr.group") diff --git a/src/zarr/v3/indexing.py b/src/zarr/indexing.py similarity index 98% rename from src/zarr/v3/indexing.py rename to src/zarr/indexing.py index 15adad111d..7c1a4df226 100644 --- a/src/zarr/v3/indexing.py +++ b/src/zarr/indexing.py @@ -4,7 +4,7 @@ import math from typing import Iterator, List, NamedTuple, Optional, Tuple -from zarr.v3.common import ChunkCoords, Selection, SliceSelection, product +from zarr.common import ChunkCoords, Selection, SliceSelection, product def _ensure_tuple(v: Selection) -> SliceSelection: diff --git a/src/zarr/v3/metadata.py b/src/zarr/metadata.py similarity index 96% rename from src/zarr/v3/metadata.py rename to src/zarr/metadata.py index 573b8484f0..8eba9a0b5a 100644 --- a/src/zarr/v3/metadata.py +++ b/src/zarr/metadata.py @@ -6,19 +6,19 @@ import numpy as np import numpy.typing as npt -from zarr.v3.chunk_grids import ChunkGrid, RegularChunkGrid -from zarr.v3.chunk_key_encodings import ChunkKeyEncoding, parse_separator +from zarr.chunk_grids import ChunkGrid, RegularChunkGrid +from zarr.chunk_key_encodings import ChunkKeyEncoding, parse_separator if TYPE_CHECKING: from typing import Literal, Union, List, Optional, Tuple - from zarr.v3.codecs.pipeline import CodecPipeline + from zarr.codecs.pipeline import CodecPipeline -from zarr.v3.abc.codec import Codec -from zarr.v3.abc.metadata import Metadata +from zarr.abc.codec import Codec +from zarr.abc.metadata import Metadata -from zarr.v3.common import ( +from zarr.common import ( JSON, ArraySpec, ChunkCoords, @@ -26,7 +26,7 @@ parse_fill_value, parse_shapelike, ) -from zarr.v3.config import RuntimeConfiguration, parse_indexing_order +from zarr.config import RuntimeConfiguration, parse_indexing_order def runtime_configuration( @@ -370,7 +370,7 @@ def parse_v2_metadata(data: ArrayV2Metadata) -> ArrayV2Metadata: def parse_codecs(data: Iterable[Union[Codec, JSON]]) -> CodecPipeline: - from zarr.v3.codecs.pipeline import CodecPipeline + from zarr.codecs.pipeline import CodecPipeline if not isinstance(data, Iterable): raise TypeError(f"Expected iterable, got {type(data)}") diff --git a/src/zarr/store/__init__.py b/src/zarr/store/__init__.py new file mode 100644 index 0000000000..b1c3a5f720 --- /dev/null +++ b/src/zarr/store/__init__.py @@ -0,0 +1,5 @@ +# flake8: noqa +from zarr.store.core import StorePath, StoreLike, make_store_path +from zarr.store.remote import RemoteStore +from zarr.store.local import LocalStore +from zarr.store.memory import MemoryStore diff --git a/src/zarr/v3/store/core.py b/src/zarr/store/core.py similarity index 94% rename from src/zarr/v3/store/core.py rename to src/zarr/store/core.py index 16714d9e30..29506aa619 100644 --- a/src/zarr/v3/store/core.py +++ b/src/zarr/store/core.py @@ -3,9 +3,9 @@ from pathlib import Path from typing import Any, Optional, Tuple, Union -from zarr.v3.common import BytesLike -from zarr.v3.abc.store import Store -from zarr.v3.store.local import LocalStore +from zarr.common import BytesLike +from zarr.abc.store import Store +from zarr.store.local import LocalStore def _dereference_path(root: str, path: str) -> str: diff --git a/src/zarr/v3/store/local.py b/src/zarr/store/local.py similarity index 98% rename from src/zarr/v3/store/local.py rename to src/zarr/store/local.py index 8f02b904c0..1e9e880875 100644 --- a/src/zarr/v3/store/local.py +++ b/src/zarr/store/local.py @@ -5,8 +5,8 @@ from pathlib import Path from typing import Union, Optional, List, Tuple -from zarr.v3.abc.store import Store -from zarr.v3.common import BytesLike, concurrent_map, to_thread +from zarr.abc.store import Store +from zarr.common import BytesLike, concurrent_map, to_thread def _get(path: Path, byte_range: Optional[Tuple[int, Optional[int]]] = None) -> bytes: diff --git a/src/zarr/v3/store/memory.py b/src/zarr/store/memory.py similarity index 97% rename from src/zarr/v3/store/memory.py rename to src/zarr/store/memory.py index afacfa4321..9661b6cea7 100644 --- a/src/zarr/v3/store/memory.py +++ b/src/zarr/store/memory.py @@ -2,8 +2,8 @@ from typing import Optional, MutableMapping, List, Tuple -from zarr.v3.common import BytesLike -from zarr.v3.abc.store import Store +from zarr.common import BytesLike +from zarr.abc.store import Store # TODO: this store could easily be extended to wrap any MutuableMapping store from v2 diff --git a/src/zarr/v3/store/remote.py b/src/zarr/store/remote.py similarity index 96% rename from src/zarr/v3/store/remote.py rename to src/zarr/store/remote.py index 0e6fc84e08..c42cf3f56d 100644 --- a/src/zarr/v3/store/remote.py +++ b/src/zarr/store/remote.py @@ -2,9 +2,9 @@ from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, Union -from zarr.v3.abc.store import Store -from zarr.v3.store.core import _dereference_path -from zarr.v3.common import BytesLike +from zarr.abc.store import Store +from zarr.store.core import _dereference_path +from zarr.common import BytesLike if TYPE_CHECKING: diff --git a/src/zarr/v3/sync.py b/src/zarr/sync.py similarity index 98% rename from src/zarr/v3/sync.py rename to src/zarr/sync.py index 41dfeadba9..d9665b4c58 100644 --- a/src/zarr/v3/sync.py +++ b/src/zarr/sync.py @@ -12,7 +12,7 @@ ) from typing_extensions import ParamSpec -from zarr.v3.config import SyncConfiguration +from zarr.config import SyncConfiguration # From https://github.com/fsspec/filesystem_spec/blob/master/fsspec/asyn.py diff --git a/src/zarr/v3/codecs/__init__.py b/src/zarr/v3/codecs/__init__.py deleted file mode 100644 index 474344ec25..0000000000 --- a/src/zarr/v3/codecs/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -from __future__ import annotations - -from zarr.v3.codecs.blosc import BloscCodec, BloscCname, BloscShuffle # noqa: F401 -from zarr.v3.codecs.bytes import BytesCodec, Endian # noqa: F401 -from zarr.v3.codecs.crc32c_ import Crc32cCodec # noqa: F401 -from zarr.v3.codecs.gzip import GzipCodec # noqa: F401 -from zarr.v3.codecs.sharding import ShardingCodec, ShardingCodecIndexLocation # noqa: F401 -from zarr.v3.codecs.transpose import TransposeCodec # noqa: F401 -from zarr.v3.codecs.zstd import ZstdCodec # noqa: F401 diff --git a/src/zarr/v3/store/__init__.py b/src/zarr/v3/store/__init__.py deleted file mode 100644 index 2268381d2a..0000000000 --- a/src/zarr/v3/store/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# flake8: noqa -from zarr.v3.store.core import StorePath, StoreLike, make_store_path -from zarr.v3.store.remote import RemoteStore -from zarr.v3.store.local import LocalStore -from zarr.v3.store.memory import MemoryStore diff --git a/tests/v2/test_storage.py b/tests/v2/test_storage.py index 4746a30e37..b6877aa713 100644 --- a/tests/v2/test_storage.py +++ b/tests/v2/test_storage.py @@ -68,8 +68,8 @@ # from zarr.tests.util import CountingDict, have_fsspec, skip_test_env_var, abs_container, mktemp # from zarr.util import ConstantMap, json_dumps -from zarr.v3.abc.store import Store -from zarr.v3.store import MemoryStore as KVStore, LocalStore +from zarr.abc.store import Store +from zarr.store import MemoryStore as KVStore, LocalStore # @contextmanager diff --git a/tests/v3/test_codecs.py b/tests/v3/test_codecs.py index dba28cd995..ffd225668b 100644 --- a/tests/v3/test_codecs.py +++ b/tests/v3/test_codecs.py @@ -8,11 +8,11 @@ import numpy as np import pytest import zarr.v2 -from zarr.v3.abc.codec import Codec -from zarr.v3.array import Array, AsyncArray -from zarr.v3.common import Selection -from zarr.v3.indexing import morton_order_iter -from zarr.v3.codecs import ( +from zarr.abc.codec import Codec +from zarr.array import Array, AsyncArray +from zarr.common import Selection +from zarr.indexing import morton_order_iter +from zarr.codecs import ( ShardingCodec, ShardingCodecIndexLocation, BloscCodec, @@ -21,10 +21,10 @@ TransposeCodec, ZstdCodec, ) -from zarr.v3.metadata import runtime_configuration +from zarr.metadata import runtime_configuration -from zarr.v3.abc.store import Store -from zarr.v3.store import MemoryStore, StorePath +from zarr.abc.store import Store +from zarr.store import MemoryStore, StorePath @dataclass(frozen=True) diff --git a/tests/v3/test_common.py b/tests/v3/test_common.py index 0f664ef22e..b5690d0d7e 100644 --- a/tests/v3/test_common.py +++ b/tests/v3/test_common.py @@ -5,9 +5,9 @@ from typing import Literal, Any, Tuple import numpy as np -from zarr.v3.config import parse_indexing_order -from zarr.v3.common import parse_shapelike -from zarr.v3.common import parse_name, product +from zarr.config import parse_indexing_order +from zarr.common import parse_shapelike +from zarr.common import parse_name, product import pytest diff --git a/tests/v3/test_group.py b/tests/v3/test_group.py index f5b5dde86d..1150469db1 100644 --- a/tests/v3/test_group.py +++ b/tests/v3/test_group.py @@ -1,9 +1,9 @@ import pytest import numpy as np -from zarr.v3.group import AsyncGroup, Group, GroupMetadata -from zarr.v3.store import LocalStore, StorePath -from zarr.v3.config import RuntimeConfiguration +from zarr.group import AsyncGroup, Group, GroupMetadata +from zarr.store import LocalStore, StorePath +from zarr.config import RuntimeConfiguration @pytest.fixture diff --git a/tests/v3/test_metadata.py b/tests/v3/test_metadata.py index 6dacf2c700..33df4a6438 100644 --- a/tests/v3/test_metadata.py +++ b/tests/v3/test_metadata.py @@ -5,7 +5,7 @@ if TYPE_CHECKING: from typing import Sequence, Any -from zarr.v3.metadata import parse_dimension_names, parse_zarr_format_v2, parse_zarr_format_v3 +from zarr.metadata import parse_dimension_names, parse_zarr_format_v2, parse_zarr_format_v3 # todo: test From b7a7fa2b7dff018be29cc15603ee4d5bdc679353 Mon Sep 17 00:00:00 2001 From: Joseph Hamman Date: Mon, 22 Apr 2024 21:31:45 -0700 Subject: [PATCH 3/4] add extra doc deps --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 5771f7b972..3dcda98980 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,10 @@ docs = [ 'pydata-sphinx-theme', 'numpydoc', 'numcodecs[msgpack]', + "msgpack", + "lmdb", + "zstandard", + "crc32c", ] extra = [ 'attrs', From 013954cd7b738f833180c801f1e8c771ced053c3 Mon Sep 17 00:00:00 2001 From: Joseph Hamman Date: Mon, 22 Apr 2024 21:40:36 -0700 Subject: [PATCH 4/4] import __version__ in root __init__ --- src/zarr/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/zarr/__init__.py b/src/zarr/__init__.py index 5be8f9764b..9ae9dc54c4 100644 --- a/src/zarr/__init__.py +++ b/src/zarr/__init__.py @@ -13,6 +13,10 @@ make_store_path, ) from zarr.sync import sync as _sync +from zarr._version import version as __version__ + +# in case setuptools scm screw up and find version to be 0.0.0 +assert not __version__.startswith("0.0.0") async def open_auto_async(