-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
DOC: update the pandas.Series.str.slice_replace docstring #20273
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor suggestions, if you have a chance to update it'd be great. Looks good though!
pandas/core/strings.py
Outdated
@@ -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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"
pandas/core/strings.py
Outdated
|
||
Returns | ||
------- | ||
replaced : Series/Index of objects | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Added some additional comments
pandas/core/strings.py
Outdated
@@ -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. |
There was a problem hiding this comment.
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"
pandas/core/strings.py
Outdated
Replace a slice of each string in the Series/Index with another | ||
string. | ||
|
||
Parameters | ||
---------- | ||
start : int or None | ||
Left edge index. |
There was a problem hiding this comment.
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"
pandas/core/strings.py
Outdated
|
||
Returns | ||
------- | ||
replaced : Series/Index of objects | ||
|
There was a problem hiding this comment.
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?
pandas/core/strings.py
Outdated
0 This is a Test 1 | ||
1 This is a Test 2 | ||
dtype: object | ||
>>> s = s.str.slice_replace(8, 14, 'an Example') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line between cases
Updated if you want to take a look. I'm not sure how, but apparently changing the default |
pandas/core/strings.py
Outdated
repl : str or None | ||
String for replacement. | ||
start : int, optional | ||
Left index position to use for the slice. The default of None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General question: do we more want to use the phrase of "If not specified" instead of "The default of None" if we say something is optional?
On the one hand I think this can be clearer as that is what you do in practice, you don't specify it. But on the other hand of course the signature shows None.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, if not specified is probably best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went with if not specified (None)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, If not specified (None)
, is a good combination of both, we should use that pattern more
[ci skip]
…ring_slice_replace [ci skip] [ci skip]
Codecov Report
@@ Coverage Diff @@
## master #20273 +/- ##
=========================================
Coverage ? 91.77%
=========================================
Files ? 152
Lines ? 49178
Branches ? 0
=========================================
Hits ? 45133
Misses ? 4045
Partials ? 0
Continue to review full report at Codecov.
|
Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):
scripts/validate_docstrings.py <your-function-or-method>
git diff upstream/master -u -- "*.py" | flake8 --diff
python doc/make.py --single <your-function-or-method>
Please include the output of the validation script below between the "```" ticks: