Skip to content

Commit bec4591

Browse files
committed
BUG: Fix boolean value of NA is ambiguous in iloc assignment
1 parent caa0fd3 commit bec4591

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

pandas/core/arrays/numeric.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
pandas_dtype,
2525
)
2626

27-
import pandas as pd
2827
from pandas.core.arrays.masked import (
2928
BaseMaskedArray,
3029
BaseMaskedDtype,
3130
)
31+
from pandas.core.construction import extract_array
3232

3333
if TYPE_CHECKING:
3434
from collections.abc import (
@@ -143,6 +143,7 @@ def _safe_cast(cls, values: np.ndarray, dtype: np.dtype, copy: bool) -> np.ndarr
143143
def _coerce_to_data_and_mask(
144144
values, dtype, copy: bool, dtype_cls: type[NumericDtype], default_dtype: np.dtype
145145
):
146+
values = extract_array(values, extract_numpy=True)
146147
checker = dtype_cls._checker
147148

148149
mask = None
@@ -232,17 +233,16 @@ def _coerce_to_data_and_mask(
232233
values = np.ones(values.shape, dtype=dtype)
233234
else:
234235
idx = np.nanargmax(values)
235-
if not (pd.isna(values[idx]) or pd.isna(original[idx])):
236-
if int(values[idx]) != original[idx]:
237-
# We have ints that lost precision during the cast.
238-
inferred_type = lib.infer_dtype(original, skipna=True)
239-
if (
240-
inferred_type not in ["floating", "mixed-integer-float"]
241-
and not mask.any()
242-
):
243-
values = np.asarray(original, dtype=dtype)
244-
else:
245-
values = np.asarray(original, dtype="object")
236+
if int(values[idx]) != original[idx]:
237+
# We have ints that lost precision during the cast.
238+
inferred_type = lib.infer_dtype(original, skipna=True)
239+
if (
240+
inferred_type not in ["floating", "mixed-integer-float"]
241+
and not mask.any()
242+
):
243+
values = np.asarray(original, dtype=dtype)
244+
else:
245+
values = np.asarray(original, dtype="object")
246246

247247
# we copy as need to coerce here
248248
if mask.any():

0 commit comments

Comments
 (0)