@@ -91,12 +91,13 @@ def test_interpolate_inplace_no_reference_no_copy(using_copy_on_write, vals):
91
91
@pytest .mark .parametrize (
92
92
"vals" , [[1 , np .nan , 2 ], [Timestamp ("2019-12-31" ), NaT , Timestamp ("2020-12-31" )]]
93
93
)
94
- def test_interpolate_inplace_with_refs (using_copy_on_write , vals ):
94
+ def test_interpolate_inplace_with_refs (using_copy_on_write , vals , warn_copy_on_write ):
95
95
df = DataFrame ({"a" : [1 , np .nan , 2 ]})
96
96
df_orig = df .copy ()
97
97
arr = get_array (df , "a" )
98
98
view = df [:]
99
- df .interpolate (method = "linear" , inplace = True )
99
+ with tm .assert_cow_warning (warn_copy_on_write ):
100
+ df .interpolate (method = "linear" , inplace = True )
100
101
101
102
if using_copy_on_write :
102
103
# Check that copy was triggered in interpolate and that we don't
@@ -109,6 +110,31 @@ def test_interpolate_inplace_with_refs(using_copy_on_write, vals):
109
110
assert np .shares_memory (arr , get_array (df , "a" ))
110
111
111
112
113
+ @pytest .mark .parametrize ("func" , ["ffill" , "bfill" ])
114
+ @pytest .mark .parametrize ("dtype" , ["float64" , "Float64" ])
115
+ def test_interp_fill_functions_inplace (
116
+ using_copy_on_write , func , warn_copy_on_write , dtype
117
+ ):
118
+ # Check that these takes the same code paths as interpolate
119
+ df = DataFrame ({"a" : [1 , np .nan , 2 ]}, dtype = dtype )
120
+ df_orig = df .copy ()
121
+ arr = get_array (df , "a" )
122
+ view = df [:]
123
+
124
+ with tm .assert_cow_warning (warn_copy_on_write and dtype == "float64" ):
125
+ getattr (df , func )(inplace = True )
126
+
127
+ if using_copy_on_write :
128
+ # Check that copy was triggered in interpolate and that we don't
129
+ # have any references left
130
+ assert not np .shares_memory (arr , get_array (df , "a" ))
131
+ tm .assert_frame_equal (df_orig , view )
132
+ assert df ._mgr ._has_no_reference (0 )
133
+ assert view ._mgr ._has_no_reference (0 )
134
+ else :
135
+ assert np .shares_memory (arr , get_array (df , "a" )) is (dtype == "float64" )
136
+
137
+
112
138
def test_interpolate_cleaned_fill_method (using_copy_on_write ):
113
139
# Check that "method is set to None" case works correctly
114
140
df = DataFrame ({"a" : ["a" , np .nan , "c" ], "b" : 1 })
0 commit comments