Skip to content

Commit 5418c24

Browse files
committed
zarr_version fixes
* removed open_consolidated workarounds * removed _store_version check * pass through zarr_version
1 parent 636838c commit 5418c24

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

xarray/backends/zarr.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
import warnings
77
from collections.abc import Callable, Iterable
8-
from typing import TYPE_CHECKING, Any
8+
from typing import TYPE_CHECKING, Any, Literal
99

1010
import numpy as np
1111
import packaging.version
@@ -56,6 +56,7 @@ def _zarr_v3() -> bool:
5656

5757
# need some special secret attributes to tell us the dimensions
5858
DIMENSION_KEY = "_ARRAY_DIMENSIONS"
59+
ZarrFormat = Literal[2, 3]
5960

6061

6162
def encode_zarr_attr_value(value):
@@ -1436,30 +1437,18 @@ def _get_open_params(
14361437
if isinstance(store, os.PathLike):
14371438
store = os.fspath(store)
14381439

1439-
if zarr_version is None:
1440-
# default to 2 if store doesn't specify it's version (e.g. a path)
1441-
zarr_version = getattr(store, "_store_version", 2)
1442-
14431440
open_kwargs = dict(
14441441
# mode='a-' is a handcrafted xarray specialty
14451442
mode="a" if mode == "a-" else mode,
14461443
synchronizer=synchronizer,
14471444
path=group,
14481445
)
14491446
open_kwargs["storage_options"] = storage_options
1450-
if zarr_version > 2:
1451-
open_kwargs["zarr_version"] = zarr_version
1452-
1453-
if consolidated or consolidate_on_close:
1454-
raise ValueError(
1455-
"consolidated metadata has not been implemented for zarr "
1456-
f"version {zarr_version} yet. Set consolidated=False for "
1457-
f"zarr version {zarr_version}. See also "
1458-
"https://github.com/zarr-developers/zarr-specs/issues/136"
1459-
)
14601447

1461-
if consolidated is None:
1462-
consolidated = False
1448+
if _zarr_v3():
1449+
open_kwargs["zarr_format"] = zarr_version
1450+
else:
1451+
open_kwargs["zarr_version"] = zarr_version
14631452

14641453
if chunk_store is not None:
14651454
open_kwargs["chunk_store"] = chunk_store

0 commit comments

Comments
 (0)