Implement the common part of `__getitem__` and `__setitem__`.
(
self,
keys: SelectionType,
)
| 373 | return self.listarr # Scalar case |
| 374 | |
| 375 | def _interpret_indexing( |
| 376 | self, |
| 377 | keys: SelectionType, |
| 378 | ) -> tuple[np.ndarray, np.ndarray, np.ndarray, list[int]]: |
| 379 | """Implement the common part of `__getitem__` and `__setitem__`.""" |
| 380 | maxlen = len(self.shape) |
| 381 | shape = (maxlen,) |
| 382 | startl = np.empty(shape=shape, dtype=SizeType) |
| 383 | stopl = np.empty(shape=shape, dtype=SizeType) |
| 384 | stepl = np.empty(shape=shape, dtype=SizeType) |
| 385 | stop_none = np.zeros(shape=shape, dtype=SizeType) |
| 386 | if not isinstance(keys, tuple): |
| 387 | keys = (keys,) |
| 388 | nkeys = len(keys) |
| 389 | dim = 0 |
| 390 | # Here is some problem when dealing with [...,...] params |
| 391 | # but this is a bit weird way to pass parameters anyway |
| 392 | for key in keys: |
| 393 | ellipsis = 0 # Sentinel |
| 394 | if isinstance(key, type(Ellipsis)): |
| 395 | ellipsis = 1 |
| 396 | for diml in range(dim, len(self.shape) - (nkeys - dim) + 1): |
| 397 | startl[dim] = 0 |
| 398 | stopl[dim] = self.shape[diml] |
| 399 | stepl[dim] = 1 |
| 400 | dim += 1 |
| 401 | elif dim >= maxlen: |
| 402 | raise IndexError( |
| 403 | "Too many indices for object '%s'" % self._v_pathname |
| 404 | ) |
| 405 | elif is_idx(key): |
| 406 | key = operator.index(key) |
| 407 | |
| 408 | # Protection for index out of range |
| 409 | if key >= self.shape[dim]: |
| 410 | raise IndexError("Index out of range") |
| 411 | if key < 0: |
| 412 | # To support negative values (Fixes bug #968149) |
| 413 | key += self.shape[dim] |
| 414 | start, stop, step = self._process_range( |
| 415 | key, key + 1, 1, dim=dim |
| 416 | ) |
| 417 | stop_none[dim] = 1 |
| 418 | elif isinstance(key, slice): |
| 419 | start, stop, step = self._process_range( |
| 420 | key.start, key.stop, key.step, dim=dim |
| 421 | ) |
| 422 | else: |
| 423 | raise TypeError("Non-valid index or slice: %s" % key) |
| 424 | if not ellipsis: |
| 425 | startl[dim] = start |
| 426 | stopl[dim] = stop |
| 427 | stepl[dim] = step |
| 428 | dim += 1 |
| 429 | |
| 430 | # Complete the other dimensions, if needed |
| 431 | if dim < len(self.shape): |
| 432 | for diml in range(dim, len(self.shape)): |
no test coverage detected