Skip to content

Make xr.corr and xr.map_blocks work without dask #5731

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

Merged
merged 14 commits into from
Nov 24, 2021
Merged
5 changes: 3 additions & 2 deletions xarray/core/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .alignment import align
from .dataarray import DataArray
from .dataset import Dataset
from .pycompat import is_duck_dask_array

try:
import dask
Expand Down Expand Up @@ -325,13 +326,13 @@ def _wrapper(
raise TypeError("kwargs must be a mapping (for example, a dict)")

for value in kwargs.values():
if dask.is_dask_collection(value):
if is_duck_dask_array(value):
raise TypeError(
"Cannot pass dask collections in kwargs yet. Please compute or "
"load values before passing to map_blocks."
)

if not dask.is_dask_collection(obj):
if not is_duck_dask_array(obj):
return func(obj, *args, **kwargs)

all_args = [obj] + list(args)
Expand Down
16 changes: 16 additions & 0 deletions xarray/tests/test_computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,22 @@ def test_covcorr_consistency(da_a, da_b, dim):
assert_allclose(actual, expected)


@requires_dask
@pytest.mark.parametrize(
"da_a, da_b",
arrays_w_tuples()[1],
)
@pytest.mark.parametrize("dim", [None, "time", "x"])
def test_cov_lazycov_consistency(da_a, da_b, dim):
da_al = da_a.chunk()
da_bl = da_b.chunk()
c_abl = xr.corr(da_al, da_bl)
c_ab = xr.corr(da_a, da_b)
c_ab_mixed = xr.corr(da_a, da_bl)
assert_allclose(c_ab, c_abl)
assert_allclose(c_ab, c_ab_mixed)


@pytest.mark.parametrize(
"da_a",
arrays_w_tuples()[0],
Expand Down