Skip to content

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

Merged
merged 15 commits into from
Mar 13, 2018
Merged
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4321,21 +4321,41 @@ def combiner(x, y, needs_i8_conversion=False):
def update(self, other, join='left', overwrite=True, filter_func=None,
raise_conflict=False):
"""
Modify DataFrame in place using non-NA values from passed
DataFrame. Aligns on indices
Modify in place using non-NA values from another DataFrame.

Aligns on indices. There is no return value.

Parameters
----------
other : DataFrame, or object coercible into a DataFrame
Index should be similar to one of the columns in this one. If a
Copy link
Member

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?

Series is passed, its name attribute must be set, and that will be
used as the column name in the resulting joined DataFrame.
join : {'left'}, default 'left'
Only left join is implemented, keeping the index and columns of the
original object.
overwrite : boolean, default True
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`.
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 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)

* False : only update values that are NA in `self`.

filter_func : callable(1d-array) -> 1d-array<boolean>, default None
Copy link
Member

Choose a reason for hiding this comment

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

"default None" -> "optional"

Can choose to replace values other than NA. Return True for values
that should be updated
that should be updated.
raise_conflict : boolean
If True, will raise an error if the DataFrame and other both
contain data in the same place.
If True, will raise a `ValueError` if the DataFrame and `other`
both contain non-NA data in the same place.

Raises
------
ValueError
When `raise_conflict` is True and there's overlapping non-NA data.

See Also
--------
dict.update : Similar method for dictionaries.
DataFrame.merge : For column(s)-on-columns(s) operations.

Examples
--------
Expand All @@ -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.
Copy link
Member

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"


>>> df = pd.DataFrame({'A': ['a', 'b', 'c'],
... 'B': ['x', 'y', 'z']})
>>> new_df = pd.DataFrame({'B': ['d', 'e', 'f', 'g', 'h', 'i']})
Expand All @@ -4360,6 +4382,8 @@ def update(self, other, join='left', overwrite=True, filter_func=None,
1 b e
2 c f

For Series, it's name attribute must be set.

>>> df = pd.DataFrame({'A': ['a', 'b', 'c'],
... 'B': ['x', 'y', 'z']})
>>> new_column = pd.Series(['d', 'e'], name='B', index=[0, 2])
Expand Down