Skip to content

TST: Fix setitem parametrizations #56890

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 11 commits into from
7 changes: 6 additions & 1 deletion pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@
ensure_wrapped_if_datetimelike,
extract_array,
)
from pandas.core.indexers import check_setitem_lengths
from pandas.core.indexers import (
check_array_indexer,
check_setitem_lengths,
)
from pandas.core.indexes.base import get_values_for_csv

if TYPE_CHECKING:
Expand Down Expand Up @@ -1661,6 +1664,8 @@ def setitem(self, indexer, value):
# TODO(GH#45419): string[pyarrow] tests break if we transpose
# unconditionally
values = values.T

check_array_indexer(values, indexer)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check_setitem_lengths(indexer, value, values)

try:
Expand Down
12 changes: 6 additions & 6 deletions pandas/tests/extension/base/setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,9 @@ def test_setitem_integer_array(self, data, idx, box_in_series):
"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),
(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"],
)
Expand All @@ -225,7 +222,10 @@ def test_setitem_integer_with_missing_raises(self, data, idx, box_in_series):

msg = "Cannot index with an integer indexer containing NA values"
with pytest.raises(ValueError, match=msg):
arr[idx] = arr[0]
if type(arr) is pd.Series:
arr.iloc[idx] = arr.iloc[0]
else:
arr[idx] = arr[0]

@pytest.mark.parametrize("as_callable", [True, False])
@pytest.mark.parametrize("setter", ["loc", None])
Expand Down
17 changes: 13 additions & 4 deletions pandas/tests/extension/json/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,24 @@ 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",
[
([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],
False,
marks=pytest.mark.xfail(
reason="Cannot index with an integer indexer containing NA values"
),
),
([0, 1, 2, pd.NA], True),
pytest.param(
pd.array([0, 1, 2, pd.NA], dtype="Int64"),
False,
marks=pytest.mark.xfail(
reason="Cannot index with an integer indexer containing NA values"
),
),
(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"],
Expand Down