Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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: 2 additions & 2 deletions xarray/core/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def infer_template(
"Please supply the 'template' kwarg to map_blocks."
) from e

if not isinstance(template, Dataset | DataArray):
if not isinstance(template, (Dataset, DataArray)):
raise TypeError(
"Function must return an xarray DataArray or Dataset. Instead it returned "
f"{type(template)}"
Expand Down Expand Up @@ -351,7 +351,7 @@ def _wrapper(
result = func(*converted_args, **kwargs)

merged_coordinates = merge(
[arg.coords for arg in args if isinstance(arg, Dataset | DataArray)],
[arg.coords for arg in args if isinstance(arg, (Dataset, DataArray))],
join="exact",
compat="override",
).coords
Expand Down
11 changes: 11 additions & 0 deletions xarray/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,17 @@ def really_bad_func(darray):
xr.map_blocks(bad_func, map_da, kwargs=dict(a=map_da.chunk()))


@pytest.mark.parametrize("obj", [make_da(), make_ds()])
def test_map_blocks_accepts_da_ds_template(obj):
def identity(x):
return x

with raise_if_dask_computes():
result = xr.map_blocks(identity, obj, template=obj)

assert_identical(result, obj)


@pytest.mark.parametrize("obj", [make_da(), make_ds()])
def test_map_blocks(obj):
def func(obj):
Expand Down
Loading