@@ -177,7 +177,10 @@ def test_setitem_dtype_upcast(self):
177
177
df ["c" ] = np .nan
178
178
assert df ["c" ].dtype == np .float64
179
179
180
- df .loc [0 , "c" ] = "foo"
180
+ with tm .assert_produces_warning (
181
+ FutureWarning , match = "item of incompatible dtype"
182
+ ):
183
+ df .loc [0 , "c" ] = "foo"
181
184
expected = DataFrame (
182
185
[{"a" : 1 , "b" : np .nan , "c" : "foo" }, {"a" : 3 , "b" : 2 , "c" : np .nan }]
183
186
)
@@ -194,7 +197,10 @@ def test_setitem_dtype_upcast2(self, val):
194
197
)
195
198
196
199
left = df .copy ()
197
- left .loc ["a" , "bar" ] = val
200
+ with tm .assert_produces_warning (
201
+ FutureWarning , match = "item of incompatible dtype"
202
+ ):
203
+ left .loc ["a" , "bar" ] = val
198
204
right = DataFrame (
199
205
[[0 , val , 2 ], [3 , 4 , 5 ]],
200
206
index = list ("ab" ),
@@ -211,7 +217,10 @@ def test_setitem_dtype_upcast3(self):
211
217
index = list ("ab" ),
212
218
columns = ["foo" , "bar" , "baz" ],
213
219
)
214
- left .loc ["a" , "bar" ] = "wxyz"
220
+ with tm .assert_produces_warning (
221
+ FutureWarning , match = "item of incompatible dtype"
222
+ ):
223
+ left .loc ["a" , "bar" ] = "wxyz"
215
224
216
225
right = DataFrame (
217
226
[[0 , "wxyz" , 0.2 ], [0.3 , 0.4 , 0.5 ]],
@@ -455,7 +464,10 @@ def test_multi_assign(self):
455
464
cols = ["col1" , "col2" ]
456
465
457
466
dft = df2 * 2
458
- dft .iloc [3 , 3 ] = np .nan
467
+ with tm .assert_produces_warning (
468
+ FutureWarning , match = "item of incompatible dtype"
469
+ ):
470
+ dft .iloc [3 , 3 ] = np .nan
459
471
460
472
expected = DataFrame (
461
473
{
@@ -467,7 +479,10 @@ def test_multi_assign(self):
467
479
)
468
480
469
481
# frame on rhs
470
- df2 .loc [mask , cols ] = dft .loc [mask , cols ]
482
+ with tm .assert_produces_warning (
483
+ FutureWarning , match = "item of incompatible dtype"
484
+ ):
485
+ df2 .loc [mask , cols ] = dft .loc [mask , cols ]
471
486
tm .assert_frame_equal (df2 , expected )
472
487
473
488
# with an ndarray on rhs
@@ -482,7 +497,10 @@ def test_multi_assign(self):
482
497
}
483
498
)
484
499
df2 = df .copy ()
485
- df2 .loc [mask , cols ] = dft .loc [mask , cols ].values
500
+ with tm .assert_produces_warning (
501
+ FutureWarning , match = "item of incompatible dtype"
502
+ ):
503
+ df2 .loc [mask , cols ] = dft .loc [mask , cols ].values
486
504
tm .assert_frame_equal (df2 , expected )
487
505
488
506
def test_multi_assign_broadcasting_rhs (self ):
@@ -659,6 +677,7 @@ def test_loc_setitem_fullindex_views(self):
659
677
df .loc [df .index ] = df .loc [df .index ]
660
678
tm .assert_frame_equal (df , df2 )
661
679
680
+ @pytest .mark .filterwarnings ("ignore:.*item of incompatible dtype.*:FutureWarning" )
662
681
def test_rhs_alignment (self ):
663
682
# GH8258, tests that both rows & columns are aligned to what is
664
683
# assigned to. covers both uniform data-type & multi-type cases
@@ -808,6 +827,7 @@ class TestDataframeNoneCoercion:
808
827
]
809
828
810
829
@pytest .mark .parametrize ("expected" , EXPECTED_SINGLE_ROW_RESULTS )
830
+ @pytest .mark .filterwarnings ("ignore:.*item of incompatible dtype.*:FutureWarning" )
811
831
def test_coercion_with_loc (self , expected ):
812
832
start_data , expected_result = expected
813
833
@@ -818,6 +838,7 @@ def test_coercion_with_loc(self, expected):
818
838
tm .assert_frame_equal (start_dataframe , expected_dataframe )
819
839
820
840
@pytest .mark .parametrize ("expected" , EXPECTED_SINGLE_ROW_RESULTS )
841
+ @pytest .mark .filterwarnings ("ignore:.*item of incompatible dtype.*:FutureWarning" )
821
842
def test_coercion_with_setitem_and_dataframe (self , expected ):
822
843
start_data , expected_result = expected
823
844
@@ -828,6 +849,7 @@ def test_coercion_with_setitem_and_dataframe(self, expected):
828
849
tm .assert_frame_equal (start_dataframe , expected_dataframe )
829
850
830
851
@pytest .mark .parametrize ("expected" , EXPECTED_SINGLE_ROW_RESULTS )
852
+ @pytest .mark .filterwarnings ("ignore:.*item of incompatible dtype.*:FutureWarning" )
831
853
def test_none_coercion_loc_and_dataframe (self , expected ):
832
854
start_data , expected_result = expected
833
855
0 commit comments