@@ -163,7 +163,6 @@ def test_subset_column_slice(
163
163
subset .iloc [0 , 0 ] = 0
164
164
assert not np .shares_memory (get_array (subset , "b" ), get_array (df , "b" ))
165
165
elif warn_copy_on_write :
166
- # TODO(CoW-warn) should warn
167
166
with tm .assert_cow_warning (single_block ):
168
167
subset .iloc [0 , 0 ] = 0
169
168
else :
@@ -334,7 +333,6 @@ def test_subset_set_with_row_indexer(
334
333
):
335
334
pytest .skip ("setitem with labels selects on columns" )
336
335
337
- # TODO(CoW-warn) should warn
338
336
if using_copy_on_write :
339
337
indexer_si (subset )[indexer ] = 0
340
338
elif warn_copy_on_write :
@@ -369,7 +367,8 @@ def test_subset_set_with_mask(backend, using_copy_on_write, warn_copy_on_write):
369
367
370
368
mask = subset > 3
371
369
372
- # TODO(CoW-warn) should warn
370
+ # TODO(CoW-warn) should warn -> mask is a DataFrame, which ends up going through
371
+ # DataFrame._where(..., inplace=True)
373
372
if using_copy_on_write or warn_copy_on_write :
374
373
subset [mask ] = 0
375
374
else :
@@ -403,7 +402,6 @@ def test_subset_set_column(backend, using_copy_on_write, warn_copy_on_write):
403
402
else :
404
403
arr = pd .array ([10 , 11 ], dtype = "Int64" )
405
404
406
- # TODO(CoW-warn) should warn
407
405
if using_copy_on_write or warn_copy_on_write :
408
406
subset ["a" ] = arr
409
407
else :
@@ -512,7 +510,6 @@ def test_subset_set_columns(backend, using_copy_on_write, warn_copy_on_write, dt
512
510
df_orig = df .copy ()
513
511
subset = df [1 :3 ]
514
512
515
- # TODO(CoW-warn) should warn
516
513
if using_copy_on_write or warn_copy_on_write :
517
514
subset [["a" , "c" ]] = 0
518
515
else :
@@ -877,6 +874,8 @@ def test_series_subset_set_with_indexer(
877
874
)
878
875
if warn_copy_on_write :
879
876
# TODO(CoW-warn) should also warn for setting with mask
877
+ # -> Series.__setitem__ with boolean mask ends up using Series._set_values
878
+ # or Series._where depending on value being set
880
879
with tm .assert_cow_warning (
881
880
not is_mask , raise_on_extra_warnings = warn is not None
882
881
):
@@ -1006,6 +1005,7 @@ def test_column_as_series_set_with_upcast(
1006
1005
s [0 ] = "foo"
1007
1006
expected = Series ([1 , 2 , 3 ], name = "a" )
1008
1007
elif using_copy_on_write or warn_copy_on_write or using_array_manager :
1008
+ # TODO(CoW-warn) assert the FutureWarning for CoW is also raised
1009
1009
with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
1010
1010
s [0 ] = "foo"
1011
1011
expected = Series (["foo" , 2 , 3 ], dtype = object , name = "a" )
@@ -1130,6 +1130,7 @@ def test_set_value_copy_only_necessary_column(
1130
1130
view = df [:]
1131
1131
1132
1132
if val == "a" and indexer [0 ] != slice (None ):
1133
+ # TODO(CoW-warn) assert the FutureWarning for CoW is also raised
1133
1134
with tm .assert_produces_warning (
1134
1135
FutureWarning , match = "Setting an item of incompatible dtype is deprecated"
1135
1136
):
@@ -1154,6 +1155,8 @@ def test_series_midx_slice(using_copy_on_write):
1154
1155
ser = Series ([1 , 2 , 3 ], index = pd .MultiIndex .from_arrays ([[1 , 1 , 2 ], [3 , 4 , 5 ]]))
1155
1156
result = ser [1 ]
1156
1157
assert np .shares_memory (get_array (ser ), get_array (result ))
1158
+ # TODO(CoW-warn) should warn -> reference is only tracked in CoW mode, so
1159
+ # warning is not triggered
1157
1160
result .iloc [0 ] = 100
1158
1161
if using_copy_on_write :
1159
1162
expected = Series (
@@ -1162,7 +1165,9 @@ def test_series_midx_slice(using_copy_on_write):
1162
1165
tm .assert_series_equal (ser , expected )
1163
1166
1164
1167
1165
- def test_getitem_midx_slice (using_copy_on_write , using_array_manager ):
1168
+ def test_getitem_midx_slice (
1169
+ using_copy_on_write , warn_copy_on_write , using_array_manager
1170
+ ):
1166
1171
df = DataFrame ({("a" , "x" ): [1 , 2 ], ("a" , "y" ): 1 , ("b" , "x" ): 2 })
1167
1172
df_orig = df .copy ()
1168
1173
new_df = df [("a" ,)]
@@ -1175,6 +1180,15 @@ def test_getitem_midx_slice(using_copy_on_write, using_array_manager):
1175
1180
if using_copy_on_write :
1176
1181
new_df .iloc [0 , 0 ] = 100
1177
1182
tm .assert_frame_equal (df_orig , df )
1183
+ else :
1184
+ if warn_copy_on_write :
1185
+ with tm .assert_cow_warning ():
1186
+ new_df .iloc [0 , 0 ] = 100
1187
+ else :
1188
+ with pd .option_context ("chained_assignment" , "warn" ):
1189
+ with tm .assert_produces_warning (SettingWithCopyWarning ):
1190
+ new_df .iloc [0 , 0 ] = 100
1191
+ assert df .iloc [0 , 0 ] == 100
1178
1192
1179
1193
1180
1194
def test_series_midx_tuples_slice (using_copy_on_write ):
@@ -1184,6 +1198,8 @@ def test_series_midx_tuples_slice(using_copy_on_write):
1184
1198
)
1185
1199
result = ser [(1 , 2 )]
1186
1200
assert np .shares_memory (get_array (ser ), get_array (result ))
1201
+ # TODO(CoW-warn) should warn -> reference is only tracked in CoW mode, so
1202
+ # warning is not triggered
1187
1203
result .iloc [0 ] = 100
1188
1204
if using_copy_on_write :
1189
1205
expected = Series (
0 commit comments