@@ -139,7 +139,9 @@ def test_subset_row_slice(backend, using_copy_on_write):
139
139
@pytest .mark .parametrize (
140
140
"dtype" , ["int64" , "float64" ], ids = ["single-block" , "mixed-block" ]
141
141
)
142
- def test_subset_column_slice (backend , using_copy_on_write , using_array_manager , dtype ):
142
+ def test_subset_column_slice (
143
+ backend , using_copy_on_write , warn_copy_on_write , using_array_manager , dtype
144
+ ):
143
145
# Case: taking a subset of the columns of a DataFrame using a slice
144
146
# + afterwards modifying the subset
145
147
dtype_backend , DataFrame , _ = backend
@@ -159,10 +161,14 @@ def test_subset_column_slice(backend, using_copy_on_write, using_array_manager,
159
161
160
162
subset .iloc [0 , 0 ] = 0
161
163
assert not np .shares_memory (get_array (subset , "b" ), get_array (df , "b" ))
162
-
163
164
else :
164
165
# we only get a warning in case of a single block
165
- warn = SettingWithCopyWarning if single_block else None
166
+ # TODO
167
+ warn = (
168
+ SettingWithCopyWarning
169
+ if (single_block and not warn_copy_on_write )
170
+ else None
171
+ )
166
172
with pd .option_context ("chained_assignment" , "warn" ):
167
173
with tm .assert_produces_warning (warn ):
168
174
subset .iloc [0 , 0 ] = 0
@@ -303,7 +309,9 @@ def test_subset_iloc_rows_columns(
303
309
[slice (0 , 2 ), np .array ([True , True , False ]), np .array ([0 , 1 ])],
304
310
ids = ["slice" , "mask" , "array" ],
305
311
)
306
- def test_subset_set_with_row_indexer (backend , indexer_si , indexer , using_copy_on_write ):
312
+ def test_subset_set_with_row_indexer (
313
+ backend , indexer_si , indexer , using_copy_on_write , warn_copy_on_write
314
+ ):
307
315
# Case: setting values with a row indexer on a viewing subset
308
316
# subset[indexer] = value and subset.iloc[indexer] = value
309
317
_ , DataFrame , _ = backend
@@ -318,7 +326,8 @@ def test_subset_set_with_row_indexer(backend, indexer_si, indexer, using_copy_on
318
326
):
319
327
pytest .skip ("setitem with labels selects on columns" )
320
328
321
- if using_copy_on_write :
329
+ # TODO
330
+ if using_copy_on_write or warn_copy_on_write :
322
331
indexer_si (subset )[indexer ] = 0
323
332
else :
324
333
# INFO iloc no longer raises warning since pandas 1.4
@@ -340,7 +349,7 @@ def test_subset_set_with_row_indexer(backend, indexer_si, indexer, using_copy_on
340
349
tm .assert_frame_equal (df , df_orig )
341
350
342
351
343
- def test_subset_set_with_mask (backend , using_copy_on_write ):
352
+ def test_subset_set_with_mask (backend , using_copy_on_write , warn_copy_on_write ):
344
353
# Case: setting values with a mask on a viewing subset: subset[mask] = value
345
354
_ , DataFrame , _ = backend
346
355
df = DataFrame ({"a" : [1 , 2 , 3 , 4 ], "b" : [4 , 5 , 6 , 7 ], "c" : [0.1 , 0.2 , 0.3 , 0.4 ]})
@@ -349,7 +358,8 @@ def test_subset_set_with_mask(backend, using_copy_on_write):
349
358
350
359
mask = subset > 3
351
360
352
- if using_copy_on_write :
361
+ # TODO
362
+ if using_copy_on_write or warn_copy_on_write :
353
363
subset [mask ] = 0
354
364
else :
355
365
with pd .option_context ("chained_assignment" , "warn" ):
@@ -370,7 +380,7 @@ def test_subset_set_with_mask(backend, using_copy_on_write):
370
380
tm .assert_frame_equal (df , df_orig )
371
381
372
382
373
- def test_subset_set_column (backend , using_copy_on_write ):
383
+ def test_subset_set_column (backend , using_copy_on_write , warn_copy_on_write ):
374
384
# Case: setting a single column on a viewing subset -> subset[col] = value
375
385
dtype_backend , DataFrame , _ = backend
376
386
df = DataFrame ({"a" : [1 , 2 , 3 ], "b" : [4 , 5 , 6 ], "c" : [0.1 , 0.2 , 0.3 ]})
@@ -382,7 +392,8 @@ def test_subset_set_column(backend, using_copy_on_write):
382
392
else :
383
393
arr = pd .array ([10 , 11 ], dtype = "Int64" )
384
394
385
- if using_copy_on_write :
395
+ # TODO
396
+ if using_copy_on_write or warn_copy_on_write :
386
397
subset ["a" ] = arr
387
398
else :
388
399
with pd .option_context ("chained_assignment" , "warn" ):
@@ -472,7 +483,7 @@ def test_subset_set_column_with_loc2(backend, using_copy_on_write, using_array_m
472
483
@pytest .mark .parametrize (
473
484
"dtype" , ["int64" , "float64" ], ids = ["single-block" , "mixed-block" ]
474
485
)
475
- def test_subset_set_columns (backend , using_copy_on_write , dtype ):
486
+ def test_subset_set_columns (backend , using_copy_on_write , warn_copy_on_write , dtype ):
476
487
# Case: setting multiple columns on a viewing subset
477
488
# -> subset[[col1, col2]] = value
478
489
dtype_backend , DataFrame , _ = backend
@@ -482,7 +493,8 @@ def test_subset_set_columns(backend, using_copy_on_write, dtype):
482
493
df_orig = df .copy ()
483
494
subset = df [1 :3 ]
484
495
485
- if using_copy_on_write :
496
+ # TODO
497
+ if using_copy_on_write or warn_copy_on_write :
486
498
subset [["a" , "c" ]] = 0
487
499
else :
488
500
with pd .option_context ("chained_assignment" , "warn" ):
@@ -879,7 +891,9 @@ def test_del_series(backend):
879
891
# Accessing column as Series
880
892
881
893
882
- def test_column_as_series (backend , using_copy_on_write , using_array_manager ):
894
+ def test_column_as_series (
895
+ backend , using_copy_on_write , warn_copy_on_write , using_array_manager
896
+ ):
883
897
# Case: selecting a single column now also uses Copy-on-Write
884
898
dtype_backend , DataFrame , Series = backend
885
899
df = DataFrame ({"a" : [1 , 2 , 3 ], "b" : [4 , 5 , 6 ], "c" : [0.1 , 0.2 , 0.3 ]})
@@ -892,10 +906,14 @@ def test_column_as_series(backend, using_copy_on_write, using_array_manager):
892
906
if using_copy_on_write or using_array_manager :
893
907
s [0 ] = 0
894
908
else :
895
- warn = SettingWithCopyWarning if dtype_backend == "numpy" else None
896
- with pd .option_context ("chained_assignment" , "warn" ):
897
- with tm .assert_produces_warning (warn ):
909
+ if warn_copy_on_write :
910
+ with tm .assert_produces_warning (FutureWarning ):
898
911
s [0 ] = 0
912
+ else :
913
+ warn = SettingWithCopyWarning if dtype_backend == "numpy" else None
914
+ with pd .option_context ("chained_assignment" , "warn" ):
915
+ with tm .assert_produces_warning (warn ):
916
+ s [0 ] = 0
899
917
900
918
expected = Series ([0 , 2 , 3 ], name = "a" )
901
919
tm .assert_series_equal (s , expected )
@@ -910,7 +928,7 @@ def test_column_as_series(backend, using_copy_on_write, using_array_manager):
910
928
911
929
912
930
def test_column_as_series_set_with_upcast (
913
- backend , using_copy_on_write , using_array_manager
931
+ backend , using_copy_on_write , using_array_manager , warn_copy_on_write
914
932
):
915
933
# Case: selecting a single column now also uses Copy-on-Write -> when
916
934
# setting a value causes an upcast, we don't need to update the parent
@@ -921,10 +939,12 @@ def test_column_as_series_set_with_upcast(
921
939
922
940
s = df ["a" ]
923
941
if dtype_backend == "nullable" :
924
- with pytest .raises (TypeError , match = "Invalid value" ):
925
- s [0 ] = "foo"
942
+ warn = FutureWarning if warn_copy_on_write else None
943
+ with tm .assert_produces_warning (warn ):
944
+ with pytest .raises (TypeError , match = "Invalid value" ):
945
+ s [0 ] = "foo"
926
946
expected = Series ([1 , 2 , 3 ], name = "a" )
927
- elif using_copy_on_write or using_array_manager :
947
+ elif using_copy_on_write or warn_copy_on_write or using_array_manager :
928
948
with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
929
949
s [0 ] = "foo"
930
950
expected = Series (["foo" , 2 , 3 ], dtype = object , name = "a" )
@@ -962,7 +982,12 @@ def test_column_as_series_set_with_upcast(
962
982
ids = ["getitem" , "loc" , "iloc" ],
963
983
)
964
984
def test_column_as_series_no_item_cache (
965
- request , backend , method , using_copy_on_write , using_array_manager
985
+ request ,
986
+ backend ,
987
+ method ,
988
+ using_copy_on_write ,
989
+ warn_copy_on_write ,
990
+ using_array_manager ,
966
991
):
967
992
# Case: selecting a single column (which now also uses Copy-on-Write to protect
968
993
# the view) should always give a new object (i.e. not make use of a cache)
@@ -979,7 +1004,8 @@ def test_column_as_series_no_item_cache(
979
1004
else :
980
1005
assert s1 is s2
981
1006
982
- if using_copy_on_write or using_array_manager :
1007
+ # TODO
1008
+ if using_copy_on_write or warn_copy_on_write or using_array_manager :
983
1009
s1 .iloc [0 ] = 0
984
1010
else :
985
1011
warn = SettingWithCopyWarning if dtype_backend == "numpy" else None
0 commit comments