pandas-dev/pandas · error · ValueError

limit must be None

Error message

limit must be None

What it means

Raised by IntervalArray.fillna when the 'limit' keyword is not None. Filling a capped number of NA entries is explicitly unsupported on IntervalArray (documented as 'Not implemented yet'), so the method rejects the argument outright rather than silently ignoring it. Use Series.fillna or implement the cap manually.

Solutions

  1. Drop the 'limit' argument when calling fillna on an IntervalArray or interval-backed Series.
  2. If you need a cap, fill all NAs then mask/truncate the changed positions yourself.
  3. Use Series.fillna and post-process if you must respect a cap.

Example fix

// before
arr.fillna(pd.Interval(0, 1), limit=3)
// after
arr.fillna(pd.Interval(0, 1))
Defensive patterns

Strategy: validation

Validate before calling

def safe_fillna(arr, value, limit=None):
    import pandas as pd
    if limit is not None and isinstance(arr, pd.arrays.IntervalArray):
        raise ValueError(
            'limit unsupported for IntervalArray.fillna; drop it or cap manually'
        )
    return arr.fillna(value, limit=limit)

Prevention

When it happens

Trigger: Calling interval_array.fillna(value, limit=5); calling Series.fillna(..., limit=N) on a Series whose dtype is an IntervalDtype; passing limit unconditionally in dtype-agnostic fillna code.

Common situations: Generic NA-filling helpers templated across dtypes that always forward limit; porting numeric fillna code to interval-backed Series.

Related errors


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

Appendix: 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 3b7651241d)