Skip to content

Commit 01bb8ca

Browse files
DOC: Replace @appender decorator with inline docstrings for MultiIndex.take and MultiIndex.repeat
1 parent 9234ed5 commit 01bb8ca

File tree

1 file changed

+81
-2
lines changed

1 file changed

+81
-2
lines changed

pandas/core/indexes/multi.py

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,7 +2290,6 @@ def _getitem_slice(self: MultiIndex, slobj: slice) -> MultiIndex:
22902290
verify_integrity=False,
22912291
)
22922292

2293-
@Appender(_index_shared_docs["take"] % _index_doc_kwargs)
22942293
def take(
22952294
self: MultiIndex,
22962295
indices,
@@ -2299,6 +2298,51 @@ def take(
22992298
fill_value=None,
23002299
**kwargs,
23012300
) -> MultiIndex:
2301+
"""
2302+
Return a new MultiIndex of the values selected by the indices.
2303+
2304+
For internal compatibility with numpy arrays.
2305+
2306+
Parameters
2307+
----------
2308+
indices : array-like
2309+
Indices to be taken.
2310+
axis : int, optional
2311+
The axis over which to select values, always 0.
2312+
allow_fill : bool, default True
2313+
How to handle negative values in `indices`.
2314+
2315+
* False: negative values in `indices` indicate positional indices
2316+
from the right (the default). This is similar to
2317+
:func:`numpy.take`.
2318+
2319+
* True: negative values in `indices` indicate
2320+
missing values. These values are set to `fill_value`. Any other
2321+
other negative values raise a ``ValueError``.
2322+
2323+
fill_value : scalar, default None
2324+
If allow_fill=True and fill_value is not None, indices specified by
2325+
-1 are regarded as NA. If Index doesn't hold NA, raise ValueError.
2326+
**kwargs
2327+
Required for compatibility with numpy.
2328+
2329+
Returns
2330+
-------
2331+
Index
2332+
An index formed of elements at the given indices. Will be the same
2333+
type as self, except for RangeIndex.
2334+
2335+
See Also
2336+
--------
2337+
numpy.ndarray.take: Return an array formed from the
2338+
elements of a at the given indices.
2339+
2340+
Examples
2341+
--------
2342+
>>> idx = pd.Index(['a', 'b', 'c'])
2343+
>>> idx.take([2, 2, 1, 2])
2344+
Index(['c', 'c', 'b', 'c'], dtype='str')
2345+
"""
23022346
nv.validate_take((), kwargs)
23032347
indices = ensure_platform_int(indices)
23042348

@@ -2454,8 +2498,43 @@ def argsort(
24542498
keys = [lev.codes for lev in target._get_codes_for_sorting()]
24552499
return lexsort_indexer(keys, na_position=na_position, codes_given=True)
24562500

2457-
@Appender(_index_shared_docs["repeat"] % _index_doc_kwargs)
24582501
def repeat(self, repeats: int, axis=None) -> MultiIndex:
2502+
"""
2503+
Repeat elements of a MultiIndex.
2504+
2505+
Returns a new MultiIndex where each element of the current MultiIndex
2506+
is repeated consecutively a given number of times.
2507+
2508+
Parameters
2509+
----------
2510+
repeats : int or array of ints
2511+
The number of repetitions for each element. This should be a
2512+
non-negative integer. Repeating 0 times will return an empty
2513+
MultiIndex.
2514+
axis : None
2515+
Must be ``None``. Has no effect but is accepted for compatibility
2516+
with numpy.
2517+
2518+
Returns
2519+
-------
2520+
MultiIndex
2521+
Newly created MultiIndex with repeated elements.
2522+
2523+
See Also
2524+
--------
2525+
Series.repeat : Equivalent function for Series.
2526+
numpy.repeat : Similar method for :class:`numpy.ndarray`.
2527+
2528+
Examples
2529+
--------
2530+
>>> idx = pd.Index(['a', 'b', 'c'])
2531+
>>> idx
2532+
Index(['a', 'b', 'c'], dtype='object')
2533+
>>> idx.repeat(2)
2534+
Index(['a', 'a', 'b', 'b', 'c', 'c'], dtype='object')
2535+
>>> idx.repeat([1, 2, 3])
2536+
Index(['a', 'b', 'b', 'c', 'c', 'c'], dtype='object')
2537+
"""
24592538
nv.validate_repeat((), {"axis": axis})
24602539
# error: Incompatible types in assignment (expression has type "ndarray",
24612540
# variable has type "int")

0 commit comments

Comments
 (0)