pandas-dev/pandas · error · ValueError
Encountered an NA value with skipna=False
Error message
Encountered an NA value with skipna=False
What it means
`ValueError` from `NDArrayBackedExtensionArray.argmin` when `skipna=False` and the backing ndarray contains NA. pandas refuses to pick a 'minimum' position when an NA is present and the user explicitly opted out of skipping NAs, because the result would be ambiguous. The check uses `self._hasna` (a cheap cache) before dispatching to the cython `nargminmax`.
Solutions
- Pass `skipna=True` (the default) to ignore NA values: `s.argmin(skipna=True)`.
- Drop or fill NA before computing: `s.dropna().argmin()` or `s.fillna(...).argmin()`.
- If you truly need skipna=False, first assert the data has no NA: `if s.isna().any(): raise ...` so the failure is intentional and explained.
Example fix
// before pos = s.argmin(skipna=False) # s has NA -> ValueError // after pos = s.argmin(skipna=True) # or pos = s.dropna().argmin()
Defensive patterns
Strategy: validation
Validate before calling
if not skipna and s.isna().any():
raise ValueError('cannot compute argmin(skipna=False) with NA present')
pos = s.argmin(skipna=skipna) Type guard
def safe_for_argmin_no_skipna(s) -> bool:
return not s.isna().any() Try / catch
try:
pos = s.argmin(skipna=False)
except ValueError as e:
if 'skipna=False' in str(e):
pos = s.dropna().argmin()
else:
raise Prevention
- Default to skipna=True
- Drop or fill NA before computing reductions if you need NA-aware code
When it happens
Trigger: `Series.argmin(skipna=False)` or `DataFrame.idxmin(skipna=False)` on a nullable-backed (IntegerArray/Float64Array/ArrowExtensionArray/etc.) Series or frame that contains NA, when the underlying array is an `NDArrayBackedExtensionArray`. Also `np.argmin`-style internal calls routed through this method.
Common situations: Calling `idxmin`/`argmin` with `skipna=False` on real-world data containing nulls; switching from numpy-backed to nullable or Arrow dtypes where `_hasna` becomes true; assert-style code that expects a deterministic minimum on incomplete data.
Related errors
- Cannot cast NaN value to Integer dtype.
- `axis` must be fewer than the number of dimensions
- cannot convert float NaN to integer
- Cannot mask with non-boolean array containing NA / NaN…
- cannot pass mask for BooleanArray input
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/c70985c75434c066.
Report an issue: GitHub.
Appendix: source
Thrown at pandas/core/arrays/_mixins.py:220
) -> npt.NDArray[np.uint64]:
from pandas.core.util.hashing import hash_array
values = self._ndarray
return hash_array(
values, encoding=encoding, hash_key=hash_key, categorize=categorize
)
def _cast_pointwise_result(self, values: ArrayLike) -> ArrayLike:
if not (isinstance(values, np.ndarray) and values.dtype == object):
values = construct_1d_object_array_from_listlike(values) # type: ignore[arg-type]
return lib.maybe_convert_objects(values, convert_non_numeric=True)
# Signature of "argmin" incompatible with supertype "ExtensionArray"
def argmin(self, axis: AxisInt = 0, skipna: bool = True): # type: ignore[override]
# override base class by adding axis keyword
validate_bool_kwarg(skipna, "skipna")
if not skipna and self._hasna:
raise ValueError("Encountered an NA value with skipna=False")
return nargminmax(self, "argmin", axis=axis)
# Signature of "argmax" incompatible with supertype "ExtensionArray"
def argmax(self, axis: AxisInt = 0, skipna: bool = True): # type: ignore[override]
# override base class by adding axis keyword
validate_bool_kwarg(skipna, "skipna")
if not skipna and self._hasna:
raise ValueError("Encountered an NA value with skipna=False")
return nargminmax(self, "argmax", axis=axis)
def unique(self) -> Self:
new_data = unique(self._ndarray)
return self._from_backing_data(new_data)
def sort(
self,
*,
ascending: bool = True,View on GitHub (pinned to 3b7651241d)