Skip to content

Commit dd53f5d

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

File tree

1 file changed

+81
-4
lines changed

1 file changed

+81
-4
lines changed

pandas/core/indexes/multi.py

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
UnsortedIndexError,
5353
)
5454
from pandas.util._decorators import (
55-
Appender,
5655
cache_readonly,
5756
doc,
5857
set_module,
@@ -101,7 +100,6 @@
101100
import pandas.core.indexes.base as ibase
102101
from pandas.core.indexes.base import (
103102
Index,
104-
_index_shared_docs,
105103
ensure_index,
106104
get_unanimous_names,
107105
)
@@ -2290,7 +2288,6 @@ def _getitem_slice(self: MultiIndex, slobj: slice) -> MultiIndex:
22902288
verify_integrity=False,
22912289
)
22922290

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

@@ -2454,8 +2496,43 @@ def argsort(
24542496
keys = [lev.codes for lev in target._get_codes_for_sorting()]
24552497
return lexsort_indexer(keys, na_position=na_position, codes_given=True)
24562498

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

0 commit comments

Comments
 (0)