@@ -474,41 +474,48 @@ def inferred_type(self) -> str:
474474
475475 def get_loc (self , key ) -> int :
476476 """
477- Get integer location, slice or boolean mask for requested label.
477+ Get integer location for requested label.
478478
479479 Parameters
480480 ----------
481- key : label
482- The key to check its location if it is present in the index.
481+ key : int or float
482+ Label to locate. Integer-like floats (e.g. 3.0) are accepted and
483+ treated as the corresponding integer. Non-integer floats and other
484+ non-integer labels are not valid and will raise KeyError or
485+ InvalidIndexError.
483486
484487 Returns
485488 -------
486- int if unique index, slice if monotonic index, else mask
487- Integer location, slice or boolean mask.
489+ int
490+ Integer location of the label within the RangeIndex.
491+
492+ Raises
493+ ------
494+ KeyError
495+ If the label is not present in the RangeIndex or the label is a
496+ non-integer value.
497+ InvalidIndexError
498+ If the label is of an invalid type for the RangeIndex.
488499
489500 See Also
490501 --------
491- Index .get_slice_bound : Calculate slice bound that corresponds to
502+ RangeIndex .get_slice_bound : Calculate slice bound that corresponds to
492503 given label.
493- Index .get_indexer : Computes indexer and mask for new index given
504+ RangeIndex .get_indexer : Computes indexer and mask for new index given
494505 the current index.
495- Index .get_non_unique : Returns indexer and masks for new index given
506+ RangeIndex .get_non_unique : Returns indexer and masks for new index given
496507 the current index.
497- Index .get_indexer_for : Returns an indexer even when non-unique.
508+ RangeIndex .get_indexer_for : Returns an indexer even when non-unique.
498509
499510 Examples
500511 --------
501- >>> unique_index = pd.Index(list("abc"))
502- >>> unique_index.get_loc("b")
503- 1
504-
505- >>> monotonic_index = pd.Index(list("abbc"))
506- >>> monotonic_index.get_loc("b")
507- slice(1, 3, None)
512+ >>> idx = pd.RangeIndex(5)
513+ >>> idx.get_loc(3)
514+ 3
508515
509- >>> non_monotonic_index = pd.Index(list("abcb"))
510- >>> non_monotonic_index .get_loc("b" )
511- array([False, True, False, True])
516+ >>> idx = pd.RangeIndex(2, 10, 2) # values [2, 4, 6, 8]
517+ >>> idx .get_loc(6 )
518+ 2
512519 """
513520 if is_integer (key ) or (is_float (key ) and key .is_integer ()):
514521 new_key = int (key )
@@ -567,41 +574,33 @@ def __iter__(self) -> Iterator[int]:
567574 """
568575 Return an iterator of the values.
569576
570- These are each a scalar type, which is a Python scalar
571- (for str, int, float) or a pandas scalar
572- (for Timestamp/Timedelta/Interval/Period)
573-
574577 Returns
575578 -------
576579 iterator
577- An iterator yielding scalar values from the Series.
578-
579- See Also
580- --------
581- Series.items : Lazily iterate over (index, value) tuples.
580+ An iterator yielding ints from the RangeIndex.
582581
583582 Examples
584583 --------
585- >>> s = pd.Series([1, 2, 3] )
586- >>> for x in s :
584+ >>> idx = pd.RangeIndex(3 )
585+ >>> for x in idx :
587586 ... print(x)
587+ 0
588588 1
589589 2
590- 3
591590 """
592591 yield from self ._range
593592
594593 def _shallow_copy (self , values , name : Hashable = no_default ):
595594 """
596- Create a new Index with the same class as the caller, don't copy the
595+ Create a new RangeIndex with the same class as the caller, don't copy the
597596 data, use the same object attributes with passed in attributes taking
598597 precedence.
599598
600599 *this is an internal non-public method*
601600
602601 Parameters
603602 ----------
604- values : the values to create the new Index , optional
603+ values : the values to create the new RangeIndex , optional
605604 name : Label, defaults to self.name
606605 """
607606 name = self ._name if name is no_default else name
@@ -641,18 +640,18 @@ def copy(self, name: Hashable | None = None, deep: bool = False) -> Self:
641640 name : Label, optional
642641 Set name for new object.
643642 deep : bool, default False
644- If True attempts to make a deep copy of the Index .
643+ If True attempts to make a deep copy of the RangeIndex .
645644 Else makes a shallow copy.
646645
647646 Returns
648647 -------
649- Index
650- Index refer to new object which is a copy of this object.
648+ RangeIndex
649+ RangeIndex refer to new object which is a copy of this object.
651650
652651 See Also
653652 --------
654- Index .delete: Make new Index with passed location(-s) deleted.
655- Index .drop: Make new Index with passed list of labels deleted.
653+ RangeIndex .delete: Make new RangeIndex with passed location(-s) deleted.
654+ RangeIndex .drop: Make new RangeIndex with passed list of labels deleted.
656655
657656 Notes
658657 -----
@@ -661,7 +660,7 @@ def copy(self, name: Hashable | None = None, deep: bool = False) -> Self:
661660
662661 Examples
663662 --------
664- >>> idx = pd.Index(["a", "b", "c"] )
663+ >>> idx = pd.RangeIndex(3 )
665664 >>> new_idx = idx.copy()
666665 >>> idx is new_idx
667666 False
0 commit comments