pandas-dev/pandas · error · ValueError

limit must be None

Error message

limit must be None

What it means

Raised as a ValueError by `IntervalArray.fillna` when a `limit` argument is supplied. The method does not implement partial filling (limiting consecutive fills); only full fill is supported. Fires at pandas/core/arrays/interval.py:904.

Source

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

        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
        ----------
        dtype : str or dtype
            Typecode or data-type to which the array is cast.

        copy : bool, default True
            Whether to copy the data, even if not necessary. If False,

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Drop the `limit` argument when calling fillna on the IntervalArray.
  2. If partial fill is needed, use the Series-level API: `s.fillna(value, limit=N)`.
  3. Implement partial fill manually by masking the first N NA positions and assigning.

Example fix

// before
ia.fillna(pd.Interval(0, 1), limit=2)
// after
ia.fillna(pd.Interval(0, 1))
// or, for partial fill:
s = pd.Series(ia)
s = s.fillna(pd.Interval(0, 1), limit=2)
Defensive patterns

Strategy: validation

Validate before calling

def fillna_interval(ia, value, limit=None):
    import pandas as pd
    if limit is not None:
        return pd.Series(ia).fillna(value, limit=limit).values
    return ia.fillna(value)

Type guard

def limit_is_none(limit) -> bool:
    return limit is None

Try / catch

try:
    out = ia.fillna(value, limit=limit)
except ValueError as e:
    if "limit must be None" in str(e):
        out = pd.Series(ia).fillna(value, limit=limit).values
    else:
        raise

Prevention

When it happens

Trigger: `ia.fillna(pd.Interval(0,1), limit=2)`, or routing a Series `.fillna(..., limit=N)` call down into the underlying array.

Common situations: Copy-pasting numeric fillna patterns that include `limit=`; pipelines that auto-pass `limit` to every fillna.

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/0e0be8c17d271dd8. Report an issue: GitHub.