File tree 2 files changed +20
-0
lines changed
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -405,6 +405,8 @@ def set_flags(
405
405
406
406
Parameters
407
407
----------
408
+ copy : bool, default False
409
+ Specify if a copy of the object should be made.
408
410
allows_duplicate_labels : bool, optional
409
411
Whether the returned object allows duplicate labels.
410
412
Original file line number Diff line number Diff line change @@ -514,6 +514,24 @@ def test_series_set_axis(using_copy_on_write):
514
514
tm .assert_series_equal (ser , ser_orig )
515
515
516
516
517
+ def test_set_flags (using_copy_on_write ):
518
+ ser = Series ([1 , 2 , 3 ])
519
+ ser_orig = ser .copy ()
520
+ ser2 = ser .set_flags (allows_duplicate_labels = False )
521
+
522
+ assert np .shares_memory (ser , ser2 )
523
+
524
+ # mutating ser triggers a copy-on-write for the column / block
525
+ ser2 .iloc [0 ] = 0
526
+ if using_copy_on_write :
527
+ assert not np .shares_memory (ser2 , ser )
528
+ tm .assert_series_equal (ser , ser_orig )
529
+ else :
530
+ assert np .shares_memory (ser2 , ser )
531
+ expected = Series ([0 , 2 , 3 ])
532
+ tm .assert_series_equal (ser , expected )
533
+
534
+
517
535
@pytest .mark .parametrize ("copy_kwargs" , [{"copy" : True }, {}])
518
536
@pytest .mark .parametrize ("kwargs" , [{"mapper" : "test" }, {"index" : "test" }])
519
537
def test_rename_axis (using_copy_on_write , kwargs , copy_kwargs ):
You can’t perform that action at this time.
0 commit comments