Skip to content

Commit 02d22f3

Browse files
authored
BUG: isetitem coercing df columns to object (#50175)
* BUG: isetitem coercing df columns to object * Adjust test * Move to new file
1 parent 548444b commit 02d22f3

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

doc/source/whatsnew/v2.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ Indexing
879879
- Bug in :meth:`DataFrame.iloc` raising ``IndexError`` when indexer is a :class:`Series` with numeric extension array dtype (:issue:`49521`)
880880
- Bug in :func:`~DataFrame.describe` when formatting percentiles in the resulting index showed more decimals than needed (:issue:`46362`)
881881
- Bug in :meth:`DataFrame.compare` does not recognize differences when comparing ``NA`` with value in nullable dtypes (:issue:`48939`)
882+
- Bug in :meth:`DataFrame.isetitem` coercing extension array dtypes in :class:`DataFrame` to object (:issue:`49922`)
882883
-
883884

884885
Missing

pandas/core/frame.py

+9
Original file line numberDiff line numberDiff line change
@@ -3822,6 +3822,15 @@ def isetitem(self, loc, value) -> None:
38223822
In cases where `frame.columns` is unique, this is equivalent to
38233823
`frame[frame.columns[i]] = value`.
38243824
"""
3825+
if isinstance(value, DataFrame):
3826+
if is_scalar(loc):
3827+
loc = [loc]
3828+
3829+
for i, idx in enumerate(loc):
3830+
arraylike = self._sanitize_column(value.iloc[:, i])
3831+
self._iset_item_mgr(idx, arraylike, inplace=False)
3832+
return
3833+
38253834
arraylike = self._sanitize_column(value)
38263835
self._iset_item_mgr(loc, arraylike, inplace=False)
38273836

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from pandas import (
2+
DataFrame,
3+
Series,
4+
)
5+
import pandas._testing as tm
6+
7+
8+
class TestDataFrameSetItem:
9+
def test_isetitem_ea_df(self):
10+
# GH#49922
11+
df = DataFrame([[1, 2, 3], [4, 5, 6]])
12+
rhs = DataFrame([[11, 12], [13, 14]], dtype="Int64")
13+
14+
df.isetitem([0, 1], rhs)
15+
expected = DataFrame(
16+
{
17+
0: Series([11, 13], dtype="Int64"),
18+
1: Series([12, 14], dtype="Int64"),
19+
2: [3, 6],
20+
}
21+
)
22+
tm.assert_frame_equal(df, expected)
23+
24+
def test_isetitem_ea_df_scalar_indexer(self):
25+
# GH#49922
26+
df = DataFrame([[1, 2, 3], [4, 5, 6]])
27+
rhs = DataFrame([[11], [13]], dtype="Int64")
28+
29+
df.isetitem(2, rhs)
30+
expected = DataFrame(
31+
{
32+
0: [1, 4],
33+
1: [2, 5],
34+
2: Series([11, 13], dtype="Int64"),
35+
}
36+
)
37+
tm.assert_frame_equal(df, expected)

0 commit comments

Comments
 (0)