Skip to content

Commit a548b84

Browse files
committed
Replace @doc decorator with inlined docstrings
1 parent ea75dd7 commit a548b84

File tree

1 file changed

+109
-5
lines changed

1 file changed

+109
-5
lines changed

pandas/core/indexes/range.py

Lines changed: 109 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from pandas.compat.numpy import function as nv
2828
from pandas.util._decorators import (
2929
cache_readonly,
30-
doc,
3130
set_module,
3231
)
3332

@@ -473,8 +472,44 @@ def inferred_type(self) -> str:
473472
# --------------------------------------------------------------------
474473
# Indexing Methods
475474

476-
@doc(Index.get_loc)
477475
def get_loc(self, key) -> int:
476+
"""
477+
Get integer location, slice or boolean mask for requested label.
478+
479+
Parameters
480+
----------
481+
key : label
482+
The key to check its location if it is present in the index.
483+
484+
Returns
485+
-------
486+
int if unique index, slice if monotonic index, else mask
487+
Integer location, slice or boolean mask.
488+
489+
See Also
490+
--------
491+
Index.get_slice_bound : Calculate slice bound that corresponds to
492+
given label.
493+
Index.get_indexer : Computes indexer and mask for new index given
494+
the current index.
495+
Index.get_non_unique : Returns indexer and masks for new index given
496+
the current index.
497+
Index.get_indexer_for : Returns an indexer even when non-unique.
498+
499+
Examples
500+
--------
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)
508+
509+
>>> non_monotonic_index = pd.Index(list("abcb"))
510+
>>> non_monotonic_index.get_loc("b")
511+
array([False, True, False, True])
512+
"""
478513
if is_integer(key) or (is_float(key) and key.is_integer()):
479514
new_key = int(key)
480515
try:
@@ -528,12 +563,47 @@ def _should_fallback_to_positional(self) -> bool:
528563
def tolist(self) -> list[int]:
529564
return list(self._range)
530565

531-
@doc(Index.__iter__)
532566
def __iter__(self) -> Iterator[int]:
567+
"""
568+
Return an iterator of the values.
569+
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+
574+
Returns
575+
-------
576+
iterator
577+
An iterator yielding scalar values from the Series.
578+
579+
See Also
580+
--------
581+
Series.items : Lazily iterate over (index, value) tuples.
582+
583+
Examples
584+
--------
585+
>>> s = pd.Series([1, 2, 3])
586+
>>> for x in s:
587+
... print(x)
588+
1
589+
2
590+
3
591+
"""
533592
yield from self._range
534593

535-
@doc(Index._shallow_copy)
536594
def _shallow_copy(self, values, name: Hashable = no_default):
595+
"""
596+
Create a new Index with the same class as the caller, don't copy the
597+
data, use the same object attributes with passed in attributes taking
598+
precedence.
599+
600+
*this is an internal non-public method*
601+
602+
Parameters
603+
----------
604+
values : the values to create the new Index, optional
605+
name : Label, defaults to self.name
606+
"""
537607
name = self._name if name is no_default else name
538608

539609
if values.dtype.kind == "f":
@@ -560,8 +630,42 @@ def _wrap_reindex_result(self, target, indexer, preserve_names: bool):
560630
target = self._shallow_copy(target._values, name=target.name)
561631
return super()._wrap_reindex_result(target, indexer, preserve_names)
562632

563-
@doc(Index.copy)
564633
def copy(self, name: Hashable | None = None, deep: bool = False) -> Self:
634+
"""
635+
Make a copy of this object.
636+
637+
Name is set on the new object.
638+
639+
Parameters
640+
----------
641+
name : Label, optional
642+
Set name for new object.
643+
deep : bool, default False
644+
If True attempts to make a deep copy of the Index.
645+
Else makes a shallow copy.
646+
647+
Returns
648+
-------
649+
Index
650+
Index refer to new object which is a copy of this object.
651+
652+
See Also
653+
--------
654+
Index.delete: Make new Index with passed location(-s) deleted.
655+
Index.drop: Make new Index with passed list of labels deleted.
656+
657+
Notes
658+
-----
659+
In most cases, there should be no functional difference from using
660+
``deep``, but if ``deep`` is passed it will attempt to deepcopy.
661+
662+
Examples
663+
--------
664+
>>> idx = pd.Index(["a", "b", "c"])
665+
>>> new_idx = idx.copy()
666+
>>> idx is new_idx
667+
False
668+
"""
565669
name = self._validate_names(name=name, deep=deep)[0]
566670
new_index = self._rename(name=name)
567671
return new_index

0 commit comments

Comments
 (0)