Skip to content

Commit

Permalink
DOC: Add "auto" to dataarray chunk method (#6068)
Browse files Browse the repository at this point in the history
* DOC: Uniformize DS and DA chunk method

* DOC: Use literal instead of str

Co-authored-by: Illviljan <14371165+Illviljan@users.noreply.github.com>
  • Loading branch information
bzah and Illviljan authored Jan 3, 2022
1 parent bc8d7f9 commit 0a40bf1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
14 changes: 11 additions & 3 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import datetime
import sys
import warnings
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -90,6 +91,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
Expand Down Expand Up @@ -1096,6 +1103,7 @@ def chunk(
self,
chunks: Union[
int,
Literal["auto"],
Tuple[int, ...],
Tuple[Tuple[int, ...], ...],
Mapping[Any, Union[None, int, Tuple[int, ...]]],
Expand All @@ -1116,9 +1124,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
Expand Down
12 changes: 9 additions & 3 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,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
Expand Down Expand Up @@ -2140,7 +2146,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-",
Expand All @@ -2159,8 +2165,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.
Expand Down

0 comments on commit 0a40bf1

Please sign in to comment.