MCPcopy
hub / github.com/pydata/xarray / test_map_blocks_da_ds_with_template

Function test_map_blocks_da_ds_with_template

xarray/tests/test_dask.py:1410–1427  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

1408
1409@pytest.mark.parametrize("obj", [make_da(), make_ds()])
1410def test_map_blocks_da_ds_with_template(obj):
1411 func = lambda x: x.isel(x=[1])
1412 # a simple .isel(x=[1, 5, 9]) puts all those in a single chunk.
1413 template = xr.concat([obj.isel(x=[i]) for i in [1, 5, 9]], data_vars=None, dim="x")
1414 with raise_if_dask_computes():
1415 actual = xr.map_blocks(func, obj, template=template)
1416 assert_identical(actual, template)
1417
1418 # Check that indexes are written into the graph directly
1419 dsk = dict(actual.__dask_graph__())
1420 assert {k for k in dsk if "x-coordinate" in k}
1421 assert all(
1422 isinstance(v, PandasIndex) for k, v in dsk.items() if "x-coordinate" in k
1423 )
1424
1425 with raise_if_dask_computes():
1426 actual = obj.map_blocks(func, template=template)
1427 assert_identical(actual, template)
1428
1429
1430def test_map_blocks_roundtrip_string_index():

Callers

nothing calls this directly

Calls 7

raise_if_dask_computesFunction · 0.90
assert_identicalFunction · 0.90
itemsMethod · 0.80
iselMethod · 0.45
concatMethod · 0.45
map_blocksMethod · 0.45
__dask_graph__Method · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…