Skip to content

DOC: update the pandas.Series.str.slice_replace docstring #20273

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

Merged
merged 5 commits into from
Mar 16, 2018
Merged
Changes from 1 commit
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
19 changes: 18 additions & 1 deletion pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,19 +1180,36 @@ def str_slice(arr, start=None, stop=None, step=None):

def str_slice_replace(arr, start=None, stop=None, repl=None):
"""
Replace a sliced string.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's implied, but I'd like to see this say what the sliced bit is replaced with

Replace a sliced string with another value.

Like all of pandas string methods, this operates elementwise on each string
in the Series or Index.

and then the rest of the docstring.

Copy link
Member

Choose a reason for hiding this comment

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

I think "a slice of a string" is easier to understand than "sliced string"


Replace a slice of each string in the Series/Index with another
string.

Parameters
----------
start : int or None
Left edge index.
Copy link
Member

Choose a reason for hiding this comment

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

Can you indicate what None means? (I suppose this is the from the start of the string)

Can you also change "int or None" into "int, optional"? And then maybe you can say for the above "If not specified, slice from the start of each string"

(and same for end, but then "slice until the end of each string"

stop : int or None
Right edge index.
repl : str or None
String for replacement
String for replacement.

Returns
-------
replaced : Series/Index of objects

Copy link
Contributor

Choose a reason for hiding this comment

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

For a See Also, str.replace to link to https://docs.python.org/3/library/stdtypes.html#str.replace would be good.

Copy link
Member

Choose a reason for hiding this comment

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

And we also have replace as a string method in Series.str, so I would rather add a link to that?

Examples
--------
>>> s = pd.Series(['This is a Test 1', 'This is a Test 2'])
>>> s
0 This is a Test 1
1 This is a Test 2
dtype: object
>>> s = s.str.slice_replace(8, 14, 'an Example')
Copy link
Contributor

Choose a reason for hiding this comment

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

blank line between cases

>>> s
0 This is an Example 1
1 This is an Example 2
dtype: object
"""
if repl is None:
repl = ''
Expand Down