Skip to content

Commit bf731cc

Browse files
authored
TST: Test cow for set_flags (#50489)
1 parent 07f0575 commit bf731cc

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pandas/core/generic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ def set_flags(
405405
406406
Parameters
407407
----------
408+
copy : bool, default False
409+
Specify if a copy of the object should be made.
408410
allows_duplicate_labels : bool, optional
409411
Whether the returned object allows duplicate labels.
410412

pandas/tests/copy_view/test_methods.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,24 @@ def test_series_set_axis(using_copy_on_write):
514514
tm.assert_series_equal(ser, ser_orig)
515515

516516

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+
517535
@pytest.mark.parametrize("copy_kwargs", [{"copy": True}, {}])
518536
@pytest.mark.parametrize("kwargs", [{"mapper": "test"}, {"index": "test"}])
519537
def test_rename_axis(using_copy_on_write, kwargs, copy_kwargs):

0 commit comments

Comments
 (0)