Skip to content

API/DEPR: replace "raise_conflict" with "errors" for df.update #23657

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 6 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Review (jreback)
  • Loading branch information
h-vetinari committed Nov 14, 2018
commit 8f9ee07d93eed9a1a2db526324852228a883e47e
11 changes: 10 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5246,14 +5246,20 @@ def update(self, other, join='left', overwrite=True, filter_func=None,
If 'raise', will raise a ValueError if the DataFrame and `other`
Copy link
Contributor

Choose a reason for hiding this comment

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

versionchanged tag

both contain non-NA data in the same place.

.. versionchanged :: 0.24.0
Changed from `raise_conflict=False|True` to `errors='ignore'|'raise'`.

Returns
-------
None : method directly changes calling object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added due to running docstring validation

Raises
------
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add an if for valid errors values (e.g. raise/error), and test for passing bad values in the tests themselves

ValueError
When `errors='raise'` and there's overlapping non-NA data.
* When `errors='raise'` and there's overlapping non-NA data.
* When `errors` is not either `'ignore'` or `'raise'`
NotImplementedError
* If `join != 'left'`

See Also
--------
Expand Down Expand Up @@ -5324,6 +5330,9 @@ def update(self, other, join='left', overwrite=True, filter_func=None,
# TODO: Support other joins
if join != 'left': # pragma: no cover
raise NotImplementedError("Only left join is supported")
if errors not in ['ignore', 'raise']:
raise ValueError("The parameter errors must be either "
"'ignore' or 'raise'")

if not isinstance(other, DataFrame):
other = DataFrame(other)
Expand Down
19 changes: 17 additions & 2 deletions pandas/tests/frame/test_combine_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,17 @@ def test_update_filtered(self):
[1.5, nan, 7.]])
assert_frame_equal(df, expected)

def test_update_raise(self):
@pytest.mark.parametrize('bad_kwarg, exception, msg', [
# errors must be 'ignore' or 'raise'
({'errors': 'something'}, ValueError, 'The parameter errors must.*'),
({'join': 'inner'}, NotImplementedError, 'Only left join is supported')
])
def test_update_raise_bad_parameter(self, bad_kwarg, exception, msg):
df = DataFrame([[1.5, 1, 3.]])
with pytest.raises(exception, match=msg):
df.update(df, **bad_kwarg)

def test_update_raise_on_overlap(self):
df = DataFrame([[1.5, 1, 3.],
[1.5, nan, 3.],
[1.5, nan, 3],
Expand All @@ -323,8 +333,13 @@ def test_update_raise(self):
[nan, 7]], index=[1, 3], columns=[1, 2])
with pytest.raises(ValueError, match="Data overlaps"):
df.update(other, errors='raise')
Copy link
Contributor

Choose a reason for hiding this comment

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

can you move this to another test, e.g. test_update_deprecation


@pytest.mark.parametrize('raise_conflict', [True, False])
def test_update_deprecation(self, raise_conflict):
df = DataFrame([[1.5, 1, 3.]])
other = DataFrame()
with tm.assert_produces_warning(FutureWarning):
df.update(other, raise_conflict=False)
df.update(other, raise_conflict=raise_conflict)

def test_update_from_non_df(self):
d = {'a': Series([1, 2, 3, 4]), 'b': Series([5, 6, 7, 8])}
Expand Down