diff --git a/pandas/tests/extension/base/setitem.py b/pandas/tests/extension/base/setitem.py index b273c9b9f092a..1265edb02dfa8 100644 --- a/pandas/tests/extension/base/setitem.py +++ b/pandas/tests/extension/base/setitem.py @@ -221,28 +221,28 @@ def test_setitem_integer_array_with_repeats(self, data, idx, box_in_series): tm.assert_equal(arr, expected) @pytest.mark.parametrize( - "idx, box_in_series", + "idx", [ - ([0, 1, 2, pd.NA], False), - pytest.param( - [0, 1, 2, pd.NA], True, marks=pytest.mark.xfail(reason="GH-31948") - ), - (pd.array([0, 1, 2, pd.NA], dtype="Int64"), False), - # TODO: change False to True? - (pd.array([0, 1, 2, pd.NA], dtype="Int64"), False), # noqa: PT014 + [0, 1, 2, pd.NA], + pd.array([0, 1, 2, pd.NA], dtype="Int64"), ], - ids=["list-False", "list-True", "integer-array-False", "integer-array-True"], + ids=["list", "integer-array"], ) + @pytest.mark.parametrize("box_in_series", [True, False]) def test_setitem_integer_with_missing_raises(self, data, idx, box_in_series): arr = data.copy() - # TODO(xfail) this raises KeyError about labels not found (it tries label-based) - # for list of labels with Series + msg = "Cannot index with an integer indexer containing NA values" + err = ValueError + if box_in_series: + # The integer labels are not present in the (string) index, so + # we get KeyErrors arr = pd.Series(data, index=[chr(100 + i) for i in range(len(data))]) + msg = "0" + err = KeyError - msg = "Cannot index with an integer indexer containing NA values" - with pytest.raises(ValueError, match=msg): + with pytest.raises(err, match=msg): arr[idx] = arr[0] @pytest.mark.parametrize("as_callable", [True, False]) diff --git a/pandas/tests/extension/json/test_json.py b/pandas/tests/extension/json/test_json.py index cdb98c5342ecb..aee9df47d6553 100644 --- a/pandas/tests/extension/json/test_json.py +++ b/pandas/tests/extension/json/test_json.py @@ -356,18 +356,25 @@ def test_setitem_integer_array(self, data, idx, box_in_series, request): request.applymarker(mark) super().test_setitem_integer_array(data, idx, box_in_series) - @pytest.mark.xfail(reason="list indices must be integers or slices, not NAType") @pytest.mark.parametrize( - "idx, box_in_series", + "idx", + [ + [0, 1, 2, pd.NA], + pd.array([0, 1, 2, pd.NA], dtype="Int64"), + ], + ids=["list", "integer-array"], + ) + @pytest.mark.parametrize( + "box_in_series", [ - ([0, 1, 2, pd.NA], False), + True, pytest.param( - [0, 1, 2, pd.NA], True, marks=pytest.mark.xfail(reason="GH-31948") + False, + marks=pytest.mark.xfail( + reason="list indices must be integers or slices, not NAType" + ), ), - (pd.array([0, 1, 2, pd.NA], dtype="Int64"), False), - (pd.array([0, 1, 2, pd.NA], dtype="Int64"), True), ], - ids=["list-False", "list-True", "integer-array-False", "integer-array-True"], ) def test_setitem_integer_with_missing_raises(self, data, idx, box_in_series): super().test_setitem_integer_with_missing_raises(data, idx, box_in_series)