(map_da, map_ds)
| 1186 | |
| 1187 | |
| 1188 | def 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()]) |
nothing calls this directly
no test coverage detected
searching dependent graphs…