pandas-dev/pandas · error · ValueError

Encountered an NA value with skipna=False

Error message

Encountered an NA value with skipna=False

What it means

argmin() refuses to silently skip NA values when the caller passed skipna=False. It first validates skipna is a bool, then checks self._hasna; if NAs are present and the user explicitly asked not to skip them, raising ValueError is the data-integrity-preserving choice (returning an index would imply a well-defined min over data containing NA).

Solutions

  1. Drop or fill NAs before calling: arr[~arr.isna()].argmin() or arr.fillna(...).argmin().
  2. Pass skipna=True (the default) if skipping NAs is acceptable.
  3. Guard the call: if not arr.isna().any(): arr.argmin(skipna=False).

Example fix

// before
idx = series.argmin(skipna=False)  # ValueError if NA present

// after
idx = series.dropna().argmin(skipna=False)
# or, if skipping is acceptable
idx = series.argmin(skipna=True)
Defensive patterns

Strategy: validation

Validate before calling

if skipna is False and bool(getattr(arr, '_hasna', arr.isna().any())):
    raise ValueError('cannot argmin with skipna=False over NA-containing data')
idx = arr.argmin(skipna=skipna)

Try / catch

try:
    idx = series.argmin(skipna=False)
except ValueError:
    idx = series.dropna().argmin(skipna=False)

Prevention

When it happens

Trigger: Calling arr.argmin(skipna=False) or Series.argmin(skipna=False)/idxmin() on a Series backed by an EA that contains at least one NA. Also reached via df.idxmin() when the column has NA and the internal call passes skipna=False.

Common situations: Passing skipna=False to honor missing data, then hitting a column with NAs. Aggregation pipelines that propagate skipna=False from a global config. Calling idxmin on a filtered subset that unexpectedly retained NAs.

Related errors


AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11). Data as JSON: /api/errors/3d90f33530216e97. Report an issue: GitHub.

Appendix: source

Thrown at pandas/core/arrays/base.py:1152

        int

        See Also
        --------
        ExtensionArray.argmax : Return the index of the maximum value.

        Examples
        --------
        >>> arr = pd.array([3, 1, 2, 5, 4])
        >>> arr.argmin()
        np.int64(1)
        """
        # Implementer note: You have two places to override the behavior of
        # argmin.
        # 1. _values_for_argsort : construct the values used in nargminmax
        # 2. argmin itself : total control over sorting.
        validate_bool_kwarg(skipna, "skipna")
        if not skipna and self._hasna:
            raise ValueError("Encountered an NA value with skipna=False")
        return cast("int", nargminmax(self, "argmin"))

    def argmax(self, skipna: bool = True) -> int:
        """
        Return the index of maximum value.

        In case of multiple occurrences of the maximum value, the index
        corresponding to the first occurrence is returned.

        Parameters
        ----------
        skipna : bool, default True

        Returns
        -------
        int

        See Also

View on GitHub (pinned to 3b7651241d)