Skip to content
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

DOC: Updating str_repeat docstring #22571

Merged
merged 9 commits into from
Sep 18, 2018
Merged
Changes from all 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
34 changes: 28 additions & 6 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,20 +675,42 @@ def str_replace(arr, pat, repl, n=-1, case=None, flags=0, regex=True):

def str_repeat(arr, repeats):
"""
Duplicate each string in the Series/Index by indicated number
of times.
Duplicate each string in the Series or Index.

Parameters
----------
repeats : int or array
Same value for all (int) or different value per (array)
repeats : int or sequence of int

Choose a reason for hiding this comment

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

sequence of int might be fine, and maybe 'sequence' is a term that has a clear definition in the pandas community, but I often see array_like used in the numpy documentation. Not really recommending anything, just curious is sequence is used similarly here, or you were just using to to indicate a list/array/tuple/etc of integers.

Same value for all (int) or different value per (sequence).

Returns
-------
repeated : Series/Index of objects
Series or Index of object
Series or Index of repeated string objects specified by
input parameter repeats.

Examples
--------
>>> s = pd.Series(['a', 'b', 'c'])
>>> s
0 a
1 b
2 c

Choose a reason for hiding this comment

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

I don't know that it is necessary, be I do see that elsewhere in our examples the dtype: object is included beneath the series printout.


Single int repeats string in Series

>>> s.str.repeat(repeats=2)
0 aa
1 bb
2 cc

Sequence of int repeats corresponding string in Series

>>> s.str.repeat(repeats=[1, 2, 3])
0 a
1 bb
2 ccc
"""
if is_scalar(repeats):

def rep(x):
try:
return compat.binary_type.__mul__(x, repeats)
Expand Down