Skip to content

Commit c2d0291

Browse files
authored
BUG: df.iloc[ndarray, ndarray] = 2dvals raising with EA column (#44714)
1 parent cedbefe commit c2d0291

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

doc/source/whatsnew/v1.4.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ Indexing
715715
- Bug in :meth:`DataFrame.loc.__setitem__` and :meth:`DataFrame.iloc.__setitem__` with mixed dtypes sometimes failing to operate in-place (:issue:`44345`)
716716
- Bug in :meth:`DataFrame.loc.__getitem__` incorrectly raising ``KeyError`` when selecting a single column with a boolean key (:issue:`44322`).
717717
- Bug in setting :meth:`DataFrame.iloc` with a single ``ExtensionDtype`` column and setting 2D values e.g. ``df.iloc[:] = df.values`` incorrectly raising (:issue:`44514`)
718+
- Bug in setting values with :meth:`DataFrame.iloc` with a single ``ExtensionDtype`` column and a tuple of arrays as the indexer (:issue:`44703`)
718719
- Bug in indexing on columns with ``loc`` or ``iloc`` using a slice with a negative step with ``ExtensionDtype`` columns incorrectly raising (:issue:`44551`)
719720
- Bug in :meth:`DataFrame.loc.__setitem__` changing dtype when indexer was completely ``False`` (:issue:`37550`)
720721
- Bug in :meth:`IntervalIndex.get_indexer_non_unique` returning boolean mask instead of array of integers for a non unique and non monotonic index (:issue:`44084`)

pandas/core/internals/blocks.py

+8
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,14 @@ def setitem(self, indexer, value):
15121512
# TODO(EA2D): not needed with 2D EAs
15131513
# we are always 1-D
15141514
indexer = indexer[0]
1515+
if isinstance(indexer, np.ndarray) and indexer.ndim == 2:
1516+
# GH#44703
1517+
if indexer.shape[1] != 1:
1518+
raise NotImplementedError(
1519+
"This should not be reached. Please report a bug at "
1520+
"github.com/pandas-dev/pandas/"
1521+
)
1522+
indexer = indexer[:, 0]
15151523

15161524
# TODO(EA2D): not needed with 2D EAS
15171525
if isinstance(value, (np.ndarray, ExtensionArray)) and value.ndim == 2:

pandas/tests/indexing/test_iloc.py

+8
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,14 @@ def test_iloc_getitem_slice_negative_step_ea_block(self):
11571157
expected = DataFrame({"B": df["B"], "A": df["A"]})
11581158
tm.assert_frame_equal(res, expected)
11591159

1160+
def test_iloc_setitem_2d_ndarray_into_ea_block(self):
1161+
# GH#44703
1162+
df = DataFrame({"status": ["a", "b", "c"]}, dtype="category")
1163+
df.iloc[np.array([0, 1]), np.array([0])] = np.array([["a"], ["a"]])
1164+
1165+
expected = DataFrame({"status": ["a", "a", "c"]}, dtype=df["status"].dtype)
1166+
tm.assert_frame_equal(df, expected)
1167+
11601168

11611169
class TestILocErrors:
11621170
# NB: this test should work for _any_ Series we can pass as

0 commit comments

Comments
 (0)