Skip to content

Commit 45b4436

Browse files
authored
Improve map_blocks docs (#5076)
* improve map_blocks docs * clarify load
1 parent 2bbac15 commit 45b4436

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

doc/user-guide/dask.rst

+7
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,13 @@ Notice that the 0-shaped sizes were not printed to screen. Since ``template`` ha
511511
mapped.identical(expected)
512512
513513
514+
.. tip::
515+
516+
As :py:func:`map_blocks` loads each block into memory, reduce as much as possible objects consumed by user functions.
517+
For example, drop useless variables before calling ``func`` with :py:func:`map_blocks`.
518+
519+
520+
514521
Chunking and performance
515522
------------------------
516523

xarray/core/dataarray.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3666,8 +3666,8 @@ def map_blocks(
36663666
Notes
36673667
-----
36683668
This function is designed for when ``func`` needs to manipulate a whole xarray object
3669-
subset to each block. In the more common case where ``func`` can work on numpy arrays, it is
3670-
recommended to use ``apply_ufunc``.
3669+
subset to each block. Each block is loaded into memory. In the more common case where
3670+
``func`` can work on numpy arrays, it is recommended to use ``apply_ufunc``.
36713671
36723672
If none of the variables in this object is backed by dask arrays, calling this function is
36733673
equivalent to calling ``func(obj, *args, **kwargs)``.

xarray/core/dataset.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6274,8 +6274,8 @@ def map_blocks(
62746274
Notes
62756275
-----
62766276
This function is designed for when ``func`` needs to manipulate a whole xarray object
6277-
subset to each block. In the more common case where ``func`` can work on numpy arrays, it is
6278-
recommended to use ``apply_ufunc``.
6277+
subset to each block. Each block is loaded into memory. In the more common case where
6278+
``func`` can work on numpy arrays, it is recommended to use ``apply_ufunc``.
62796279
62806280
If none of the variables in this object is backed by dask arrays, calling this function is
62816281
equivalent to calling ``func(obj, *args, **kwargs)``.

xarray/core/parallel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ def map_blocks(
208208
Notes
209209
-----
210210
This function is designed for when ``func`` needs to manipulate a whole xarray object
211-
subset to each block. In the more common case where ``func`` can work on numpy arrays, it is
212-
recommended to use ``apply_ufunc``.
211+
subset to each block. Each block is loaded into memory. In the more common case where
212+
``func`` can work on numpy arrays, it is recommended to use ``apply_ufunc``.
213213
214214
If none of the variables in ``obj`` is backed by dask arrays, calling this function is
215215
equivalent to calling ``func(obj, *args, **kwargs)``.

0 commit comments

Comments
 (0)