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