diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 05d06400f2e..a1b0d78823b 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -1,6 +1,7 @@ from __future__ import annotations import datetime +import sys import warnings from typing import ( TYPE_CHECKING, @@ -88,6 +89,12 @@ from .types import T_DataArray, T_Xarray +# TODO: Remove this check once python 3.7 is not supported: +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + def _infer_coords_and_dims( shape, coords, dims @@ -1094,6 +1101,7 @@ def chunk( self, chunks: Union[ int, + Literal["auto"], Tuple[int, ...], Tuple[Tuple[int, ...], ...], Mapping[Any, Union[None, int, Tuple[int, ...]]], @@ -1114,9 +1122,9 @@ def chunk( Parameters ---------- - chunks : int, tuple of int or mapping of hashable to int, optional - Chunk sizes along each dimension, e.g., ``5``, ``(5, 5)`` or - ``{'x': 5, 'y': 5}``. + chunks : int, "auto", tuple of int or mapping of hashable to int, optional + Chunk sizes along each dimension, e.g., ``5``, ``"auto"``, ``(5, 5)`` or + ``{"x": 5, "y": 5}``. name_prefix : str, optional Prefix for the name of the new dask array. token : str, optional diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 3fbc6154c5d..5f6c4fb2e34 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -104,6 +104,12 @@ broadcast_variables, ) +# TODO: Remove this check once python 3.7 is not supported: +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + if TYPE_CHECKING: from ..backends import AbstractDataStore, ZarrStore from .dataarray import DataArray @@ -2131,7 +2137,7 @@ def chunk( self, chunks: Union[ int, - str, + Literal["auto"], Mapping[Any, Union[None, int, str, Tuple[int, ...]]], ] = {}, # {} even though it's technically unsafe, is being used intentionally here (#4667) name_prefix: str = "xarray-", @@ -2150,8 +2156,8 @@ def chunk( Parameters ---------- - chunks : int, 'auto' or mapping, optional - Chunk sizes along each dimension, e.g., ``5`` or + chunks : int, "auto" or mapping of hashable to int, optional + Chunk sizes along each dimension, e.g., ``5``, ``"auto"``, or ``{"x": 5, "y": 5}``. name_prefix : str, optional Prefix for the name of any new dask arrays.