Skip to content

Commit 7683563

Browse files
authored
BUG: DataFrame.setitem raising when rhs is ea dtype Series (#47425)
* BUG: DataFrame.setitem raising when rhs is ea dtype Series * Add gh ref
1 parent 963111d commit 7683563

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pandas/core/indexing.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,11 @@ def _setitem_single_column(self, loc: int, value, plane_indexer):
19771977
# We will not operate in-place, but will attempt to in the future.
19781978
# To determine whether we need to issue a FutureWarning, see if the
19791979
# setting in-place would work, i.e. behavior will change.
1980-
warn = can_hold_element(orig_values, value)
1980+
if isinstance(value, ABCSeries):
1981+
warn = can_hold_element(orig_values, value._values)
1982+
else:
1983+
warn = can_hold_element(orig_values, value)
1984+
19811985
# Don't issue the warning yet, as we can still trim a few cases where
19821986
# behavior will not change.
19831987

pandas/tests/frame/indexing/test_setitem.py

+7
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,13 @@ def test_boolean_mask_nullable_int64(self):
683683
)
684684
tm.assert_frame_equal(result, expected)
685685

686+
def test_setitem_ea_dtype_rhs_series(self):
687+
# GH#47425
688+
df = DataFrame({"a": [1, 2]})
689+
df["a"] = Series([1, 2], dtype="Int64")
690+
expected = DataFrame({"a": [1, 2]}, dtype="Int64")
691+
tm.assert_frame_equal(df, expected)
692+
686693
# TODO(ArrayManager) set column with 2d column array, see #44788
687694
@td.skip_array_manager_not_yet_implemented
688695
def test_setitem_npmatrix_2d(self):

0 commit comments

Comments
 (0)