Skip to content

Commit 747501a

Browse files
alysivjijorisvandenbossche
authored andcommitted
DOC: Improve docstring for pandas.Index.repeat (pandas-dev#19985)
1 parent 1d73cf3 commit 747501a

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

pandas/core/indexes/base.py

+30-4
Original file line numberDiff line numberDiff line change
@@ -696,12 +696,38 @@ def memory_usage(self, deep=False):
696696
@deprecate_kwarg(old_arg_name='n', new_arg_name='repeats')
697697
def repeat(self, repeats, *args, **kwargs):
698698
"""
699-
Repeat elements of an Index. Refer to `numpy.ndarray.repeat`
700-
for more information about the `repeats` argument.
699+
Repeat elements of an Index.
701700
702-
See also
701+
Returns a new index where each element of the current index
702+
is repeated consecutively a given number of times.
703+
704+
Parameters
705+
----------
706+
repeats : int
707+
The number of repetitions for each element.
708+
**kwargs
709+
Additional keywords have no effect but might be accepted for
710+
compatibility with numpy.
711+
712+
Returns
713+
-------
714+
pandas.Index
715+
Newly created Index with repeated elements.
716+
717+
See Also
718+
--------
719+
Series.repeat : Equivalent function for Series
720+
numpy.repeat : Underlying implementation
721+
722+
Examples
703723
--------
704-
numpy.ndarray.repeat
724+
>>> idx = pd.Index([1, 2, 3])
725+
>>> idx
726+
Int64Index([1, 2, 3], dtype='int64')
727+
>>> idx.repeat(2)
728+
Int64Index([1, 1, 2, 2, 3, 3], dtype='int64')
729+
>>> idx.repeat(3)
730+
Int64Index([1, 1, 1, 2, 2, 2, 3, 3, 3], dtype='int64')
705731
"""
706732
nv.validate_repeat(args, kwargs)
707733
return self._shallow_copy(self._values.repeat(repeats))

0 commit comments

Comments
 (0)