Skip to content

Commit c03ac84

Browse files
authored
TST: Add test for set_index not mutating index when parent is mutated (#51324)
1 parent 985e89a commit c03ac84

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pandas/tests/copy_view/test_methods.py

+9
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,15 @@ def test_set_index(using_copy_on_write):
648648
tm.assert_frame_equal(df, df_orig)
649649

650650

651+
def test_set_index_mutating_parent_does_not_mutate_index():
652+
df = DataFrame({"a": [1, 2, 3], "b": 1})
653+
result = df.set_index("a")
654+
expected = result.copy()
655+
656+
df.iloc[0, 0] = 100
657+
tm.assert_frame_equal(result, expected)
658+
659+
651660
def test_add_prefix(using_copy_on_write):
652661
# GH 49473
653662
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [0.1, 0.2, 0.3]})

0 commit comments

Comments
 (0)