-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: update the DataFrame.update() docstring #20201
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 DataFrame.update() docstring #20201
Conversation
DOC: Improved the docstring of DataFrame.update()
pandas/core/frame.py
Outdated
@@ -4207,17 +4207,23 @@ def update(self, other, join='left', overwrite=True, filter_func=None, | |||
raise_conflict=False): | |||
""" | |||
Modify DataFrame in place using non-NA values from passed |
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.
May have to reword this so the first line isn't too long? Does the validation script complain about this?
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.
The validation script actually did not complain, but I'll try to adjust it.
pandas/core/frame.py
Outdated
join : {'left'}, default 'left' | ||
Indicates which column values overwrite. |
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.
Is join='right'
valid? Can you do some exploration on what happens?
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.
It's actually not valid. I tried it.
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 you can say "Only left join is implemented, keeping the index and columns of the original object"
pandas/core/frame.py
Outdated
@@ -4276,6 +4282,14 @@ def update(self, other, join='left', overwrite=True, filter_func=None, | |||
0 1 4.0 | |||
1 2 500.0 | |||
2 3 6.0 | |||
|
|||
See also |
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.
See Also (note capitalization)
should go before the examples.
pandas/core/frame.py
Outdated
|
||
Returns | ||
------- | ||
updated : DataFrame |
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.
Rerturns goes right after the Parameters section.
DOC: Improved the docstring of DataFrame.update()
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 add some more explanation between the different examples ?
pandas/core/frame.py
Outdated
raise_conflict : boolean | ||
If True, will raise an error if the DataFrame and other both | ||
contain data in the same place. | ||
|
||
Returns | ||
------- | ||
updated : DataFrame |
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.
It actually does not return a DataFrame, as the update is in place.
pandas/core/frame.py
Outdated
join : {'left'}, default 'left' | ||
Indicates which column values overwrite. |
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 you can say "Only left join is implemented, keeping the index and columns of the original object"
pandas/core/frame.py
Outdated
overwrite : boolean, default True | ||
If True then overwrite values for common keys in the calling frame | ||
If True then overwrite values for common keys in the calling frame. |
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 what if False?
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 it that case only NA values in the calling object are updated
DOC: Improved the docstring of DataFrame.join()
Added Raises Reformatted join. Added dict.update to see also
Codecov Report
@@ Coverage Diff @@
## master #20201 +/- ##
==========================================
+ Coverage 91.73% 91.76% +0.02%
==========================================
Files 150 150
Lines 49144 49144
==========================================
+ Hits 45083 45095 +12
+ Misses 4061 4049 -12
Continue to review full report at Codecov.
|
Made a couple updates. Mind taking a look @kantologist? |
DOC: Improved the docstring of DataFrame.update()
DOC: Improved the docstring of DataFrame.update()
So the only issue is the doc validation script complaining about the absent of a return section. by the way I observed the same pattern of return section for other inplace functions too. |
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.
So the only issue is the doc validation script complaining about the absent of a return section. by the way I observed the same pattern of return section for other inplace functions too.
It's fine to ignore those errors in this case (the methods that don't return something are a minority)
pandas/core/frame.py
Outdated
|
||
Parameters | ||
---------- | ||
other : DataFrame, or object coercible into a DataFrame | ||
Index should be similar to one of the columns in this one. If a |
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 don't really understand "Index should be similar to one of the columns in this one". What do you want to say here?
pandas/core/frame.py
Outdated
If True then overwrite values for common keys in the calling frame | ||
How to handle non-NA values for overlapping keys. | ||
|
||
* True : overwrite values in `self` with values from `other`. |
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 we should try to avoid using 'self', as not necessarily every pandas user knows how classes are written.
There is not always an ideal alternative, but I would use "original object" or "calling object" (or use DataFrame instead of object)
pandas/core/frame.py
Outdated
|
||
* True : overwrite values in `self` with values from `other`. | ||
* False : only update values that are NA in `self`. | ||
|
||
filter_func : callable(1d-array) -> 1d-array<boolean>, default 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.
"default None" -> "optional"
pandas/core/frame.py
Outdated
@@ -4350,6 +4370,8 @@ def update(self, other, join='left', overwrite=True, filter_func=None, | |||
1 2 5 | |||
2 3 6 | |||
|
|||
The DataFrame's length does not increase as a result of the update. |
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 add something like ", only values at matching index/column labels are updated"
DOC: Improve the docstring of DataFrame.update()
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 for the updates! Fixed up some minor formatting issues
Thanks for the PR @kantologist ! |
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:
If the validation script still gives errors, but you think there is a good reason
to deviate in this case (and there are certainly such cases), please state this
explicitly.