1
1
import numpy as np
2
2
import pytest
3
3
4
+ from pandas .errors import SettingWithCopyWarning
5
+
4
6
import pandas as pd
5
7
from pandas import (
6
8
DataFrame ,
7
9
Series ,
8
10
)
9
11
import pandas ._testing as tm
10
- import pandas .core .common as com
11
12
from pandas .tests .copy_view .util import get_array
12
13
13
14
# -----------------------------------------------------------------------------
@@ -31,7 +32,7 @@ def test_subset_column_selection(using_copy_on_write):
31
32
assert not np .shares_memory (get_array (subset , "a" ), get_array (df , "a" ))
32
33
# INFO this no longer raise warning since pandas 1.4
33
34
# with pd.option_context("chained_assignment", "warn"):
34
- # with tm.assert_produces_warning(com. SettingWithCopyWarning):
35
+ # with tm.assert_produces_warning(SettingWithCopyWarning):
35
36
subset .iloc [0 , 0 ] = 0
36
37
37
38
assert not np .shares_memory (get_array (subset , "a" ), get_array (df , "a" ))
@@ -80,7 +81,7 @@ def test_subset_row_slice(using_copy_on_write):
80
81
else :
81
82
# INFO this no longer raise warning since pandas 1.4
82
83
# with pd.option_context("chained_assignment", "warn"):
83
- # with tm.assert_produces_warning(com. SettingWithCopyWarning):
84
+ # with tm.assert_produces_warning(SettingWithCopyWarning):
84
85
subset .iloc [0 , 0 ] = 0
85
86
86
87
subset ._mgr ._verify_integrity ()
@@ -119,7 +120,7 @@ def test_subset_column_slice(using_copy_on_write, using_array_manager, dtype):
119
120
120
121
else :
121
122
# we only get a warning in case of a single block
122
- warn = com . SettingWithCopyWarning if single_block else None
123
+ warn = SettingWithCopyWarning if single_block else None
123
124
with pd .option_context ("chained_assignment" , "warn" ):
124
125
with tm .assert_produces_warning (warn ):
125
126
subset .iloc [0 , 0 ] = 0
@@ -252,7 +253,7 @@ def test_subset_set_with_row_indexer(indexer_si, indexer, using_copy_on_write):
252
253
indexer_si (subset )[indexer ] = 0
253
254
else :
254
255
# INFO iloc no longer raises warning since pandas 1.4
255
- warn = com . SettingWithCopyWarning if indexer_si is tm .setitem else None
256
+ warn = SettingWithCopyWarning if indexer_si is tm .setitem else None
256
257
with pd .option_context ("chained_assignment" , "warn" ):
257
258
with tm .assert_produces_warning (warn ):
258
259
indexer_si (subset )[indexer ] = 0
@@ -282,7 +283,7 @@ def test_subset_set_with_mask(using_copy_on_write):
282
283
subset [mask ] = 0
283
284
else :
284
285
with pd .option_context ("chained_assignment" , "warn" ):
285
- with tm .assert_produces_warning (com . SettingWithCopyWarning ):
286
+ with tm .assert_produces_warning (SettingWithCopyWarning ):
286
287
subset [mask ] = 0
287
288
288
289
expected = DataFrame (
@@ -309,7 +310,7 @@ def test_subset_set_column(using_copy_on_write):
309
310
subset ["a" ] = np .array ([10 , 11 ], dtype = "int64" )
310
311
else :
311
312
with pd .option_context ("chained_assignment" , "warn" ):
312
- with tm .assert_produces_warning (com . SettingWithCopyWarning ):
313
+ with tm .assert_produces_warning (SettingWithCopyWarning ):
313
314
subset ["a" ] = np .array ([10 , 11 ], dtype = "int64" )
314
315
315
316
subset ._mgr ._verify_integrity ()
@@ -340,7 +341,7 @@ def test_subset_set_column_with_loc(using_copy_on_write, using_array_manager, dt
340
341
# warnings and only assert the SettingWithCopyWarning
341
342
raise_on_extra_warnings = False if using_array_manager else True
342
343
with tm .assert_produces_warning (
343
- com . SettingWithCopyWarning ,
344
+ SettingWithCopyWarning ,
344
345
raise_on_extra_warnings = raise_on_extra_warnings ,
345
346
):
346
347
subset .loc [:, "a" ] = np .array ([10 , 11 ], dtype = "int64" )
@@ -377,7 +378,7 @@ def test_subset_set_column_with_loc2(using_copy_on_write, using_array_manager):
377
378
# warnings and only assert the SettingWithCopyWarning
378
379
raise_on_extra_warnings = False if using_array_manager else True
379
380
with tm .assert_produces_warning (
380
- com . SettingWithCopyWarning ,
381
+ SettingWithCopyWarning ,
381
382
raise_on_extra_warnings = raise_on_extra_warnings ,
382
383
):
383
384
subset .loc [:, "a" ] = 0
@@ -410,7 +411,7 @@ def test_subset_set_columns(using_copy_on_write, dtype):
410
411
subset [["a" , "c" ]] = 0
411
412
else :
412
413
with pd .option_context ("chained_assignment" , "warn" ):
413
- with tm .assert_produces_warning (com . SettingWithCopyWarning ):
414
+ with tm .assert_produces_warning (SettingWithCopyWarning ):
414
415
subset [["a" , "c" ]] = 0
415
416
416
417
subset ._mgr ._verify_integrity ()
@@ -443,7 +444,7 @@ def test_subset_set_with_column_indexer(
443
444
# The (i)loc[:, col] inplace deprecation gets triggered here, ignore those
444
445
# warnings and only assert the SettingWithCopyWarning
445
446
with tm .assert_produces_warning (
446
- com . SettingWithCopyWarning , raise_on_extra_warnings = False
447
+ SettingWithCopyWarning , raise_on_extra_warnings = False
447
448
):
448
449
subset .loc [:, indexer ] = 0
449
450
@@ -580,7 +581,7 @@ def test_column_as_series(using_copy_on_write, using_array_manager):
580
581
s [0 ] = 0
581
582
else :
582
583
with pd .option_context ("chained_assignment" , "warn" ):
583
- with tm .assert_produces_warning (com . SettingWithCopyWarning ):
584
+ with tm .assert_produces_warning (SettingWithCopyWarning ):
584
585
s [0 ] = 0
585
586
586
587
expected = Series ([0 , 2 , 3 ], name = "a" )
@@ -607,7 +608,7 @@ def test_column_as_series_set_with_upcast(using_copy_on_write, using_array_manag
607
608
s [0 ] = "foo"
608
609
else :
609
610
with pd .option_context ("chained_assignment" , "warn" ):
610
- with tm .assert_produces_warning (com . SettingWithCopyWarning ):
611
+ with tm .assert_produces_warning (SettingWithCopyWarning ):
611
612
s [0 ] = "foo"
612
613
613
614
expected = Series (["foo" , 2 , 3 ], dtype = object , name = "a" )
0 commit comments