Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ def set_flags(

Parameters
----------
copy : bool, default False
Specify if a copy of the object should be made.
allows_duplicate_labels : bool, optional
Whether the returned object allows duplicate labels.

Expand Down
18 changes: 18 additions & 0 deletions pandas/tests/copy_view/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,21 @@ def test_series_set_axis(using_copy_on_write):
ser2.iloc[0] = 0
assert not np.shares_memory(ser2, ser)
tm.assert_series_equal(ser, ser_orig)


def test_set_flags(using_copy_on_write):
ser = Series([1, 2, 3])
ser_orig = ser.copy()
ser2 = ser.set_flags(allows_duplicate_labels=False)

assert np.shares_memory(ser, ser2)

# mutating ser triggers a copy-on-write for the column / block
ser2.iloc[0] = 0
if using_copy_on_write:
assert not np.shares_memory(ser2, ser)
tm.assert_series_equal(ser, ser_orig)
else:
assert np.shares_memory(ser2, ser)
expected = Series([0, 2, 3])
tm.assert_series_equal(ser, expected)