@@ -986,20 +986,28 @@ def test_sort_values_inplace(using_copy_on_write, obj, kwargs, using_array_manag
986
986
assert np .shares_memory (get_array (obj , "a" ), get_array (view , "a" ))
987
987
988
988
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 ):
990
991
df = DataFrame ({"a" : [1 , 2 ], "b" : "c" })
991
- df2 = df .round ()
992
992
df_orig = df .copy ()
993
+ df2 = df .round (decimals = decimals )
993
994
994
995
if using_copy_on_write :
995
996
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" ))
997
1003
else :
998
1004
assert not np .shares_memory (get_array (df2 , "b" ), get_array (df , "b" ))
999
1005
1000
1006
df2 .iloc [0 , 1 ] = "d"
1007
+ df2 .iloc [0 , 0 ] = 4
1001
1008
if using_copy_on_write :
1002
1009
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" ))
1003
1011
tm .assert_frame_equal (df , df_orig )
1004
1012
1005
1013
0 commit comments