Skip to content

DOC: Update Series.repeat docstring #20242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,12 +918,49 @@ def _set_values(self, key, value):
@deprecate_kwarg(old_arg_name='reps', new_arg_name='repeats')
def repeat(self, repeats, *args, **kwargs):
"""
Repeat elements of an Series. Refer to `numpy.ndarray.repeat`
for more information about the `repeats` argument.
Repeat elements of a Series.

Each element of the Series is repeated 'repeats' times.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single backtick for parameters like `repeats`


Parameters
----------
repeats : int
The number of repetitions for each element.
*args
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove args and kwargs. The validation function is an implementation detail that users shouldn't have to worry about. repeats is the only valid argument.

You could mention, perhaps in Notes that "unlike numpy.repeat, `axis` is not a valid argument".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Listen to @jorisvandenbossche about args and kwargs, not me :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussion, you can document them like

*args, **kwargs
    Additional keywords have no effect but might be accepted for
    compatibility with numpy.

These parameters will be passed to a validation function.
**kwargs
These parameters will be passed to a validation function.

See also
--------
numpy.ndarray.repeat
Series.append : Concatenate two or more Series.
pandas.concat : Concatenate two or more DataFrames.
numpy.repeat : Repeat elements of an array.

Returns
-------
Series
The repeated version of the Series.

Examples
--------
>>> df = pd.DataFrame({'col1' : ['A','B','C'],'col2' : [ 0 , 1 , 2 ]})
>>> df
col1 col2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing looks off. Should move it over a few spaces I think. Double check that this is right.

0 A 0
1 B 1
2 C 2
>>> df.col1.repeat(3)
0 A
0 A
0 A
1 B
1 B
1 B
2 C
2 C
2 C
Name: col1, dtype: object
"""
nv.validate_repeat(args, kwargs)
new_index = self.index.repeat(repeats)
Expand Down