pandas-dev/pandas · error · TypeError

FloatingArray does not support np.float16 dtype.

Error message

FloatingArray does not support np.float16 dtype.

What it means

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.

Solutions

  1. Upcast to float32 or float64 before wrapping: values.astype(np.float64).
  2. Use pd.array(values, dtype='Float32') which coerces through the standard path.
  3. Keep float16 data in a plain numpy array or a numpy-backed Series instead of a FloatingArray.

Example fix

# before
pd.arrays.FloatingArray(np.array([1.0], dtype=np.float16), mask=np.zeros(1, bool))  # raises

# after
pd.arrays.FloatingArray(np.array([1.0], dtype=np.float16).astype(np.float32), mask=np.zeros(1, bool))
Defensive patterns

Strategy: validation

Validate before calling

import numpy as np

def to_float_array(values):
    arr = np.asarray(values)
    if arr.dtype == np.float16:
        arr = arr.astype(np.float32)
    return arr

Type guard

def is_supported_float_dtype(values) -> bool:
    import numpy as np
    dt = np.asarray(values).dtype
    return dt.kind == 'f' and dt != np.float16

Try / catch

try:
    pd.arrays.FloatingArray(values, mask)
except TypeError as e:
    if 'float16' in str(e):
        values = np.asarray(values, dtype=np.float32)
        pd.arrays.FloatingArray(values, mask)
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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

Appendix: source

Thrown at pandas/core/arrays/numeric.py:275

    _dtype_cls: type[NumericDtype]

    def __init__(
        self, values: np.ndarray, mask: npt.NDArray[np.bool_], copy: bool = False
    ) -> None:
        checker = self._dtype_cls._checker
        if not (isinstance(values, np.ndarray) and checker(values.dtype)):
            descr = (
                "floating"
                if self._dtype_cls.kind == "f"  # type: ignore[comparison-overlap]
                else "integer"
            )
            raise TypeError(
                f"values should be {descr} numpy array. Use "
                "the 'pd.array' function instead"
            )
        if values.dtype == np.float16:
            # If we don't raise here, then accessing self.dtype would raise
            raise TypeError("FloatingArray does not support np.float16 dtype.")

        # NB: if is_nan_na() is True
        #  then caller is responsible for ensuring
        #  assert mask[np.isnan(values)].all()

        super().__init__(values, mask, copy=copy)

    @cache_readonly
    def dtype(self) -> NumericDtype:
        mapping = self._dtype_cls._get_dtype_mapping()
        return mapping[self._data.dtype]

    @classmethod
    def _coerce_to_array(
        cls, value, *, dtype: DtypeObj, copy: bool = False
    ) -> tuple[np.ndarray, np.ndarray]:
        dtype_cls = cls._dtype_cls
        values, mask = _coerce_to_data_and_mask(value, dtype, copy, dtype_cls)

View on GitHub (pinned to 3b7651241d)