MCPcopy Index your code
hub / github.com/pydata/xarray / test_map_blocks_errors_bad_template

Function test_map_blocks_errors_bad_template

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

Source from the content-addressed store, hash-verified

1465
1466@pytest.mark.parametrize("obj", [make_da(), make_ds()])
1467def test_map_blocks_errors_bad_template(obj):
1468 with pytest.raises(ValueError, match=r"unexpected coordinate variables"):
1469 xr.map_blocks(lambda x: x.assign_coords(a=10), obj, template=obj).compute()
1470 with pytest.raises(ValueError, match=r"does not contain coordinate variables"):
1471 xr.map_blocks(lambda x: x.drop_vars("cxy"), obj, template=obj).compute()
1472 with pytest.raises(ValueError, match=r"Dimensions {'x'} missing"):
1473 xr.map_blocks(lambda x: x.isel(x=1), obj, template=obj).compute()
1474 with pytest.raises(ValueError, match=r"Received dimension 'x' of length 1"):
1475 xr.map_blocks(lambda x: x.isel(x=[1]), obj, template=obj).compute()
1476 with pytest.raises(TypeError, match=r"must be a DataArray"):
1477 xr.map_blocks(lambda x: x.isel(x=[1]), obj, template=(obj,)).compute() # type: ignore[arg-type]
1478 with pytest.raises(ValueError, match=r"map_blocks requires that one block"):
1479 xr.map_blocks(
1480 lambda x: x.isel(x=[1]).assign_coords(x=10), obj, template=obj.isel(x=[1])
1481 ).compute()
1482 with pytest.raises(ValueError, match=r"Expected index 'x' to be"):
1483 xr.map_blocks(
1484 lambda a: a.isel(x=[1]).assign_coords(x=[120]), # assign bad index values
1485 obj,
1486 template=xr.concat(
1487 [obj.isel(x=[i]) for i in [1, 5, 9]], data_vars=None, dim="x"
1488 ),
1489 ).compute()
1490
1491
1492def test_map_blocks_errors_bad_template_2(map_ds):

Callers

nothing calls this directly

Calls 6

computeMethod · 0.45
map_blocksMethod · 0.45
assign_coordsMethod · 0.45
drop_varsMethod · 0.45
iselMethod · 0.45
concatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…