Skip to content

Commit 68c1af5

Browse files
TST: clean CoW chained assignment warning iloc test case (#56400)
1 parent 8399185 commit 68c1af5

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

pandas/tests/copy_view/test_chained_assignment_deprecation.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,38 @@ def test_methods_iloc_warn(using_copy_on_write):
3535
@pytest.mark.parametrize(
3636
"func, args",
3737
[
38-
("replace", (1, 5)),
38+
("replace", (4, 5)),
3939
("fillna", (1,)),
4040
("interpolate", ()),
4141
("bfill", ()),
4242
("ffill", ()),
4343
],
4444
)
45-
def test_methods_iloc_getitem_item_cache(
46-
func, args, using_copy_on_write, warn_copy_on_write
47-
):
48-
df = DataFrame({"a": [1, 2, 3], "b": 1})
45+
def test_methods_iloc_getitem_item_cache(func, args, using_copy_on_write):
46+
# ensure we don't incorrectly raise chained assignment warning because
47+
# of the item cache / iloc not setting the item cache
48+
df_orig = DataFrame({"a": [1, 2, 3], "b": 1})
49+
50+
df = df_orig.copy()
4951
ser = df.iloc[:, 0]
50-
with tm.assert_cow_warning(warn_copy_on_write and func == "replace"):
51-
getattr(ser, func)(*args, inplace=True)
52+
getattr(ser, func)(*args, inplace=True)
5253

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

57-
df = df.copy()
58-
59+
df = df_orig.copy()
5960
df["a"] # populate the item_cache
6061
ser = df.iloc[:, 0] # iloc creates a new object
61-
ser.fillna(0, inplace=True)
62+
getattr(ser, func)(*args, inplace=True)
6263

64+
df = df_orig.copy()
6365
df["a"] # populate the item_cache
6466
ser = df["a"]
65-
ser.fillna(0, inplace=True)
67+
getattr(ser, func)(*args, inplace=True)
6668

67-
df = df.copy()
69+
df = df_orig.copy()
6870
df["a"] # populate the item_cache
6971
if using_copy_on_write:
7072
with tm.raises_chained_assignment_error():

0 commit comments

Comments
 (0)