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

Method __getitem__

tables/vlarray.py:649–699  ·  view source on GitHub ↗

Get a row or a range of rows from the array. If key argument is an integer, the corresponding array row is returned as an object of the current flavor. If key is a slice, the range of rows determined by it is returned as a list of objects of the current flavor.

(
        self, key: int | slice | Sequence[int] | np.ndarray
    )

Source from the content-addressed store, hash-verified

647 return self.listarr[self._row]
648
649 def __getitem__(
650 self, key: int | slice | Sequence[int] | np.ndarray
651 ) -> list:
652 """Get a row or a range of rows from the array.
653
654 If key argument is an integer, the corresponding array row is returned
655 as an object of the current flavor. If key is a slice, the range of
656 rows determined by it is returned as a list of objects of the current
657 flavor.
658
659 In addition, NumPy-style point selections are supported. In
660 particular, if key is a list of row coordinates, the set of rows
661 determined by it is returned. Furthermore, if key is an array of
662 boolean values, only the coordinates where key is True are returned.
663 Note that for the latter to work it is necessary that key list would
664 contain exactly as many rows as the array has.
665
666 Examples
667 --------
668 ::
669
670 a_row = vlarray[4]
671 a_list = vlarray[4:1000:2]
672 a_list2 = vlarray[[0,2]] # get list of coords
673 a_list3 = vlarray[[0,-2]] # negative values accepted
674 a_list4 = vlarray[np.array([True,...,False])] # array of bools
675
676 """
677 self._g_check_open()
678 if is_idx(key):
679 key = operator.index(key)
680
681 # Index out of range protection
682 if key >= self.nrows:
683 raise IndexError("Index out of range")
684 if key < 0:
685 # To support negative values
686 key += self.nrows
687 start, stop, step = self._process_range(key, key + 1, 1)
688 return self.read(start, stop, step)[0]
689 elif isinstance(key, slice):
690 start, stop, step = self._process_range(
691 key.start, key.stop, key.step
692 )
693 return self.read(start, stop, step)
694 # Try with a boolean or point selection
695 elif type(key) in (list, tuple) or isinstance(key, np.ndarray):
696 coords = self._point_selection(key)
697 return self._read_coordinates(coords)
698 else:
699 raise IndexError(f"Invalid index or slice: {key!r}")
700
701 def _assign_values(self, coords: Sequence[int], values: Sequence) -> None:
702 """Assign the `values` to the positions stated in `coords`."""

Callers

nothing calls this directly

Calls 7

readMethod · 0.95
_read_coordinatesMethod · 0.95
is_idxFunction · 0.85
_g_check_openMethod · 0.80
indexMethod · 0.80
_point_selectionMethod · 0.80
_process_rangeMethod · 0.45

Tested by

no test coverage detected