@@ -35,36 +35,38 @@ def test_methods_iloc_warn(using_copy_on_write):
35
35
@pytest .mark .parametrize (
36
36
"func, args" ,
37
37
[
38
- ("replace" , (1 , 5 )),
38
+ ("replace" , (4 , 5 )),
39
39
("fillna" , (1 ,)),
40
40
("interpolate" , ()),
41
41
("bfill" , ()),
42
42
("ffill" , ()),
43
43
],
44
44
)
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 ()
49
51
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 )
52
53
53
54
# parent that holds item_cache is dead, so don't increase ref count
55
+ df = df_orig .copy ()
54
56
ser = df .copy ()["a" ]
55
57
getattr (ser , func )(* args , inplace = True )
56
58
57
- df = df .copy ()
58
-
59
+ df = df_orig .copy ()
59
60
df ["a" ] # populate the item_cache
60
61
ser = df .iloc [:, 0 ] # iloc creates a new object
61
- ser . fillna ( 0 , inplace = True )
62
+ getattr ( ser , func )( * args , inplace = True )
62
63
64
+ df = df_orig .copy ()
63
65
df ["a" ] # populate the item_cache
64
66
ser = df ["a" ]
65
- ser . fillna ( 0 , inplace = True )
67
+ getattr ( ser , func )( * args , inplace = True )
66
68
67
- df = df .copy ()
69
+ df = df_orig .copy ()
68
70
df ["a" ] # populate the item_cache
69
71
if using_copy_on_write :
70
72
with tm .raises_chained_assignment_error ():
0 commit comments