{"record":{"id":"3d90f33530216e97","repo":"pandas-dev/pandas","slug":"encountered-an-na-value-with-skipna-false-3d90f3","errorCode":null,"errorMessage":"Encountered an NA value with skipna=False","messagePattern":"Encountered an NA value with skipna=False","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/base.py","lineNumber":1152,"sourceCode":"        int\n\n        See Also\n        --------\n        ExtensionArray.argmax : Return the index of the maximum value.\n\n        Examples\n        --------\n        >>> arr = pd.array([3, 1, 2, 5, 4])\n        >>> arr.argmin()\n        np.int64(1)\n        \"\"\"\n        # Implementer note: You have two places to override the behavior of\n        # argmin.\n        # 1. _values_for_argsort : construct the values used in nargminmax\n        # 2. argmin itself : total control over sorting.\n        validate_bool_kwarg(skipna, \"skipna\")\n        if not skipna and self._hasna:\n            raise ValueError(\"Encountered an NA value with skipna=False\")\n        return cast(\"int\", nargminmax(self, \"argmin\"))\n\n    def argmax(self, skipna: bool = True) -> int:\n        \"\"\"\n        Return the index of maximum value.\n\n        In case of multiple occurrences of the maximum value, the index\n        corresponding to the first occurrence is returned.\n\n        Parameters\n        ----------\n        skipna : bool, default True\n\n        Returns\n        -------\n        int\n\n        See Also","sourceCodeStart":1134,"sourceCodeEnd":1170,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/base.py#L1134-L1170","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Drop or fill NAs before calling: arr[~arr.isna()].argmin() or arr.fillna(...).argmin().","Pass skipna=True (the default) if skipping NAs is acceptable.","Guard the call: if not arr.isna().any(): arr.argmin(skipna=False)."],"exampleFix":"// before\nidx = series.argmin(skipna=False)  # ValueError if NA present\n\n// after\nidx = series.dropna().argmin(skipna=False)\n# or, if skipping is acceptable\nidx = series.argmin(skipna=True)","handlingStrategy":"validation","validationCode":"if skipna is False and bool(getattr(arr, '_hasna', arr.isna().any())):\n    raise ValueError('cannot argmin with skipna=False over NA-containing data')\nidx = arr.argmin(skipna=skipna)","typeGuard":null,"tryCatchPattern":"try:\n    idx = series.argmin(skipna=False)\nexcept ValueError:\n    idx = series.dropna().argmin(skipna=False)","preventionTips":["Drop or fill NAs before argmin(skipna=False).","Default skipna=True skips NAs safely.","Pre-check series.hasnans before passing skipna=False."],"tags":["extension-array","missing-data","value-error","pandas"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}