-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Improve the docstring of pandas.DataFrame.append() #20267
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
Conversation
pandas/core/frame.py
Outdated
@@ -5054,7 +5054,9 @@ def infer(x): | |||
def append(self, other, ignore_index=False, verify_integrity=False): | |||
""" | |||
Append rows of `other` to the end of this frame, returning a new |
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.
This needs to fit on a single line - can you consolidate?
pandas/core/frame.py
Outdated
object. Columns not in this frame are added as new columns. | ||
object. | ||
|
||
Columns not in this frame are added as new columns. |
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.
Instead of "this frame" can you say "the caller"? Also while conceptually simple the usage of the word "Columns" mixes reference to the calling object and the object being appended, so differentiating between those would be preferable
pandas/core/frame.py
Outdated
object. Columns not in this frame are added as new columns. | ||
Append rows of `other` to the end of `caller`, returning a new object. | ||
|
||
Columns not in the caller are added as new columns. |
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.
Better but for explicitness say "Columns in other
not in caller
are ..."
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 PR!
Other comments:
-
In the Notes: " A better solution is to append those rows to a list and then concatenate the list with the original DataFrame all at once." -> can you add
.. using :func:`pandas.concat`
at the end of that sentence ? -
for the Parameter section: 'boolean' -> 'bool'
pandas/core/frame.py
Outdated
@@ -5053,8 +5053,9 @@ def infer(x): | |||
|
|||
def append(self, other, ignore_index=False, verify_integrity=False): | |||
""" | |||
Append rows of `other` to the end of this frame, returning a new | |||
object. Columns not in this frame are added as new columns. | |||
Append rows of `other` to the end of `caller`, returning a new object. |
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.
'caller' is not needed to quote (it's not an argument).
Also given this is the docstring specific to DataFrame (not shared with Series), I think we can be more specific. So maybe "calling DataFrame" ? (or is it then too long ?)
pandas/core/frame.py
Outdated
object. Columns not in this frame are added as new columns. | ||
Append rows of `other` to the end of `caller`, returning a new object. | ||
|
||
Columns not in other are added as new columns. |
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 not the columns in other
, but in "calling DataFrame" (or more explicit: Columns in `other` that are not in the calling DataFrame are added as new columns
pandas/core/frame.py
Outdated
* left: use only keys from left frame, similar to a SQL left outer join; | ||
preserve key order | ||
preserve key order. |
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.
Shouldn't need periods at the end of bullet points
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.
Couple minor edits. You can also clean up the Returns
section where applicable to simply show that this returns a DataFrame
pandas/core/frame.py
Outdated
----------%s | ||
right : DataFrame | ||
---------- | ||
right : DataFrame or Series/dict-like object |
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.
Since Series
and dict
are distinct types I'd separate these out as DataFrame
, Series
or dict
. Update for append as well
pandas/core/frame.py
Outdated
copy : boolean, default True | ||
If False, do not copy data unnecessarily | ||
If False, do not copy data unnecessarily. |
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.
Generally put built-ins in backticks, so `False` wherever applicable
pandas/core/frame.py
Outdated
@@ -199,7 +201,7 @@ | |||
dataset. | |||
* "many_to_many" or "m:m": allowed, but does not result in checks. | |||
|
|||
.. versionadded:: 0.21.0 | |||
.. versionadded:: 0.21.0. |
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.
Don't put a period at the end of the versionadded
directive
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.
@Triple0 Can you try to limit the changes to a single docstring?
(I don't know to what extens other people are working on the merge / assign docstrings. It's fine to keep the changes you have in those, but please focus for the rest on doing edits to the append
docstring)
pandas/core/frame.py
Outdated
# ----------------------------------------------------------------------- | ||
# DataFrame class | ||
|
||
|
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.
@Triple0 Can you undo those unrelated white-space changes?
pandas/core/frame.py
Outdated
@@ -2689,14 +2699,15 @@ def insert(self, loc, column, value, allow_duplicates=False): | |||
allow_duplicates=allow_duplicates) | |||
|
|||
def assign(self, **kwargs): | |||
r""" |
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.
There is a reason for this 'r' (the \
should not be interpreted)
pandas/core/frame.py
Outdated
|
||
Keyword argument order is maintained for Python 3.6 and later. | ||
Keyword argument order is maintained for Python 3.6 and later. |
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 indentation was needed for having it part of the versionchanged directive
pandas/core/frame.py
Outdated
|
||
See Also | ||
-------- | ||
DataFrame.assign: For column(s)-on-DataFrame operations |
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.
This is the docstring of DataFrame.assign I think? So then not needed to refer to itself
Thanks @Triple0 ! |
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.