Skip to content

Commit 7c7a882

Browse files
committed
Mark V3 API experimental
Following discussion at this week's community call, a few additional precautions are being implemented here: - [x] rename the var ZARR_V3_API_AVAILABLE to ZARR_V3_EXPERIMENTAL_API - [x] add an assertion to prevent use of zarr_version=3 w/o the var
1 parent bd7ab16 commit 7c7a882

File tree

6 files changed

+37
-6
lines changed

6 files changed

+37
-6
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
ZARR_TEST_ABS: 1
7272
ZARR_TEST_MONGO: 1
7373
ZARR_TEST_REDIS: 1
74-
ZARR_V3_API_AVAILABLE: 1
74+
ZARR_V3_EXPERIMENTAL_API: 1
7575
run: |
7676
conda activate zarr-env
7777
mkdir ~/blob_emulator

docs/release.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Enhancements
2323
package has the necessary classes and functions for evaluating Zarr V3.
2424
Since the format is not yet finalized, the classes and functions are not
2525
automatically imported into the regular `zarr` name space. Setting the
26-
`ZARR_V3_API_AVAILABLE` environment variable will activate them.
26+
`ZARR_V3_EXPERIMENTAL_API` environment variable will activate them.
2727
By :user:`Greggory Lee <grlee77>`; :issue:`898`, :issue:`1006`, and :issue:`1007`.
2828

2929
* **Create FSStore from an existing fsspec filesystem**. If you have created

zarr/_storage/store.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@
1818

1919
DEFAULT_ZARR_VERSION = 2
2020

21-
v3_api_available = os.environ.get('ZARR_V3_API_AVAILABLE', '0').lower() not in ['0', 'false']
21+
v3_api_available = os.environ.get('ZARR_V3_EXPERIMENTAL_API', '0').lower() not in ['0', 'false']
22+
23+
24+
def assert_zarr_v3_api_available():
25+
if not v3_api_available:
26+
raise NotImplementedError(
27+
"# V3 reading and writing is experimental! To enable support, set:\n"
28+
"ZARR_V3_EXPERIMENTAL_API=1"
29+
)
2230

2331

2432
class BaseStore(MutableMapping):

zarr/convenience.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import re
66
from collections.abc import Mapping, MutableMapping
77

8-
from zarr._storage.store import data_root, meta_root
8+
from zarr._storage.store import data_root, meta_root, assert_zarr_v3_api_available
99
from zarr.core import Array
1010
from zarr.creation import array as _create_array
1111
from zarr.creation import open_array
@@ -1209,6 +1209,8 @@ def is_zarr_key(key):
12091209

12101210
else:
12111211

1212+
assert_zarr_v3_api_available()
1213+
12121214
sfx = _get_metadata_suffix(store) # type: ignore
12131215

12141216
def is_zarr_key(key):
@@ -1288,6 +1290,7 @@ def open_consolidated(store: StoreLike, metadata_key=".zmetadata", mode="r+", **
12881290
if store._store_version == 2:
12891291
ConsolidatedStoreClass = ConsolidatedMetadataStore
12901292
else:
1293+
assert_zarr_v3_api_available()
12911294
ConsolidatedStoreClass = ConsolidatedMetadataStoreV3
12921295
# default is to store within 'consolidated' group on v3
12931296
if not metadata_key.startswith('meta/root/'):

zarr/core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import numpy as np
1212
from numcodecs.compat import ensure_bytes, ensure_ndarray
1313

14-
from zarr._storage.store import _prefix_to_attrs_key
14+
from zarr._storage.store import _prefix_to_attrs_key, assert_zarr_v3_api_available
1515
from zarr.attrs import Attributes
1616
from zarr.codecs import AsType, get_codec
1717
from zarr.errors import ArrayNotFoundError, ReadOnlyError, ArrayIndexError
@@ -171,6 +171,9 @@ def __init__(
171171
if zarr_version is None:
172172
zarr_version = store._store_version
173173

174+
if zarr_version != 2:
175+
assert_zarr_v3_api_available()
176+
174177
if chunk_store is not None:
175178
chunk_store = normalize_store_arg(chunk_store,
176179
zarr_version=zarr_version)

zarr/hierarchy.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import numpy as np
55

6-
from zarr._storage.store import _get_metadata_suffix, data_root, meta_root, DEFAULT_ZARR_VERSION
6+
from zarr._storage.store import (_get_metadata_suffix, data_root, meta_root,
7+
DEFAULT_ZARR_VERSION, assert_zarr_v3_api_available)
78
from zarr.attrs import Attributes
89
from zarr.core import Array
910
from zarr.creation import (array, create, empty, empty_like, full, full_like,
@@ -117,6 +118,10 @@ def __init__(self, store, path=None, read_only=False, chunk_store=None,
117118
store: BaseStore = _normalize_store_arg(store, zarr_version=zarr_version)
118119
if zarr_version is None:
119120
zarr_version = getattr(store, '_store_version', DEFAULT_ZARR_VERSION)
121+
122+
if zarr_version != 2:
123+
assert_zarr_v3_api_available()
124+
120125
if chunk_store is not None:
121126
chunk_store: BaseStore = _normalize_store_arg(chunk_store, zarr_version=zarr_version)
122127
self._store = store
@@ -1178,6 +1183,10 @@ def _normalize_store_arg(store, *, storage_options=None, mode="r",
11781183
zarr_version=None):
11791184
if zarr_version is None:
11801185
zarr_version = getattr(store, '_store_version', DEFAULT_ZARR_VERSION)
1186+
1187+
if zarr_version != 2:
1188+
assert_zarr_v3_api_available()
1189+
11811190
if store is None:
11821191
return MemoryStore() if zarr_version == 2 else MemoryStoreV3()
11831192
return normalize_store_arg(store,
@@ -1234,6 +1243,10 @@ def group(store=None, overwrite=False, chunk_store=None,
12341243
store = _normalize_store_arg(store, zarr_version=zarr_version)
12351244
if zarr_version is None:
12361245
zarr_version = getattr(store, '_store_version', DEFAULT_ZARR_VERSION)
1246+
1247+
if zarr_version != 2:
1248+
assert_zarr_v3_api_available()
1249+
12371250
if zarr_version == 3 and path is None:
12381251
raise ValueError(f"path must be provided for a v{zarr_version} group")
12391252
path = normalize_storage_path(path)
@@ -1305,6 +1318,10 @@ def open_group(store=None, mode='a', cache_attrs=True, synchronizer=None, path=N
13051318
zarr_version=zarr_version)
13061319
if zarr_version is None:
13071320
zarr_version = getattr(store, '_store_version', DEFAULT_ZARR_VERSION)
1321+
1322+
if zarr_version != 2:
1323+
assert_zarr_v3_api_available()
1324+
13081325
if chunk_store is not None:
13091326
chunk_store = _normalize_store_arg(chunk_store,
13101327
storage_options=storage_options,

0 commit comments

Comments
 (0)