Skip to content

Commit 2b191dd

Browse files
committed
Add type annotations to open_zarr parameters
All parameters in open_zarr were untyped, which caused type checkers like pyright to reject valid arguments (e.g. passing "auto" for chunks). Adds annotations to every parameter and the return type, using T_Chunks for the chunks parameter and matching types from the docstrings for the rest. Fixes #11221
1 parent 6c36d81 commit 2b191dd

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

xarray/backends/zarr.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import json
55
import os
66
import struct
7-
from collections.abc import Hashable, Iterable, Mapping
7+
from collections.abc import Hashable, Iterable, Mapping, MutableMapping
88
from typing import TYPE_CHECKING, Any, Literal, Self, cast
99

1010
import numpy as np
@@ -28,6 +28,7 @@
2828
from xarray.core.treenode import NodePath
2929
from xarray.core.types import ZarrWriteModes
3030
from xarray.core.utils import (
31+
Default,
3132
FrozenDict,
3233
HiddenKeyDict,
3334
_default,
@@ -43,7 +44,7 @@
4344
if TYPE_CHECKING:
4445
from xarray.core.dataset import Dataset
4546
from xarray.core.datatree import DataTree
46-
from xarray.core.types import ZarrArray, ZarrGroup
47+
from xarray.core.types import T_Chunks, ZarrArray, ZarrGroup
4748

4849

4950
def _get_mappers(*, storage_options, store, chunk_store):
@@ -1411,30 +1412,30 @@ def _validate_encoding(self, encoding) -> None:
14111412

14121413

14131414
def open_zarr(
1414-
store,
1415-
group=None,
1416-
synchronizer=None,
1417-
chunks=_default,
1418-
decode_cf=True,
1419-
mask_and_scale=True,
1420-
decode_times=True,
1421-
concat_characters=True,
1415+
store: str | os.PathLike[Any] | MutableMapping | None,
1416+
group: str | None = None,
1417+
synchronizer: object | None = None,
1418+
chunks: T_Chunks | Default = _default,
1419+
decode_cf: bool = True,
1420+
mask_and_scale: bool = True,
1421+
decode_times: bool = True,
1422+
concat_characters: bool = True,
14221423
decode_coords: Literal["coordinates", "all"] | bool = True,
1423-
drop_variables=None,
1424-
consolidated=None,
1425-
overwrite_encoded_chunks=False,
1426-
chunk_store=None,
1427-
storage_options=None,
1428-
decode_timedelta=None,
1429-
use_cftime=None,
1430-
zarr_version=None,
1431-
zarr_format=None,
1432-
use_zarr_fill_value_as_mask=None,
1424+
drop_variables: str | Iterable[str] | None = None,
1425+
consolidated: bool | None = None,
1426+
overwrite_encoded_chunks: bool = False,
1427+
chunk_store: MutableMapping | None = None,
1428+
storage_options: dict[str, Any] | None = None,
1429+
decode_timedelta: bool | None = None,
1430+
use_cftime: bool | None = None,
1431+
zarr_version: int | None = None,
1432+
zarr_format: int | None = None,
1433+
use_zarr_fill_value_as_mask: bool | None = None,
14331434
chunked_array_type: str | None = None,
14341435
from_array_kwargs: dict[str, Any] | None = None,
1435-
create_default_indexes=True,
1436-
**kwargs,
1437-
):
1436+
create_default_indexes: bool = True,
1437+
**kwargs: Any,
1438+
) -> Dataset:
14381439
"""Load and decode a dataset from a Zarr store.
14391440
14401441
The `store` object should be a valid store for a Zarr group. `store`

0 commit comments

Comments
 (0)