diff --git a/pandas/core/arrays/numeric.py b/pandas/core/arrays/numeric.py index 2829d092ebba4..2c55906dafd6e 100644 --- a/pandas/core/arrays/numeric.py +++ b/pandas/core/arrays/numeric.py @@ -28,6 +28,7 @@ BaseMaskedArray, BaseMaskedDtype, ) +from pandas.core.construction import extract_array if TYPE_CHECKING: from collections.abc import ( @@ -139,7 +140,10 @@ def _safe_cast(cls, values: np.ndarray, dtype: np.dtype, copy: bool) -> np.ndarr raise AbstractMethodError(cls) -def _coerce_to_data_and_mask(values, dtype, copy: bool, dtype_cls: type[NumericDtype]): +def _coerce_to_data_and_mask( + values, dtype, copy: bool, dtype_cls: type[NumericDtype], default_dtype: np.dtype +): + values = extract_array(values, extract_numpy=True) checker = dtype_cls._checker default_dtype = dtype_cls._default_np_dtype diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py index ddb58ecbfa6f3..88856418cb531 100644 --- a/pandas/tests/indexing/test_iloc.py +++ b/pandas/tests/indexing/test_iloc.py @@ -1090,6 +1090,25 @@ def test_iloc_setitem_pure_position_based(self, indexer, has_ref): expected = DataFrame({"a": [1, 2, 3], "b": [11, 12, 13], "c": [7, 8, 9]}) tm.assert_frame_equal(df2, expected) + def test_iloc_assignment_nullable_int_with_na(self): + # GH#62473 + ser = Series( + [4, 6, 9, None, 10, 13, 15], index=[6, 1, 5, 0, 3, 2, 4], dtype="Int64" + ) + indices = Series( + [6, 1, 5, 0, 3, 2, 4], index=[6, 1, 5, 0, 3, 2, 4], dtype="int64" + ) + values = Series( + [4, 6, 9, None, 10, 13, 15], index=[4, 1, 2, 6, 0, 5, 3], dtype="Int64" + ) + + ser.iloc[indices] = values + + expected = Series( + [NA, 6, 13, 10, 15, 9, 4], index=[6, 1, 5, 0, 3, 2, 4], dtype="Int64" + ) + tm.assert_series_equal(ser, expected) + @pytest.mark.parametrize("has_ref", [True, False]) def test_iloc_setitem_dictionary_value(self, has_ref): # GH#37728