pandas-dev/pandas · error · TypeError

operation ' ' not supported for dtype

Error message

operation '{name}' not supported for dtype '{self.dtype}'

What it means

Inside _accumulate, the requested reduction (cummax/cummin/cumsum/cumprod) is dispatched to pyarrow.compute. If pyarrow raises ArrowNotImplementedError (no kernel for this dtype, e.g. cumprod on strings), pandas re-raises it as a TypeError naming the unsupported operation and dtype. This is the fallback after dtype pre-handlers fail to cover the case.

Solutions

  1. Check the column dtype and skip/convert non-numeric columns before applying cumulative reductions.
  2. Upgrade pyarrow to a version that implements the kernel for this type.
  3. Cast the column to a numeric dtype explicitly before .cumsum()/.cumprod().

Example fix

// before
s = pd.Series(["a", "b"], dtype="string[pyarrow]")
s.cumsum()
// after
s = pd.Series([1, 2], dtype="int64[pyarrow]")
s.cumsum()
Defensive patterns

Strategy: try-catch

Validate before calling

SUPPORTED_ACCUM = {"cumsum", "cumprod", "cummin", "cummax"}
NUMERIC_KINDS = {"i", "u", "f", "c"}

def accum_supported(arr, name) -> bool:
    return name in SUPPORTED_ACCUM and arr.dtype.kind in NUMERIC_KINDS

Type guard

def is_numeric_arrow(arr) -> bool:
    return getattr(arr.dtype, "kind", "") in {"i", "u", "f", "c"}

Try / catch

try:
    s.cumsum()
except TypeError:
    s.astype("float64").cumsum()

Prevention

When it happens

Trigger: Calling .cumsum(), .cumprod(), .cummin(), or .cummax() on an ArrowExtensionArray whose pyarrow type lacks a matching accumulator kernel (e.g. cumprod on string[pyarrow], cumulative ops on some temporal types).

Common situations: Accidentally running cumulative reductions on categorical/string columns; pyarrow version missing a newer kernel.

Related errors


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

Appendix: source

Thrown at pandas/core/arrays/arrow/array.py:2431

        convert_to_int = (
            pa.types.is_temporal(pa_dtype) and name in ["cummax", "cummin"]
        ) or (pa.types.is_duration(pa_dtype) and name == "cumsum")

        if convert_to_int:
            if pa_dtype.bit_width == 32:
                data_to_accum = data_to_accum.cast(pa.int32())
            else:
                data_to_accum = data_to_accum.cast(pa.int64())

        if name in ("cummax", "cummin") and pa.types.is_floating(data_to_accum.type):
            kwargs["start"] = float("-inf") if name == "cummax" else float("inf")

        try:
            result = pyarrow_meth(data_to_accum, skip_nulls=skipna, **kwargs)
        except pa.ArrowNotImplementedError as err:
            msg = f"operation '{name}' not supported for dtype '{self.dtype}'"
            raise TypeError(msg) from err

        if convert_to_int:
            result = result.cast(pa_dtype)

        return self._from_pyarrow_array(result)

    def _str_accumulate(
        self, name: str, *, skipna: bool = True, **kwargs
    ) -> ArrowExtensionArray | ExtensionArray:
        """
        Accumulate implementation for strings, see `_accumulate` docstring for details.

        pyarrow.compute does not implement these methods for strings.
        """
        if name == "cumprod":
            msg = f"operation '{name}' not supported for dtype '{self.dtype}'"
            raise TypeError(msg)

View on GitHub (pinned to 3b7651241d)