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

Function test_apply_dask_new_output_dimension

xarray/tests/test_computation.py:1330–1355  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1328
1329@requires_dask
1330def test_apply_dask_new_output_dimension() -> None:
1331 import dask.array as da
1332
1333 array = da.ones((2, 2), chunks=(1, 1))
1334 data_array = xr.DataArray(array, dims=("x", "y"))
1335
1336 def stack_negative(obj):
1337 def func(x):
1338 return np.stack([x, -x], axis=-1)
1339
1340 return apply_ufunc(
1341 func,
1342 obj,
1343 output_core_dims=[["sign"]],
1344 dask="parallelized",
1345 output_dtypes=[obj.dtype],
1346 dask_gufunc_kwargs=dict(output_sizes={"sign": 2}),
1347 )
1348
1349 expected = stack_negative(data_array.compute())
1350
1351 actual = stack_negative(data_array)
1352 assert actual.dims == ("x", "y", "sign")
1353 assert actual.shape == (2, 2, 2)
1354 assert isinstance(actual.data, da.Array)
1355 assert_identical(expected, actual)
1356
1357
1358@requires_dask

Callers

nothing calls this directly

Calls 3

computeMethod · 0.95
stack_negativeFunction · 0.85
assert_identicalFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…