@@ -1141,16 +1141,18 @@ def test_set_value_copy_only_necessary_column(
1141
1141
assert np .shares_memory (get_array (df , "a" ), get_array (view , "a" ))
1142
1142
1143
1143
1144
- def test_series_midx_slice (using_copy_on_write ):
1144
+ def test_series_midx_slice (using_copy_on_write , warn_copy_on_write ):
1145
1145
ser = Series ([1 , 2 , 3 ], index = pd .MultiIndex .from_arrays ([[1 , 1 , 2 ], [3 , 4 , 5 ]]))
1146
+ ser_orig = ser .copy ()
1146
1147
result = ser [1 ]
1147
1148
assert np .shares_memory (get_array (ser ), get_array (result ))
1148
- # TODO(CoW-warn) should warn -> reference is only tracked in CoW mode, so
1149
- # warning is not triggered
1150
- result .iloc [0 ] = 100
1149
+ with tm .assert_cow_warning (warn_copy_on_write ):
1150
+ result .iloc [0 ] = 100
1151
1151
if using_copy_on_write :
1152
+ tm .assert_series_equal (ser , ser_orig )
1153
+ else :
1152
1154
expected = Series (
1153
- [1 , 2 , 3 ], index = pd .MultiIndex .from_arrays ([[1 , 1 , 2 ], [3 , 4 , 5 ]])
1155
+ [100 , 2 , 3 ], index = pd .MultiIndex .from_arrays ([[1 , 1 , 2 ], [3 , 4 , 5 ]])
1154
1156
)
1155
1157
tm .assert_series_equal (ser , expected )
1156
1158
@@ -1181,16 +1183,15 @@ def test_getitem_midx_slice(
1181
1183
assert df .iloc [0 , 0 ] == 100
1182
1184
1183
1185
1184
- def test_series_midx_tuples_slice (using_copy_on_write ):
1186
+ def test_series_midx_tuples_slice (using_copy_on_write , warn_copy_on_write ):
1185
1187
ser = Series (
1186
1188
[1 , 2 , 3 ],
1187
1189
index = pd .MultiIndex .from_tuples ([((1 , 2 ), 3 ), ((1 , 2 ), 4 ), ((2 , 3 ), 4 )]),
1188
1190
)
1189
1191
result = ser [(1 , 2 )]
1190
1192
assert np .shares_memory (get_array (ser ), get_array (result ))
1191
- # TODO(CoW-warn) should warn -> reference is only tracked in CoW mode, so
1192
- # warning is not triggered
1193
- result .iloc [0 ] = 100
1193
+ with tm .assert_cow_warning (warn_copy_on_write ):
1194
+ result .iloc [0 ] = 100
1194
1195
if using_copy_on_write :
1195
1196
expected = Series (
1196
1197
[1 , 2 , 3 ],
0 commit comments