Skip to content

Commit 1cc3f50

Browse files
author
MarcoGorelli
committed
fixup test_indexing
1 parent 150fa9a commit 1cc3f50

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

pandas/tests/indexing/test_indexing.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ def test_setitem_dtype_upcast(self):
177177
df["c"] = np.nan
178178
assert df["c"].dtype == np.float64
179179

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"
181184
expected = DataFrame(
182185
[{"a": 1, "b": np.nan, "c": "foo"}, {"a": 3, "b": 2, "c": np.nan}]
183186
)
@@ -194,7 +197,10 @@ def test_setitem_dtype_upcast2(self, val):
194197
)
195198

196199
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
198204
right = DataFrame(
199205
[[0, val, 2], [3, 4, 5]],
200206
index=list("ab"),
@@ -211,7 +217,10 @@ def test_setitem_dtype_upcast3(self):
211217
index=list("ab"),
212218
columns=["foo", "bar", "baz"],
213219
)
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"
215224

216225
right = DataFrame(
217226
[[0, "wxyz", 0.2], [0.3, 0.4, 0.5]],
@@ -455,7 +464,10 @@ def test_multi_assign(self):
455464
cols = ["col1", "col2"]
456465

457466
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
459471

460472
expected = DataFrame(
461473
{
@@ -467,7 +479,10 @@ def test_multi_assign(self):
467479
)
468480

469481
# 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]
471486
tm.assert_frame_equal(df2, expected)
472487

473488
# with an ndarray on rhs
@@ -482,7 +497,10 @@ def test_multi_assign(self):
482497
}
483498
)
484499
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
486504
tm.assert_frame_equal(df2, expected)
487505

488506
def test_multi_assign_broadcasting_rhs(self):
@@ -659,6 +677,7 @@ def test_loc_setitem_fullindex_views(self):
659677
df.loc[df.index] = df.loc[df.index]
660678
tm.assert_frame_equal(df, df2)
661679

680+
@pytest.mark.filterwarnings("ignore:.*item of incompatible dtype.*:FutureWarning")
662681
def test_rhs_alignment(self):
663682
# GH8258, tests that both rows & columns are aligned to what is
664683
# assigned to. covers both uniform data-type & multi-type cases
@@ -808,6 +827,7 @@ class TestDataframeNoneCoercion:
808827
]
809828

810829
@pytest.mark.parametrize("expected", EXPECTED_SINGLE_ROW_RESULTS)
830+
@pytest.mark.filterwarnings("ignore:.*item of incompatible dtype.*:FutureWarning")
811831
def test_coercion_with_loc(self, expected):
812832
start_data, expected_result = expected
813833

@@ -818,6 +838,7 @@ def test_coercion_with_loc(self, expected):
818838
tm.assert_frame_equal(start_dataframe, expected_dataframe)
819839

820840
@pytest.mark.parametrize("expected", EXPECTED_SINGLE_ROW_RESULTS)
841+
@pytest.mark.filterwarnings("ignore:.*item of incompatible dtype.*:FutureWarning")
821842
def test_coercion_with_setitem_and_dataframe(self, expected):
822843
start_data, expected_result = expected
823844

@@ -828,6 +849,7 @@ def test_coercion_with_setitem_and_dataframe(self, expected):
828849
tm.assert_frame_equal(start_dataframe, expected_dataframe)
829850

830851
@pytest.mark.parametrize("expected", EXPECTED_SINGLE_ROW_RESULTS)
852+
@pytest.mark.filterwarnings("ignore:.*item of incompatible dtype.*:FutureWarning")
831853
def test_none_coercion_loc_and_dataframe(self, expected):
832854
start_data, expected_result = expected
833855

0 commit comments

Comments
 (0)