Skip to content

Commit 9e38e8c

Browse files
committed
DOC: Replace @appender decorator with inline docstrings for Index.take, Index.repeat, and Index.get_indexer_non_unique
1 parent 77efcd8 commit 9e38e8c

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

pandas/core/indexes/base.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,52 @@ def astype(self, dtype: Dtype, copy: bool = True):
11701170
result._references.add_index_reference(result)
11711171
return result
11721172

1173+
_index_shared_docs["take"] = """
1174+
Return a new %(klass)s of the values selected by the indices.
1175+
1176+
For internal compatibility with numpy arrays.
1177+
1178+
Parameters
1179+
----------
1180+
indices : array-like
1181+
Indices to be taken.
1182+
axis : int, optional
1183+
The axis over which to select values, always 0.
1184+
allow_fill : bool, default True
1185+
How to handle negative values in `indices`.
1186+
1187+
* False: negative values in `indices` indicate positional indices
1188+
from the right (the default). This is similar to
1189+
:func:`numpy.take`.
1190+
1191+
* True: negative values in `indices` indicate
1192+
missing values. These values are set to `fill_value`. Any other
1193+
other negative values raise a ``ValueError``.
1194+
1195+
fill_value : scalar, default None
1196+
If allow_fill=True and fill_value is not None, indices specified by
1197+
-1 are regarded as NA. If Index doesn't hold NA, raise ValueError.
1198+
**kwargs
1199+
Required for compatibility with numpy.
1200+
1201+
Returns
1202+
-------
1203+
Index
1204+
An index formed of elements at the given indices. Will be the same
1205+
type as self, except for RangeIndex.
1206+
1207+
See Also
1208+
--------
1209+
numpy.ndarray.take: Return an array formed from the
1210+
elements of a at the given indices.
1211+
1212+
Examples
1213+
--------
1214+
>>> idx = pd.Index(['a', 'b', 'c'])
1215+
>>> idx.take([2, 2, 1, 2])
1216+
Index(['c', 'c', 'b', 'c'], dtype='str')
1217+
"""
1218+
11731219
def take(
11741220
self,
11751221
indices,
@@ -5936,6 +5982,59 @@ def _should_fallback_to_positional(self) -> bool:
59365982
"complex",
59375983
}
59385984

5985+
_index_shared_docs["get_indexer_non_unique"] = """
5986+
Compute indexer and mask for new index given the current index.
5987+
5988+
The indexer should be then used as an input to ndarray.take to align the
5989+
current data to the new index.
5990+
5991+
Parameters
5992+
----------
5993+
target : %(target_klass)s
5994+
An iterable containing the values to be used for computing indexer.
5995+
5996+
Returns
5997+
-------
5998+
indexer : np.ndarray[np.intp]
5999+
Integers from 0 to n - 1 indicating that the index at these
6000+
positions matches the corresponding target values. Missing values
6001+
in the target are marked by -1.
6002+
missing : np.ndarray[np.intp]
6003+
An indexer into the target of the values not found.
6004+
These correspond to the -1 in the indexer array.
6005+
6006+
See Also
6007+
--------
6008+
Index.get_indexer : Computes indexer and mask for new index given
6009+
the current index.
6010+
Index.get_indexer_for : Returns an indexer even when non-unique.
6011+
6012+
Examples
6013+
--------
6014+
>>> index = pd.Index(['c', 'b', 'a', 'b', 'b'])
6015+
>>> index.get_indexer_non_unique(['b', 'b'])
6016+
(array([1, 3, 4, 1, 3, 4]), array([], dtype=int64))
6017+
6018+
In the example below there are no matched values.
6019+
6020+
>>> index = pd.Index(['c', 'b', 'a', 'b', 'b'])
6021+
>>> index.get_indexer_non_unique(['q', 'r', 't'])
6022+
(array([-1, -1, -1]), array([0, 1, 2]))
6023+
6024+
For this reason, the returned ``indexer`` contains only integers equal to -1.
6025+
It demonstrates that there's no match between the index and the ``target``
6026+
values at these positions. The mask [0, 1, 2] in the return value shows that
6027+
the first, second, and third elements are missing.
6028+
6029+
Notice that the return value is a tuple contains two items. In the example
6030+
below the first item is an array of locations in ``index``. The second
6031+
item is a mask shows that the first and third elements are missing.
6032+
6033+
>>> index = pd.Index(['c', 'b', 'a', 'b', 'b'])
6034+
>>> index.get_indexer_non_unique(['f', 'b', 's'])
6035+
(array([-1, 1, 3, 4, -1]), array([0, 2]))
6036+
"""
6037+
59396038
def get_indexer_non_unique(
59406039
self, target
59416040
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]:

0 commit comments

Comments
 (0)