Skip to content

Commit 4caa8bc

Browse files
phoflnoatamir
authored andcommitted
BUG: iloc raising for ea and null slice and length one list (pandas-dev#48016)
* BUG: iloc raising for ea and null slice and length one list * BUG: iloc raising for ea and null slice and length one list * Parametrize tests
1 parent dfcbf09 commit 4caa8bc

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pandas/core/internals/blocks.py

+3
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,9 @@ def _unwrap_setitem_indexer(self, indexer):
17251725
elif com.is_null_slice(indexer[1]):
17261726
indexer = indexer[0]
17271727

1728+
elif is_list_like(indexer[1]) and indexer[1][0] == 0:
1729+
indexer = indexer[0]
1730+
17281731
else:
17291732
raise NotImplementedError(
17301733
"This should not be reached. Please report a bug at "

pandas/tests/frame/indexing/test_indexing.py

+8
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,14 @@ def test_iloc_setitem_string_na(self, val):
13631363
expected = DataFrame({"a": [pd.NA, "b", "c"]}, dtype="string")
13641364
tm.assert_frame_equal(df, expected)
13651365

1366+
@pytest.mark.parametrize("func", [list, Series, np.array])
1367+
def test_iloc_setitem_ea_null_slice_length_one_list(self, func):
1368+
# GH#48016
1369+
df = DataFrame({"a": [1, 2, 3]}, dtype="Int64")
1370+
df.iloc[:, func([0])] = 5
1371+
expected = DataFrame({"a": [5, 5, 5]}, dtype="Int64")
1372+
tm.assert_frame_equal(df, expected)
1373+
13661374

13671375
class TestDataFrameIndexingUInt64:
13681376
def test_setitem(self, uint64_frame):

0 commit comments

Comments
 (0)