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

Conversation

techedlaksh
Copy link
Contributor

@techedlaksh techedlaksh commented Mar 11, 2018

Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):

  • PR title is "DOC: update the docstring"
  • The validation script passes: scripts/validate_docstrings.py <your-function-or-method>
  • The PEP8 style check passes: git diff upstream/master -u -- "*.py" | flake8 --diff
  • The html version looks good: python doc/make.py --single <your-function-or-method>
  • It has been proofread on language by another sprint participant

Please include the output of the validation script below between the "```" ticks:

################################################################################
################# Docstring (pandas.Series.str.slice_replace)  #################
################################################################################

Replace a sliced string.

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

Parameters
----------
start : int or None
    Left edge index.
stop : int or None
    Right edge index.
repl : str or None
    String for replacement.

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

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')
>>> s
0    This is an Example 1
1    This is an Example 2
dtype: object

################################################################################
################################## Validation ##################################
################################################################################

Errors found:
	See Also section not found

Copy link
Contributor

@TomAugspurger TomAugspurger left a 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!

@@ -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"


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?

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a 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

@@ -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
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"


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

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?

@jreback jreback added the Strings String extension data type and string data label Mar 11, 2018
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

@TomAugspurger
Copy link
Contributor

Updated if you want to take a look.

I'm not sure how, but apparently changing the default repl to '' broke tests. 7a0cf0c reverted that to be how it was before. Will let the tests run on this before merging.

repl : str or None
String for replacement.
start : int, optional
Left index position to use for the slice. The default of None
Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Contributor

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)

Copy link
Member

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

@codecov
Copy link

codecov bot commented Mar 16, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@ea8ac51). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #20273   +/-   ##
=========================================
  Coverage          ?   91.77%           
=========================================
  Files             ?      152           
  Lines             ?    49178           
  Branches          ?        0           
=========================================
  Hits              ?    45133           
  Misses            ?     4045           
  Partials          ?        0
Flag Coverage Δ
#multiple 90.16% <ø> (?)
#single 41.84% <ø> (?)
Impacted Files Coverage Δ
pandas/core/strings.py 98.32% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ea8ac51...5263522. Read the comment docs.

@TomAugspurger TomAugspurger added this to the 0.23.0 milestone Mar 16, 2018
@TomAugspurger TomAugspurger merged commit 03879ba into pandas-dev:master Mar 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Strings String extension data type and string data
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants