{"record":{"id":"c6d1c3406bb03286","repo":"pandas-dev/pandas","slug":"floatingarray-does-not-support-np-float16-dtype","errorCode":null,"errorMessage":"FloatingArray does not support np.float16 dtype.","messagePattern":"FloatingArray does not support np\\.float16 dtype\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/numeric.py","lineNumber":275,"sourceCode":"    _dtype_cls: type[NumericDtype]\n\n    def __init__(\n        self, values: np.ndarray, mask: npt.NDArray[np.bool_], copy: bool = False\n    ) -> None:\n        checker = self._dtype_cls._checker\n        if not (isinstance(values, np.ndarray) and checker(values.dtype)):\n            descr = (\n                \"floating\"\n                if self._dtype_cls.kind == \"f\"  # type: ignore[comparison-overlap]\n                else \"integer\"\n            )\n            raise TypeError(\n                f\"values should be {descr} numpy array. Use \"\n                \"the 'pd.array' function instead\"\n            )\n        if values.dtype == np.float16:\n            # If we don't raise here, then accessing self.dtype would raise\n            raise TypeError(\"FloatingArray does not support np.float16 dtype.\")\n\n        # NB: if is_nan_na() is True\n        #  then caller is responsible for ensuring\n        #  assert mask[np.isnan(values)].all()\n\n        super().__init__(values, mask, copy=copy)\n\n    @cache_readonly\n    def dtype(self) -> NumericDtype:\n        mapping = self._dtype_cls._get_dtype_mapping()\n        return mapping[self._data.dtype]\n\n    @classmethod\n    def _coerce_to_array(\n        cls, value, *, dtype: DtypeObj, copy: bool = False\n    ) -> tuple[np.ndarray, np.ndarray]:\n        dtype_cls = cls._dtype_cls\n        values, mask = _coerce_to_data_and_mask(value, dtype, copy, dtype_cls)","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/numeric.py#L257-L293","documentation":"Raised by NumericArray.__init__ specifically when values.dtype == np.float16. Although float16 is a floating dtype and passes the _checker, FloatingArray maps numpy float types to Float32/Float64 only; the dtype-mapping lookup in NumericArray.dtype would otherwise fail later, so pandas fails fast here with an explicit, actionable message. float16 has limited precision and no Float16Dtype.","triggerScenarios":"pd.arrays.FloatingArray(np.array([1.0], dtype=np.float16), mask=...) ; or pd.array(values, dtype='Float64') where the underlying numpy array was upcast incorrectly and float16 leaked through an internal path. Also when a user manually builds a float16 ndarray and calls the constructor.","commonSituations":"Memory-constrained pipelines that downcast to float16 upstream and then try to wrap in a nullable floating extension array; Arrow import paths that materialize float16.","solutions":["Upcast to float32 or float64 before wrapping: values.astype(np.float64).","Use pd.array(values, dtype='Float32') which coerces through the standard path.","Keep float16 data in a plain numpy array or a numpy-backed Series instead of a FloatingArray."],"exampleFix":"# before\npd.arrays.FloatingArray(np.array([1.0], dtype=np.float16), mask=np.zeros(1, bool))  # raises\n\n# after\npd.arrays.FloatingArray(np.array([1.0], dtype=np.float16).astype(np.float32), mask=np.zeros(1, bool))","handlingStrategy":"validation","validationCode":"import numpy as np\n\ndef to_float_array(values):\n    arr = np.asarray(values)\n    if arr.dtype == np.float16:\n        arr = arr.astype(np.float32)\n    return arr","typeGuard":"def is_supported_float_dtype(values) -> bool:\n    import numpy as np\n    dt = np.asarray(values).dtype\n    return dt.kind == 'f' and dt != np.float16","tryCatchPattern":"try:\n    pd.arrays.FloatingArray(values, mask)\nexcept TypeError as e:\n    if 'float16' in str(e):\n        values = np.asarray(values, dtype=np.float32)\n        pd.arrays.FloatingArray(values, mask)\n    else:\n        raise","preventionTips":["Avoid float16 in pandas pipelines; upcast to float32/float64 at ingestion.","If memory budget forces float16, keep it in raw numpy, not in FloatingArray.","Validate dtype != float16 before constructing FloatingArray."],"tags":["pandas","masked-array","numeric","float16","dtype"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}