{"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":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/arrow/array.py","lineNumber":1715,"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":1697,"sourceCodeEnd":1733,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/arrow/array.py#L1697-L1733","documentation":"Raised by ArrowExtensionArray.fillna when the fill value cannot be boxed into the array's pyarrow type (pyarrow raises ArrowTypeError). pandas re-raises it as a TypeError so callers get a clear 'invalid value for dtype' message instead of a low-level pyarrow error.","triggerScenarios":"Calling `fillna(value)` on an ArrowExtensionArray where `value` is not convertible to `self._pa_array.type` — e.g. filling a `timestamp[us][pyarrow]` array with a plain string, or a `int32[pyarrow]` array with a float like 1.5 that would truncate.","commonSituations":"Loading data from JSON/CSV where fill constants come in as strings, mixing Python types across dtype migrations (e.g. default ints vs floats), or passing `pd.NA`/`None` where a concrete scalar is required.","solutions":["Cast the fill value to the array's pyarrow type explicitly before calling fillna: `value = pa.scalar(value, type=arr.dtype.pyarrow_dtype)`.","Use a value that matches the dtype's native Python representation (e.g. `pd.Timestamp` for timestamp arrays, `datetime.date` for date arrays).","If the array dtype is wrong, convert it with `.astype(...)` before filling."],"exampleFix":"// before\ns = pd.Series([1, None], dtype=\"timestamp[us][pyarrow]\")\ns.fillna(\"2020-01-01\")\n\n// after\ns.fillna(pd.Timestamp(\"2020-01-01\"))","handlingStrategy":"validation","validationCode":"import pyarrow as pa\n\ndef to_arrow_scalar(value, dtype):\n    pa_type = dtype.pyarrow_dtype if hasattr(dtype, \"pyarrow_dtype\") else None\n    try:\n        return pa.scalar(value, type=pa_type) if pa_type else pa.scalar(value)\n    except (pa.ArrowTypeError, pa.ArrowInvalid):\n        raise TypeError(f\"value {value!r} not valid for dtype {dtype}\")","typeGuard":"def is_valid_for_dtype(value, dtype) -> bool:\n    import pyarrow as pa\n    pa_type = getattr(dtype, \"pyarrow_dtype\", None)\n    try:\n        pa.scalar(value, type=pa_type) if pa_type else pa.scalar(value)\n        return True\n    except (pa.ArrowTypeError, pa.ArrowInvalid):\n        return False","tryCatchPattern":"try:\n    arr.fillna(value)\nexcept TypeError as e:\n    if \"Invalid value\" in str(e) and \"for dtype\" in str(e):\n        arr.fillna(arr.dtype.na_value)  # fall back to native NA\n    else:\n        raise","preventionTips":["Match fill constants to the dtype's native Python type (Timestamp for temporal, int for int dtypes).","Validate user-supplied fill constants against pa.scalar before passing them in.","Normalize incoming JSON/CSV strings to typed scalars during ingestion."],"tags":["arrow","fillna","type-coercion","dtype"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}