-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
Conversation
2e64b2a
to
e67276e
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #18100 +/- ##
==========================================
+ Coverage 91.62% 91.62% +<.01%
==========================================
Files 150 150
Lines 48681 48689 +8
==========================================
+ Hits 44604 44612 +8
Misses 4077 4077
Continue to review full report at Codecov.
|
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.
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.
pandas/core/frame.py
Outdated
@@ -227,6 +232,30 @@ | |||
|
|||
""" | |||
|
|||
def _single_replace(self, to_replace, method, inplace, limit): |
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.
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.
pandas/core/frame.py
Outdated
|
||
See Also | ||
-------- | ||
:func:`DataFrame.fillna` : Fill NA/NaN values |
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.
You do't need the
:func:`
. Just DataFrame.fillna should be enough for numpydoc.
@TomAugspurger thanks for the review, made some updates. I wasn't sure what to do with the docstring for |
9254f5c
to
2b4cefc
Compare
can you rebase |
2b4cefc
to
8ab24cd
Compare
pandas/core/series.py
Outdated
@@ -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, |
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 we share most / all of this via _shared_docs
? otherwise end up with lots of duplication here
e05597f
to
420db01
Compare
I removed the duplication by using |
@jorisvandenbossche if you'd have a look. I only glanced briefly :> |
pandas/core/generic.py
Outdated
**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. |
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 suppose this is "str, regex, and numeric rules apply as above." now?
0772078
to
008588c
Compare
thanks! |
xref #17673
closes #13852
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.