Skip to content

Commit 11c5449

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

File tree

1 file changed

+84
-2
lines changed

1 file changed

+84
-2
lines changed

pandas/core/indexes/multi.py

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

@@ -2454,8 +2500,44 @@ def argsort(
24542500
keys = [lev.codes for lev in target._get_codes_for_sorting()]
24552501
return lexsort_indexer(keys, na_position=na_position, codes_given=True)
24562502

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

0 commit comments

Comments
 (0)