Skip to content
Merged
2 changes: 2 additions & 0 deletions pandas/core/arrays/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def _from_sequence(cls, scalars, *, dtype=None, copy: bool = False) -> Self:
return cls(values, mask)

def _cast_pointwise_result(self, values) -> ArrayLike:
if isna(values).all():
return type(self)._from_sequence(values, dtype=self.dtype)
values = np.asarray(values, dtype=object)
result = lib.maybe_convert_objects(values, convert_to_nullable_dtype=True)
lkind = self.dtype.kind
Expand Down
14 changes: 11 additions & 3 deletions pandas/tests/extension/test_masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,15 @@ def check_accumulate(self, ser: pd.Series, op_name: str, skipna: bool):
tm.assert_series_equal(result, expected)

def test_loc_setitem_with_expansion_preserves_ea_index_dtype(self, data, request):
if data.dtype.kind == "b":
mark = pytest.mark.xfail(reason="GH#62344 incorrectly casts to object")
request.applymarker(mark)
super().test_loc_setitem_with_expansion_preserves_ea_index_dtype(data)


@pytest.mark.parametrize(
"arr", [pd.array([True, False]), pd.array([1, 2]), pd.array([1.0, 2.0])]
)
def test_cast_pointwise_result_all_na_respects_original_dtype(arr):
# GH#62344
values = [pd.NA, pd.NA]
result = arr._cast_pointwise_result(values)
assert result.dtype == arr.dtype
assert all(x is pd.NA for x in result)
Loading