From 61483c9cf885b2f6ed372fa669a173733a3ac361 Mon Sep 17 00:00:00 2001 From: Keewis Date: Mon, 8 Mar 2021 22:14:32 +0100 Subject: [PATCH 1/4] mention map_blocks in the See Also section of apply_ufunc [skip-ci] --- xarray/core/computation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/xarray/core/computation.py b/xarray/core/computation.py index e68c6b2629d..145c5b643c8 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -1015,6 +1015,7 @@ def earth_mover_distance(first_samples, numpy.broadcast_arrays numba.vectorize numba.guvectorize + xarray.map_blocks References ---------- From 551db82ad1440f099409eb7f965f29ec826d1f08 Mon Sep 17 00:00:00 2001 From: Keewis Date: Tue, 9 Mar 2021 15:06:00 +0100 Subject: [PATCH 2/4] copy and modify the notes from map_blocks [skip-ci] --- xarray/core/computation.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xarray/core/computation.py b/xarray/core/computation.py index 145c5b643c8..73a39968422 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -923,6 +923,12 @@ def apply_ufunc( Single value or tuple of Dataset, DataArray, Variable, dask.array.Array or numpy.ndarray, the first type on that list to appear on an input. + Notes + ----- + This function is designed for the more common case where ``func`` can work on numpy + arrays. If ``func`` needs to manipulate a whole xarray object subset to each block + it is possible to use ``map_blocks``. + Examples -------- Calculate the vector magnitude of two arguments: From 45e6a6f62b6edc9f0ec30110b4e1bcd4ea8057fb Mon Sep 17 00:00:00 2001 From: keewis Date: Tue, 9 Mar 2021 15:21:30 +0100 Subject: [PATCH 3/4] Update xarray/core/computation.py Co-authored-by: Deepak Cherian --- xarray/core/computation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/xarray/core/computation.py b/xarray/core/computation.py index 73a39968422..3ca03206288 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -1021,6 +1021,7 @@ def earth_mover_distance(first_samples, numpy.broadcast_arrays numba.vectorize numba.guvectorize + dask.array.apply_gufunc xarray.map_blocks References From 05181f49213885dc073252f49b1a5a9244efb3c9 Mon Sep 17 00:00:00 2001 From: Keewis Date: Tue, 9 Mar 2021 22:55:56 +0100 Subject: [PATCH 4/4] link to map_blocks and mention the overhead --- xarray/core/computation.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xarray/core/computation.py b/xarray/core/computation.py index 3ca03206288..027bf29000a 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -927,7 +927,9 @@ def apply_ufunc( ----- This function is designed for the more common case where ``func`` can work on numpy arrays. If ``func`` needs to manipulate a whole xarray object subset to each block - it is possible to use ``map_blocks``. + it is possible to use :py:func:`xarray.map_blocks`. + + Note that due to the overhead ``map_blocks`` is considerably slower than ``apply_ufunc``. Examples --------