()
| 1134 | |
| 1135 | @requires_dask |
| 1136 | def 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…