Skip to content

TST: clean CoW chained assignment warning iloc test case #56400

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
Changes from all 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
26 changes: 14 additions & 12 deletions pandas/tests/copy_view/test_chained_assignment_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,38 @@ def test_methods_iloc_warn(using_copy_on_write):
@pytest.mark.parametrize(
"func, args",
[
("replace", (1, 5)),
("replace", (4, 5)),
Copy link
Member Author

Choose a reason for hiding this comment

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

My understanding is that this test is just for the chained warning, so changing here to a value that is not present, so it will never trigger a "setting on view" warning at the block level (since there is nothing to replace, like for fillna there is nothing to fill), and then we only have to care about whether the chained warning is present or not

("fillna", (1,)),
("interpolate", ()),
("bfill", ()),
("ffill", ()),
],
)
def test_methods_iloc_getitem_item_cache(
func, args, using_copy_on_write, warn_copy_on_write
):
df = DataFrame({"a": [1, 2, 3], "b": 1})
def test_methods_iloc_getitem_item_cache(func, args, using_copy_on_write):
# ensure we don't incorrectly raise chained assignment warning because
# of the item cache / iloc not setting the item cache
df_orig = DataFrame({"a": [1, 2, 3], "b": 1})

df = df_orig.copy()
ser = df.iloc[:, 0]
with tm.assert_cow_warning(warn_copy_on_write and func == "replace"):
getattr(ser, func)(*args, inplace=True)
getattr(ser, func)(*args, inplace=True)

# parent that holds item_cache is dead, so don't increase ref count
df = df_orig.copy()
ser = df.copy()["a"]
getattr(ser, func)(*args, inplace=True)

df = df.copy()

df = df_orig.copy()
df["a"] # populate the item_cache
ser = df.iloc[:, 0] # iloc creates a new object
ser.fillna(0, inplace=True)
getattr(ser, func)(*args, inplace=True)

df = df_orig.copy()
df["a"] # populate the item_cache
ser = df["a"]
ser.fillna(0, inplace=True)
getattr(ser, func)(*args, inplace=True)

df = df.copy()
df = df_orig.copy()
df["a"] # populate the item_cache
if using_copy_on_write:
with tm.raises_chained_assignment_error():
Expand Down