pandas-dev/pandas · error · TypeError

Accumulation {name} not supported for {type(self)}

Error message

Accumulation {name} not supported for {type(self)}

What it means

Raised by _accumulate for any accumulation name other than 'cummin' and 'cummax'. Datetime-like arrays only support the order-preserving cumulative reductions; cumsum/cumprod/etc. are meaningless on absolute time and are rejected with TypeError.

Source

Thrown at pandas/core/arrays/datetimelike.py:1300

            return op(self, other[0])

        if config["mode"]["performance_warnings"]:
            warnings.warn(
                "Adding/subtracting object-dtype array to "
                f"{type(self).__name__} not vectorized.",
                PerformanceWarning,
                stacklevel=find_stack_level(),
            )

        # Caller is responsible for broadcasting if necessary
        assert self.shape == other.shape, (self.shape, other.shape)

        res_values = op(self.astype("O"), np.asarray(other))
        return res_values

    def _accumulate(self, name: str, *, skipna: bool = True, **kwargs) -> Self:
        if name not in {"cummin", "cummax"}:
            raise TypeError(f"Accumulation {name} not supported for {type(self)}")

        op = getattr(datetimelike_accumulations, name)
        result = op(self.copy(), skipna=skipna, **kwargs)

        return type(self)._simple_new(result, dtype=self.dtype)

    @unpack_zerodim_and_defer("__add__")
    def __add__(self, other):
        other_dtype = getattr(other, "dtype", None)
        other = ensure_wrapped_if_datetimelike(other)

        # scalar others
        if other is NaT:
            result: np.ndarray | DatetimeLikeArrayMixin = self._add_nat()
        elif isinstance(other, (Tick, timedelta, np.timedelta64)):
            result = self._add_timedeltalike_scalar(other)
        elif isinstance(other, Day) and lib.is_np_dtype(self.dtype, "Mm"):
            # We treat this as Tick-like

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Use idx.cummin() or idx.cummax() which are the only supported cumulative ops on datetimelike arrays.
  2. Convert to ordinals/timestamps for arithmetic accumulations: idx.astype('int64').cumsum() or idx.view('int64').cumsum() if you understand the units.
  3. For TimedeltaIndex.cumsum(), cast to int64 nanoseconds explicitly and wrap the result back into a TimedeltaIndex.
  4. Guard: if name not in {'cummin','cummax'} skip the op for datetimelike dtypes.

Example fix

// before
out = datetime_idx.cumsum()  # TypeError: Accumulation cumsum not supported
// after
out = datetime_idx.astype('int64').cumsum().view('datetime64[ns]')
Defensive patterns

Strategy: type-guard

Validate before calling

SUPPORTED = {'cummin', 'cummax'}
if name not in SUPPORTED and idx.dtype.kind in 'mM':
    raise ValueError(f'skipping unsupported accumulation {name}')

Type guard

def supports_accumulation(idx, name: str) -> bool:
    return name in {'cummin', 'cummax'} or idx.dtype.kind not in 'mMp'

Try / catch

try:
    out = getattr(idx, name)()
except TypeError as e:
    if 'Accumulation' in str(e) and 'not supported' in str(e):
        out = idx.astype('int64').cumsum()  # explicit cast path
    else:
        raise

Prevention

When it happens

Trigger: Calling idx.cumsum(), idx.cumprod(), or any .cum* on a DatetimeIndex, TimedeltaIndex, or PeriodIndex; or routing an arbitrary accumulation name through the EA _accumulate hook at line 1298.

Common situations: Generic 'apply every cum* op' code; porting numeric pipelines to time-series data; GroupBy dispatch into unsupported accumulations.

Related errors


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