Skip to content

Commit 0a40bf1

Browse files
bzahIllviljan
andauthored
DOC: Add "auto" to dataarray chunk method (#6068)
* DOC: Uniformize DS and DA chunk method * DOC: Use literal instead of str Co-authored-by: Illviljan <[email protected]>
1 parent bc8d7f9 commit 0a40bf1

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

xarray/core/dataarray.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import datetime
4+
import sys
45
import warnings
56
from typing import (
67
TYPE_CHECKING,
@@ -90,6 +91,12 @@
9091

9192
from .types import T_DataArray, T_Xarray
9293

94+
# TODO: Remove this check once python 3.7 is not supported:
95+
if sys.version_info >= (3, 8):
96+
from typing import Literal
97+
else:
98+
from typing_extensions import Literal
99+
93100

94101
def _infer_coords_and_dims(
95102
shape, coords, dims
@@ -1096,6 +1103,7 @@ def chunk(
10961103
self,
10971104
chunks: Union[
10981105
int,
1106+
Literal["auto"],
10991107
Tuple[int, ...],
11001108
Tuple[Tuple[int, ...], ...],
11011109
Mapping[Any, Union[None, int, Tuple[int, ...]]],
@@ -1116,9 +1124,9 @@ def chunk(
11161124
11171125
Parameters
11181126
----------
1119-
chunks : int, tuple of int or mapping of hashable to int, optional
1120-
Chunk sizes along each dimension, e.g., ``5``, ``(5, 5)`` or
1121-
``{'x': 5, 'y': 5}``.
1127+
chunks : int, "auto", tuple of int or mapping of hashable to int, optional
1128+
Chunk sizes along each dimension, e.g., ``5``, ``"auto"``, ``(5, 5)`` or
1129+
``{"x": 5, "y": 5}``.
11221130
name_prefix : str, optional
11231131
Prefix for the name of the new dask array.
11241132
token : str, optional

xarray/core/dataset.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@
105105
broadcast_variables,
106106
)
107107

108+
# TODO: Remove this check once python 3.7 is not supported:
109+
if sys.version_info >= (3, 8):
110+
from typing import Literal
111+
else:
112+
from typing_extensions import Literal
113+
108114
if TYPE_CHECKING:
109115
from ..backends import AbstractDataStore, ZarrStore
110116
from .dataarray import DataArray
@@ -2140,7 +2146,7 @@ def chunk(
21402146
self,
21412147
chunks: Union[
21422148
int,
2143-
str,
2149+
Literal["auto"],
21442150
Mapping[Any, Union[None, int, str, Tuple[int, ...]]],
21452151
] = {}, # {} even though it's technically unsafe, is being used intentionally here (#4667)
21462152
name_prefix: str = "xarray-",
@@ -2159,8 +2165,8 @@ def chunk(
21592165
21602166
Parameters
21612167
----------
2162-
chunks : int, 'auto' or mapping, optional
2163-
Chunk sizes along each dimension, e.g., ``5`` or
2168+
chunks : int, "auto" or mapping of hashable to int, optional
2169+
Chunk sizes along each dimension, e.g., ``5``, ``"auto"``, or
21642170
``{"x": 5, "y": 5}``.
21652171
name_prefix : str, optional
21662172
Prefix for the name of any new dask arrays.

0 commit comments

Comments
 (0)