Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto chunk #4064

Merged
merged 15 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Breaking changes

New Features
~~~~~~~~~~~~
- ``chunks='auto'`` is now supported in the ``chunks`` argument of
:py:meth:`Dataset.chunk`.
(:issue:`4055`)
By `Andrew Williams <https://github.com/AndrewWilliams3142>`_
- Added :py:meth:`DataArray.polyfit` and :py:func:`xarray.polyval` for fitting polynomials. (:issue:`3349`)
By `Pascal Bourgault <https://github.com/aulemahal>`_.
- Control over attributes of result in :py:func:`merge`, :py:func:`concat`,
Expand Down
9 changes: 6 additions & 3 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,10 @@ def chunks(self) -> Mapping[Hashable, Tuple[int, ...]]:
def chunk(
self,
chunks: Union[
None, Number, Mapping[Hashable, Union[None, Number, Tuple[Number, ...]]]
None,
Number,
str,
Mapping[Hashable, Union[None, Number, str, Tuple[Number, ...]]],
] = None,
name_prefix: str = "xarray-",
token: str = None,
Expand All @@ -1716,7 +1719,7 @@ def chunk(

Parameters
----------
chunks : int or mapping, optional
chunks : int, 'auto' or mapping, optional
Chunk sizes along each dimension, e.g., ``5`` or
``{'x': 5, 'y': 5}``.
name_prefix : str, optional
Expand All @@ -1733,7 +1736,7 @@ def chunk(
"""
from dask.base import tokenize

if isinstance(chunks, Number):
if isinstance(chunks, (Number, str)):
chunks = dict.fromkeys(self.dims, chunks)

if chunks is not None:
Expand Down
7 changes: 7 additions & 0 deletions xarray/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,13 @@ def test_unify_chunks_shallow_copy(obj, transform):
assert_identical(obj, unified) and obj is not obj.unify_chunks()


@pytest.mark.parametrize("obj", [make_da()])
def test_auto_chunk_da(obj):
expected = obj.chunk("auto").data
actual = obj.data.rechunk("auto")
AndrewILWilliams marked this conversation as resolved.
Show resolved Hide resolved
np.testing.assert_array_equal(actual, expected)
dcherian marked this conversation as resolved.
Show resolved Hide resolved


def test_map_blocks_error(map_da, map_ds):
def bad_func(darray):
return (darray * darray.x + 5 * darray.y)[:1, :1]
Expand Down