@@ -193,3 +193,42 @@ def test_astype_arrow_timestamp(using_copy_on_write):
193
193
if using_copy_on_write :
194
194
assert not result ._mgr ._has_no_reference (0 )
195
195
assert np .shares_memory (get_array (df , "a" ).asi8 , get_array (result , "a" )._data )
196
+
197
+
198
+ def test_convert_dtypes_infer_objects (using_copy_on_write ):
199
+ ser = Series (["a" , "b" , "c" ])
200
+ ser_orig = ser .copy ()
201
+ result = ser .convert_dtypes (
202
+ convert_integer = False ,
203
+ convert_boolean = False ,
204
+ convert_floating = False ,
205
+ convert_string = False ,
206
+ )
207
+
208
+ if using_copy_on_write :
209
+ assert np .shares_memory (get_array (ser ), get_array (result ))
210
+ else :
211
+ assert not np .shares_memory (get_array (ser ), get_array (result ))
212
+
213
+ result .iloc [0 ] = "x"
214
+ tm .assert_series_equal (ser , ser_orig )
215
+
216
+
217
+ def test_convert_dtypes (using_copy_on_write ):
218
+ df = DataFrame ({"a" : ["a" , "b" ], "b" : [1 , 2 ], "c" : [1.5 , 2.5 ], "d" : [True , False ]})
219
+ df_orig = df .copy ()
220
+ df2 = df .convert_dtypes ()
221
+
222
+ if using_copy_on_write :
223
+ assert np .shares_memory (get_array (df2 , "a" ), get_array (df , "a" ))
224
+ assert np .shares_memory (get_array (df2 , "d" ), get_array (df , "d" ))
225
+ assert np .shares_memory (get_array (df2 , "b" ), get_array (df , "b" ))
226
+ assert np .shares_memory (get_array (df2 , "c" ), get_array (df , "c" ))
227
+ else :
228
+ assert not np .shares_memory (get_array (df2 , "a" ), get_array (df , "a" ))
229
+ assert not np .shares_memory (get_array (df2 , "b" ), get_array (df , "b" ))
230
+ assert not np .shares_memory (get_array (df2 , "c" ), get_array (df , "c" ))
231
+ assert not np .shares_memory (get_array (df2 , "d" ), get_array (df , "d" ))
232
+
233
+ df2 .iloc [0 , 0 ] = "x"
234
+ tm .assert_frame_equal (df , df_orig )
0 commit comments