@@ -986,20 +986,28 @@ def test_sort_values_inplace(using_copy_on_write, obj, kwargs, using_array_manag
986986 assert np .shares_memory (get_array (obj , "a" ), get_array (view , "a" ))
987987
988988
989- def test_round (using_copy_on_write ):
989+ @pytest .mark .parametrize ("decimals" , [- 1 , 0 , 1 ])
990+ def test_round (using_copy_on_write , decimals ):
990991 df = DataFrame ({"a" : [1 , 2 ], "b" : "c" })
991- df2 = df .round ()
992992 df_orig = df .copy ()
993+ df2 = df .round (decimals = decimals )
993994
994995 if using_copy_on_write :
995996 assert np .shares_memory (get_array (df2 , "b" ), get_array (df , "b" ))
996- assert np .shares_memory (get_array (df2 , "a" ), get_array (df , "a" ))
997+ # TODO: Make inplace by using out parameter of ndarray.round?
998+ if decimals >= 0 :
999+ # Ensure lazy copy if no-op
1000+ assert np .shares_memory (get_array (df2 , "a" ), get_array (df , "a" ))
1001+ else :
1002+ assert not np .shares_memory (get_array (df2 , "a" ), get_array (df , "a" ))
9971003 else :
9981004 assert not np .shares_memory (get_array (df2 , "b" ), get_array (df , "b" ))
9991005
10001006 df2 .iloc [0 , 1 ] = "d"
1007+ df2 .iloc [0 , 0 ] = 4
10011008 if using_copy_on_write :
10021009 assert not np .shares_memory (get_array (df2 , "b" ), get_array (df , "b" ))
1010+ assert not np .shares_memory (get_array (df2 , "a" ), get_array (df , "a" ))
10031011 tm .assert_frame_equal (df , df_orig )
10041012
10051013
0 commit comments