(self, index: Any)
| 6215 | self._array = array |
| 6216 | |
| 6217 | def __getitem__(self, index: Any) -> Array: |
| 6218 | from dask.array.slicing import normalize_index |
| 6219 | |
| 6220 | if not isinstance(index, tuple): |
| 6221 | index = (index,) |
| 6222 | if sum(isinstance(ind, (np.ndarray, list)) for ind in index) > 1: |
| 6223 | raise ValueError("Can only slice with a single list") |
| 6224 | if any(ind is None for ind in index): |
| 6225 | raise ValueError("Slicing with np.newaxis or None is not supported") |
| 6226 | index = normalize_index(index, self._array.numblocks) |
| 6227 | index = tuple( |
| 6228 | slice(k, k + 1) if isinstance(k, Number) else k # type: ignore[operator] |
| 6229 | for k in index |
| 6230 | ) |
| 6231 | |
| 6232 | name = "blocks-" + tokenize(self._array, index) |
| 6233 | |
| 6234 | new_keys = self._array._key_array[index] |
| 6235 | |
| 6236 | chunks = tuple( |
| 6237 | tuple(np.array(c)[i].tolist()) for c, i in zip(self._array.chunks, index) |
| 6238 | ) |
| 6239 | |
| 6240 | keys = product(*(range(len(c)) for c in chunks)) |
| 6241 | |
| 6242 | graph: Graph = {(name,) + key: tuple(new_keys[key].tolist()) for key in keys} |
| 6243 | |
| 6244 | hlg = HighLevelGraph.from_collections(name, graph, dependencies=[self._array]) |
| 6245 | return Array(hlg, name, chunks, meta=self._array) |
| 6246 | |
| 6247 | def __eq__(self, other: object) -> bool: |
| 6248 | if isinstance(other, BlockView): |
nothing calls this directly
no test coverage detected