Skip to content

Commit

Permalink
DOC: Improve docstring for pandas.Index.repeat (pandas-dev#19985)
Browse files Browse the repository at this point in the history
  • Loading branch information
alysivji authored and jorisvandenbossche committed Mar 9, 2018
1 parent 1d73cf3 commit 747501a
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,12 +696,38 @@ def memory_usage(self, deep=False):
@deprecate_kwarg(old_arg_name='n', new_arg_name='repeats')
def repeat(self, repeats, *args, **kwargs):
"""
Repeat elements of an Index. Refer to `numpy.ndarray.repeat`
for more information about the `repeats` argument.
Repeat elements of an Index.
See also
Returns a new index where each element of the current index
is repeated consecutively a given number of times.
Parameters
----------
repeats : int
The number of repetitions for each element.
**kwargs
Additional keywords have no effect but might be accepted for
compatibility with numpy.
Returns
-------
pandas.Index
Newly created Index with repeated elements.
See Also
--------
Series.repeat : Equivalent function for Series
numpy.repeat : Underlying implementation
Examples
--------
numpy.ndarray.repeat
>>> idx = pd.Index([1, 2, 3])
>>> idx
Int64Index([1, 2, 3], dtype='int64')
>>> idx.repeat(2)
Int64Index([1, 1, 2, 2, 3, 3], dtype='int64')
>>> idx.repeat(3)
Int64Index([1, 1, 1, 2, 2, 2, 3, 3, 3], dtype='int64')
"""
nv.validate_repeat(args, kwargs)
return self._shallow_copy(self._values.repeat(repeats))
Expand Down

0 comments on commit 747501a

Please sign in to comment.