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

Function test_map_blocks_error

xarray/tests/test_dask.py:1188–1220  ·  view source on GitHub ↗
(map_da, map_ds)

Source from the content-addressed store, hash-verified

1186
1187
1188def test_map_blocks_error(map_da, map_ds):
1189 def bad_func(darray):
1190 return (darray * darray.x + 5 * darray.y)[:1, :1]
1191
1192 with pytest.raises(ValueError, match=r"Received dimension 'x' of length 1"):
1193 xr.map_blocks(bad_func, map_da).compute()
1194
1195 def returns_numpy(darray):
1196 return (darray * darray.x + 5 * darray.y).values
1197
1198 with pytest.raises(TypeError, match=r"Function must return an xarray DataArray"):
1199 xr.map_blocks(returns_numpy, map_da)
1200
1201 with pytest.raises(TypeError, match=r"args must be"):
1202 xr.map_blocks(operator.add, map_da, args=10) # type: ignore[arg-type]
1203
1204 with pytest.raises(TypeError, match=r"kwargs must be"):
1205 xr.map_blocks(operator.add, map_da, args=[10], kwargs=[20]) # type: ignore[arg-type]
1206
1207 def really_bad_func(darray):
1208 raise ValueError("couldn't do anything.")
1209
1210 with pytest.raises(Exception, match=r"Cannot infer"):
1211 xr.map_blocks(really_bad_func, map_da)
1212
1213 ds_copy = map_ds.copy()
1214 ds_copy["cxy"] = ds_copy.cxy.chunk({"y": 10})
1215
1216 with pytest.raises(ValueError, match=r"inconsistent chunks"):
1217 xr.map_blocks(bad_func, ds_copy)
1218
1219 with pytest.raises(TypeError, match=r"Cannot pass dask collections"):
1220 xr.map_blocks(bad_func, map_da, kwargs=dict(a=map_da.chunk()))
1221
1222
1223@pytest.mark.parametrize("obj", [make_da(), make_ds()])

Callers

nothing calls this directly

Calls 4

computeMethod · 0.45
map_blocksMethod · 0.45
copyMethod · 0.45
chunkMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…