MCPcopy
hub / github.com/pandas-dev/pandas / get_loc

Method get_loc

pandas/core/indexes/interval.py:743–822  ·  view source on GitHub ↗

Get integer location, slice or boolean mask for requested label. The `get_loc` method is used to retrieve the integer index, a slice for slicing objects, or a boolean mask indicating the presence of the label in the `IntervalIndex`. Parameters -----

(self, key)

Source from the content-addressed store, hash-verified

741 # Indexing Methods
742
743 def get_loc(self, key) -> int | slice | np.ndarray:
744 """
745 Get integer location, slice or boolean mask for requested label.
746
747 The `get_loc` method is used to retrieve the integer index, a slice for
748 slicing objects, or a boolean mask indicating the presence of the label
749 in the `IntervalIndex`.
750
751 Parameters
752 ----------
753 key : label
754 The value or range to find in the IntervalIndex.
755
756 Returns
757 -------
758 int if unique index, slice if monotonic index, else mask
759 The position or positions found. This could be a single
760 number, a range, or an array of true/false values
761 indicating the position(s) of the label.
762
763 See Also
764 --------
765 IntervalIndex.get_indexer_non_unique : Compute indexer and
766 mask for new index given the current index.
767 Index.get_loc : Similar method in the base Index class.
768
769 Examples
770 --------
771 >>> i1, i2 = pd.Interval(0, 1), pd.Interval(1, 2)
772 >>> index = pd.IntervalIndex([i1, i2])
773 >>> index.get_loc(1)
774 0
775
776 You can also supply a point inside an interval.
777
778 >>> index.get_loc(1.5)
779 1
780
781 If a label is in several intervals, you get the locations of all the
782 relevant intervals.
783
784 >>> i3 = pd.Interval(0, 2)
785 >>> overlapping_index = pd.IntervalIndex([i1, i2, i3])
786 >>> overlapping_index.get_loc(0.5)
787 array([ True, False, True])
788
789 Only exact matches will be returned if an interval is provided.
790
791 >>> index.get_loc(pd.Interval(0, 1))
792 0
793 """
794 self._check_indexing_error(key)
795
796 if isinstance(key, Interval):
797 if self.closed != key.closed:
798 raise KeyError(key)
799 mask = (self.left == key.left) & (self.right == key.right)
800 elif is_valid_na_for_dtype(key, self.dtype):

Callers 3

__contains__Method · 0.95

Calls 7

is_valid_na_for_dtypeFunction · 0.90
maybe_unbox_numpy_scalarFunction · 0.90
_check_indexing_errorMethod · 0.45
isnaMethod · 0.45
sumMethod · 0.45
argmaxMethod · 0.45
viewMethod · 0.45

Tested by 1