MCPcopy Index your code
hub / github.com/PyTables/PyTables / _fancy_selection

Method _fancy_selection

tables/array.py:447–633  ·  view source on GitHub ↗

Perform a NumPy-style fancy selection in `self`. Implements advanced NumPy-style selection operations in addition to the standard slice-and-int behavior. Indexing arguments may be ints, slices or lists of indices. Note: This is a backport from the h5py project.

(self, args: list[int | list[int]])

Source from the content-addressed store, hash-verified

445 return startl, stopl, stepl, shape
446
447 def _fancy_selection(self, args: list[int | list[int]]) -> tuple[
448 list[tuple[int, int, int, int, str]],
449 tuple[int, np.ndarray] | None,
450 tuple[int, ...],
451 ]:
452 """Perform a NumPy-style fancy selection in `self`.
453
454 Implements advanced NumPy-style selection operations in
455 addition to the standard slice-and-int behavior.
456
457 Indexing arguments may be ints, slices or lists of indices.
458
459 Note: This is a backport from the h5py project.
460
461 """
462 # Internal functions
463
464 def validate_number(num: int, length: int) -> None:
465 """Validate a list member for the given axis length."""
466 try:
467 num = int(num)
468 except TypeError:
469 raise TypeError("Illegal index: %r" % num)
470 if num > length - 1:
471 raise IndexError("Index out of bounds: %d" % num)
472
473 def expand_ellipsis(
474 args: tuple[int | list[int], ...], rank: int
475 ) -> list:
476 """Expand ellipsis objects and fill in missing axes."""
477 n_el = sum(1 for arg in args if arg is Ellipsis)
478 if n_el > 1:
479 raise IndexError("Only one ellipsis may be used.")
480 elif n_el == 0 and len(args) != rank:
481 args = args + (Ellipsis,)
482
483 final_args = []
484 n_args = len(args)
485 for idx, arg in enumerate(args):
486 if arg is Ellipsis:
487 final_args.extend((slice(None),) * (rank - n_args + 1))
488 else:
489 final_args.append(arg)
490
491 if len(final_args) > rank:
492 raise IndexError("Too many indices.")
493
494 return final_args
495
496 def translate_slice(exp: slice, length: int) -> tuple[int, int, int]:
497 """Given a slice object, return a 3-tuple (start, count, step).
498
499 This is for use with the hyperslab selection routines.
500
501 """
502 start, stop, step = exp.start, exp.stop, exp.step
503 if start is None:
504 start = 0

Callers 2

__getitem__Method · 0.95
__setitem__Method · 0.95

Calls 2

whereMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected