Skip to content

second approach to fix setitem parametrizations #57629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,9 @@ def setitem(self, indexer, value):

try:
values[indexer] = value
except (ValueError, TypeError):
except (ValueError, TypeError) as e:
if str(e) == "Cannot index with an integer indexer containing NA values":
raise
if isinstance(self.dtype, IntervalDtype):
# see TestSetitemFloatIntervalWithIntIntervalValues
nb = self.coerce_to_target_dtype(orig_value, warn_on_upcast=True)
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/extension/base/setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,24 +202,24 @@ def test_setitem_integer_array(self, data, idx, box_in_series):
arr[idx] = arr[0]
tm.assert_equal(arr, expected)

@pytest.mark.filterwarnings("ignore::FutureWarning")
@pytest.mark.parametrize(
"idx, box_in_series",
[
([0, 1, 2, pd.NA], False),
pytest.param(
[0, 1, 2, pd.NA], True, marks=pytest.mark.xfail(reason="GH-31948")
[0, 1, 2, pd.NA],
True,
marks=pytest.mark.xfail(reason="KeyError: '[0 1 2 <NA>] not in index'"),
),
(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
(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):
arr = data.copy()

# TODO(xfail) this raises KeyError about labels not found (it tries label-based)
# for list of labels with Series
if box_in_series:
arr = pd.Series(data, index=[chr(100 + i) for i in range(len(data))])

Expand Down