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

Function test_vectorized_indexing_dask_array

xarray/tests/test_indexing.py:1136–1163  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1134
1135@requires_dask
1136def test_vectorized_indexing_dask_array() -> None:
1137 # https://github.com/pydata/xarray/issues/2511#issuecomment-563330352
1138 darr = DataArray(data=[0.2, 0.4, 0.6], coords={"z": range(3)}, dims=("z",))
1139 indexer = DataArray(
1140 data=np.random.randint(0, 3, 8).reshape(4, 2).astype(int),
1141 coords={"y": range(4), "x": range(2)},
1142 dims=("y", "x"),
1143 )
1144 expected = darr[indexer]
1145
1146 # fails because we can't index pd.Index lazily (yet).
1147 # We could make this succeed by auto-chunking the values
1148 # and constructing a lazy index variable, and not automatically
1149 # create an index for it.
1150 with pytest.raises(ValueError, match="Cannot index with"):
1151 with raise_if_dask_computes():
1152 darr.chunk()[indexer.chunk({"y": 2})]
1153 with pytest.raises(ValueError, match="Cannot index with"):
1154 with raise_if_dask_computes():
1155 actual = darr[indexer.chunk({"y": 2})]
1156
1157 with raise_if_dask_computes():
1158 actual = darr.drop_vars("z").chunk()[indexer.chunk({"y": 2})]
1159 assert_identical(actual, expected.drop_vars("z"))
1160
1161 with raise_if_dask_computes():
1162 actual_variable = darr.variable.chunk()[indexer.variable.chunk({"y": 2})]
1163 assert_identical(actual_variable, expected.variable)
1164
1165
1166@requires_dask

Callers

nothing calls this directly

Calls 8

chunkMethod · 0.95
drop_varsMethod · 0.95
DataArrayClass · 0.90
raise_if_dask_computesFunction · 0.90
assert_identicalFunction · 0.90
astypeMethod · 0.45
chunkMethod · 0.45
drop_varsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…