Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

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
Merge branch 'main' into feature/assert-produces-warning-enh
# Conflicts: #	pandas/tests/copy_view/test_chained_assignment_deprecation.py #	pandas/tests/frame/methods/test_interpolate.py #	pandas/tests/indexing/test_chaining_and_caching.py
  • Loading branch information
Jorewin committed Feb 19, 2024
commit b8151ee01863e8e9a6821874fd868df182331c43
10 changes: 2 additions & 8 deletions pandas/tests/copy_view/test_chained_assignment_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,5 @@ def test_series_setitem(indexer):
def test_frame_setitem(indexer):
df = DataFrame({"a": [1, 2, 3, 4, 5], "b": 1})

extra_warnings = () if using_copy_on_write else (SettingWithCopyWarning,)

with option_context("chained_assignment", "warn"):
with tm.raises_chained_assignment_error(
extra_warnings=extra_warnings,
extra_match=(None for _ in range(len(extra_warnings))),
):
df[0:3][indexer] = 10
with tm.raises_chained_assignment_error():
df[0:3][indexer] = 10
30 changes: 4 additions & 26 deletions pandas/tests/frame/methods/test_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,32 +339,10 @@ def test_interp_inplace(self):
expected = df.copy()
result = df.copy()

if using_copy_on_write:
with tm.raises_chained_assignment_error():
return_value = result["a"].interpolate(inplace=True)
assert return_value is None
tm.assert_frame_equal(result, expected_cow)
else:
with tm.assert_produces_warning(FutureWarning, match="inplace method"):
return_value = result["a"].interpolate(inplace=True)
assert return_value is None
tm.assert_frame_equal(result, expected)

result = df.copy()
msg = "The 'downcast' keyword in Series.interpolate is deprecated"

if using_copy_on_write:
with tm.raises_chained_assignment_error(
extra_warnings=(FutureWarning,), extra_match=(msg,)
):
return_value = result["a"].interpolate(inplace=True, downcast="infer")
assert return_value is None
tm.assert_frame_equal(result, expected_cow)
else:
with tm.assert_produces_warning(FutureWarning, match=msg):
return_value = result["a"].interpolate(inplace=True, downcast="infer")
assert return_value is None
tm.assert_frame_equal(result, expected.astype("int64"))
with tm.raises_chained_assignment_error():
return_value = result["a"].interpolate(inplace=True)
assert return_value is None
tm.assert_frame_equal(result, expected)

def test_interp_inplace_row(self):
# GH 10395
Expand Down
27 changes: 10 additions & 17 deletions pandas/tests/indexing/test_chaining_and_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,23 +284,16 @@ def test_detect_chained_assignment_changing_dtype(self):
)
df_original = df.copy()

if using_copy_on_write or warn_copy_on_write:
with tm.raises_chained_assignment_error():
df.loc[2]["D"] = "foo"
with tm.raises_chained_assignment_error():
df.loc[2]["C"] = "foo"
tm.assert_frame_equal(df, df_original)
with tm.raises_chained_assignment_error(
extra_warnings=(FutureWarning,), extra_match=(None,)
):
df["C"][2] = "foo"
if using_copy_on_write:
tm.assert_frame_equal(df, df_original)
else:
assert df.loc[2, "C"] == "foo"
else:
with pytest.raises(SettingWithCopyError, match=msg):
df.loc[2]["D"] = "foo"
with tm.raises_chained_assignment_error():
df.loc[2]["D"] = "foo"
with tm.raises_chained_assignment_error():
df.loc[2]["C"] = "foo"
tm.assert_frame_equal(df, df_original)
with tm.raises_chained_assignment_error(
extra_warnings=(FutureWarning,), extra_match=(None,)
):
df["C"][2] = "foo"
tm.assert_frame_equal(df, df_original)

def test_setting_with_copy_bug(self):
# operating on a copy
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.