pandas-dev/pandas · error · TypeError

ExtensionArray.fillna does not support filling with a dict…

Error message

ExtensionArray.fillna does not support filling with a dict. Use Series.fillna instead.

What it means

Raised by `IntervalArray.fillna` when `value` is a dict. The ExtensionArray.fillna contract does not support dict-based filling (which maps per-index-label, requiring index information the array does not own); the user is redirected to Series.fillna which has an index.

Solutions

  1. Use Series.fillna with the dict: `s.fillna({0: ...})`.
  2. If you must work on the array, convert dict keys to positions and assign per-position with `__setitem__`.
  3. For a single fill value, pass a scalar Interval to `array.fillna`.

Example fix

# before
df['bins'].array.fillna({0: pd.Interval(0,1)})

# after
df['bins'].fillna({0: pd.Interval(0,1)})
# or scalar
arr.fillna(pd.Interval(0,1))
Defensive patterns

Strategy: type-guard

Validate before calling

import pandas as pd
from collections.abc import Mapping

def fillna_interval_array(arr, value):
    if isinstance(value, Mapping):
        raise TypeError('use Series.fillna for dict; array has no index')
    return arr.fillna(value)

Type guard

from collections.abc import Mapping

def is_dict_fill(value) -> bool:
    return isinstance(value, Mapping)

Try / catch

try:
    arr.fillna(value)
except TypeError as e:
    if 'does not support filling with a dict' in str(e):
        series.fillna(value)  # fall back to Series-level fill
    else:
        raise

Prevention

When it happens

Trigger: `interval_array.fillna({0: pd.Interval(0,1)})`; calling `.fillna` on `df['col'].array` with a dict.

Common situations: User copies a dict-based fillna pattern from a Series workflow onto the underlying array; extracting `.array` to avoid Series overhead then trying dict fill.

Related errors


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

Appendix: source

Thrown at pandas/core/arrays/interval.py:899

            values for each index. The value should not be a list. The
            value(s) passed should be either Interval objects or NA/NaN.
        limit : int, default None
            (Not implemented yet for IntervalArray)
            The maximum number of entries where NA values will be filled.
        copy : bool, default True
            Whether to make a copy of the data before filling. If False, then
            the original should be modified and no new memory should be allocated.
            For ExtensionArray subclasses that cannot do this, it is at the
            author's discretion whether to ignore "copy=False" or to raise.

        Returns
        -------
        filled : IntervalArray with NA/NaN filled
        """
        if copy is False:
            raise NotImplementedError
        if isinstance(value, dict):
            raise TypeError(
                "ExtensionArray.fillna does not support filling with a dict. "
                "Use Series.fillna instead."
            )
        if limit is not None:
            raise ValueError("limit must be None")

        value_left, value_right = self._validate_setitem_value(value)

        left = self.left.fillna(value=value_left)
        right = self.right.fillna(value=value_right)
        return self._shallow_copy(left, right)

    def astype(self, dtype, copy: bool = True):
        """
        Cast to an ExtensionArray or NumPy array with dtype 'dtype'.

        Parameters
        ----------

View on GitHub (pinned to 3b7651241d)