MCPcopy Create free account
hub / github.com/pydata/xarray / test_vectorize_dask_new_output_dims

Function test_vectorize_dask_new_output_dims

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

Source from the content-addressed store, hash-verified

1866
1867@requires_dask
1868def test_vectorize_dask_new_output_dims() -> None:
1869 # regression test for GH3574
1870 # run vectorization in dask.array.gufunc by using `dask='parallelized'`
1871 data_array = xr.DataArray([[0, 1, 2], [1, 2, 3]], dims=("x", "y"))
1872 func = lambda x: x[np.newaxis, ...]
1873 expected = data_array.expand_dims("z")
1874 actual = apply_ufunc(
1875 func,
1876 data_array.chunk({"x": 1}),
1877 output_core_dims=[["z"]],
1878 vectorize=True,
1879 dask="parallelized",
1880 output_dtypes=[float],
1881 dask_gufunc_kwargs=dict(output_sizes={"z": 1}),
1882 ).transpose(*expected.dims)
1883 assert_identical(expected, actual)
1884
1885 with pytest.raises(
1886 ValueError, match=r"dimension 'z1' in 'output_sizes' must correspond"
1887 ):
1888 apply_ufunc(
1889 func,
1890 data_array.chunk({"x": 1}),
1891 output_core_dims=[["z"]],
1892 vectorize=True,
1893 dask="parallelized",
1894 output_dtypes=[float],
1895 dask_gufunc_kwargs=dict(output_sizes={"z1": 1}),
1896 )
1897
1898 with pytest.raises(
1899 ValueError, match=r"dimension 'z' in 'output_core_dims' needs corresponding"
1900 ):
1901 apply_ufunc(
1902 func,
1903 data_array.chunk({"x": 1}),
1904 output_core_dims=[["z"]],
1905 vectorize=True,
1906 dask="parallelized",
1907 output_dtypes=[float],
1908 )
1909
1910
1911def test_output_wrong_number() -> None:

Callers

nothing calls this directly

Calls 5

expand_dimsMethod · 0.95
chunkMethod · 0.95
apply_ufuncFunction · 0.90
assert_identicalFunction · 0.70
transposeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…