{"record":{"id":"92863d49a1049e80","repo":"pandas-dev/pandas","slug":"invalid-value-value-s-for-dtype-self-dtype","errorCode":null,"errorMessage":"Invalid value '{value!s}' for dtype '{self.dtype}'","messagePattern":"Invalid value '(.+?)' for dtype '(.+?)'","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/arrow/array.py","lineNumber":1740,"sourceCode":"            )\n\n        if limit is not None:\n            return super().fillna(value=value, limit=limit, copy=copy)\n\n        if isinstance(value, (np.ndarray, ExtensionArray)):\n            # Similar to check_value_size, but we do not mask here since we may\n            #  end up passing it to the super() method.\n            if len(value) != len(self):\n                raise ValueError(\n                    f\"Length of 'value' does not match. Got ({len(value)}) \"\n                    f\" expected {len(self)}\"\n                )\n\n        try:\n            fill_value = self._box_pa(value, pa_type=self._pa_array.type)\n        except pa.ArrowTypeError as err:\n            msg = f\"Invalid value '{value!s}' for dtype '{self.dtype}'\"\n            raise TypeError(msg) from err\n\n        try:\n            return self._from_pyarrow_array(\n                _safe_fill_null(self._pa_array, fill_value=fill_value)\n            )\n        except pa.ArrowNotImplementedError:\n            # ArrowNotImplementedError: Function 'coalesce' has no kernel\n            #   matching input types (duration[ns], duration[ns])\n            # TODO: remove try/except wrapper if/when pyarrow implements\n            #   a kernel for duration types.\n            pass\n\n        return super().fillna(value=value, limit=limit, copy=copy)\n\n    def isin(self, values: ArrayLike) -> npt.NDArray[np.bool_]:\n        # short-circuit to return all False array.\n        if not len(values):\n            return np.zeros(len(self), dtype=bool)","sourceCodeStart":1722,"sourceCodeEnd":1758,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/arrow/array.py#L1722-L1758","documentation":"Raised by ArrowExtensionArray.fillna when _box_pa (boxing `value` into a pyarrow scalar of the array's type) fails with pa.ArrowTypeError. This means the fill value is not castable to the array's dtype, e.g. filling a int64[pyarrow] array with a string, or filling a boolean array with a float like 1.5.","triggerScenarios":"arr.fillna('N/A') on an int64[pyarrow] array; boolean[pyarrow].fillna(1.5); filling a timestamp array with a plain string date; decimal[pyarrow].fillna(some_float) where the precision overflows.","commonSituations":"Loading data where NA sentinel strings ('', 'null') were not pre-converted; user-supplied default values typed incorrectly; filling temporal arrays with strings instead of Timestamp objects; decimal precision mismatches.","solutions":["Cast the fill value to match the array dtype: int value for int arrays, pd.Timestamp for timestamp arrays, etc.","Use pd.NA-aware construction so NA sentinels are recognized during parsing instead of fillna.","For sentinel strings, replace them with pd.NA first: s.replace('', pd.NA).","Validate fill value type against pa.types.* before calling fillna."],"exampleFix":"# before\narr = pd.array([1, None, 3], dtype=\"int64[pyarrow]\")\narr.fillna('missing')  # raises TypeError: Invalid value 'missing' for dtype 'int[pyarrow]'\n\n# after\narr.fillna(0)","handlingStrategy":"validation","validationCode":"import pyarrow as pa\n\ndef fill_value_for_dtype(value, arr):\n    try:\n        arr._box_pa(value, pa_type=arr._pa_array.type)\n    except pa.ArrowTypeError as e:\n        raise TypeError(f'Invalid value {value!r} for dtype {arr.dtype}') from e\n    return value","typeGuard":"import pyarrow as pa\n\ndef is_castable_to(value, arr) -> bool:\n    try:\n        arr._box_pa(value, pa_type=arr._pa_array.type)\n        return True\n    except pa.ArrowTypeError:\n        return False","tryCatchPattern":"try:\n    result = arr.fillna(value)\nexcept TypeError as e:\n    if 'Invalid value' in str(e):\n        # cast or pick a default matching the dtype\n        result = arr.fillna(0)  # or pd.Timestamp(0), etc.\n    else:\n        raise","preventionTips":["Match fill value type to the array dtype (int for int, Timestamp for timestamps).","Pre-convert sentinel strings ('', 'null') to pd.NA during parsing.","Validate castability with _box_pa before calling fillna."],"tags":["fillna","type-validation","dtype","pyarrow"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}