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: Improve replace docstring #18100

Merged
merged 5 commits into from
Feb 4, 2018
Merged

Conversation

reidy-p
Copy link
Contributor

@reidy-p reidy-p commented Nov 4, 2017

xref #17673
closes #13852

  • passes git diff upstream/master -u -- "*.py" | flake8 --diff

I have tried to separate the docstrings for series and dataframe as suggested in the original issue but can try to combine them if that works better.

As noted in the original issue, replace can do a lot things and I've tried to cover most of them with the examples but would welcome other suggestions.

@reidy-p reidy-p changed the title DOC: Improve reduce docstring DOC: Improve replace docstring Nov 4, 2017
@codecov
Copy link

codecov bot commented Nov 4, 2017

Codecov Report

Merging #18100 into master will decrease coverage by 0.1%.
The diff coverage is 67.79%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18100      +/-   ##
==========================================
- Coverage   91.25%   91.14%   -0.11%     
==========================================
  Files         163      163              
  Lines       50120    50225     +105     
==========================================
+ Hits        45737    45780      +43     
- Misses       4383     4445      +62
Flag Coverage Δ
#multiple 88.96% <67.79%> (-0.09%) ⬇️
#single 40.24% <12.99%> (-0.14%) ⬇️
Impacted Files Coverage Δ
pandas/core/generic.py 91.7% <ø> (-0.73%) ⬇️
pandas/core/series.py 91.92% <55.05%> (-3.09%) ⬇️
pandas/core/frame.py 97.05% <80.68%> (-0.81%) ⬇️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/plotting/_converter.py 65.2% <0%> (+1.81%) ⬆️

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 86e9dcc...e67276e. Read the comment docs.

@codecov
Copy link

codecov bot commented Nov 4, 2017

Codecov Report

Merging #18100 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18100      +/-   ##
==========================================
+ Coverage   91.62%   91.62%   +<.01%     
==========================================
  Files         150      150              
  Lines       48681    48689       +8     
==========================================
+ Hits        44604    44612       +8     
  Misses       4077     4077
Flag Coverage Δ
#multiple 89.99% <100%> (ø) ⬆️
#single 41.74% <88.88%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/generic.py 95.91% <100%> (ø) ⬆️
pandas/core/frame.py 97.42% <100%> (ø) ⬆️
pandas/core/series.py 94.61% <100%> (+0.01%) ⬆️

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 3f3b4e0...008588c. Read the comment docs.

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.

Haven't gone through this in detail yet, but I think it'd be cleaner to leave the implementation in pandas/core/generic.py, and to only overwrite the docstring in series.py and frame.py.

So in, e.g. series.py it'd look like

    def replace(self, to_replace=None, value=None, inplace=False, limit=None,
                regex=False, method='pad', axis=None):
   """add your docstring"""
    super().replace(to_replace= to_replace, value=value...)

Then you don't have all the duplicated code.

@@ -227,6 +232,30 @@

"""

def _single_replace(self, to_replace, method, inplace, limit):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could define this in one place and then import it in frame.py and series.py.

Also a short docstring would still be nice, even though it's internal.


See Also
--------
:func:`DataFrame.fillna` : Fill NA/NaN values
Copy link
Contributor

Choose a reason for hiding this comment

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

You do't need the

:func:`

. Just DataFrame.fillna should be enough for numpydoc.

@reidy-p
Copy link
Contributor Author

reidy-p commented Nov 4, 2017

@TomAugspurger thanks for the review, made some updates.

I wasn't sure what to do with the docstring for replace in pandas/core/generic.py since it's being overwritten in series.py and frame.py.

@gfyoung gfyoung added the Docs label Nov 5, 2017
@reidy-p reidy-p force-pushed the replace_docstring branch 2 times, most recently from 9254f5c to 2b4cefc Compare November 22, 2017 21:54
@jreback
Copy link
Contributor

jreback commented Jan 21, 2018

can you rebase

@@ -2658,6 +2661,193 @@ def fillna(self, value=None, method=None, axis=None, inplace=False,
limit=limit, downcast=downcast,
**kwargs)

def replace(self, to_replace=None, value=None, inplace=False, limit=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

can we share most / all of this via _shared_docs? otherwise end up with lots of duplication here

@reidy-p
Copy link
Contributor Author

reidy-p commented Jan 29, 2018

I removed the duplication by using _shared_docs but as a result most of the examples for both the Series.replace and DataFrame.replace docstrings now use DataFrame.

@jreback jreback added this to the 0.23.0 milestone Jan 30, 2018
@jreback
Copy link
Contributor

jreback commented Jan 30, 2018

@jorisvandenbossche if you'd have a look. I only glanced briefly :>

**must** be the same length.
- Second, if ``regex=True`` then all of the strings in **both**
lists will be interpreted as regexs otherwise they will match
directly. This doesn't matter much for `value` since there
directly. This doesn't matter much for ``value`` since there
are only a few possible substitution regexes you can use.
- str and regex rules apply as above.
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose this is "str, regex, and numeric rules apply as above." now?

@jreback jreback merged commit bc1d027 into pandas-dev:master Feb 4, 2018
@jreback
Copy link
Contributor

jreback commented Feb 4, 2018

thanks!

@reidy-p reidy-p deleted the replace_docstring branch February 8, 2018 22:01
harisbal pushed a commit to harisbal/pandas that referenced this pull request Feb 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Series.replace and DataFrame.replace have same docstring?
4 participants