pandas-dev/pandas · error · TypeError
Accumulation not supported for
Error message
Accumulation {name} not supported for {type(self)} What it means
Raised by DatetimeLikeArrayMixin._accumulate when the requested accumulation name is not in {'cummin', 'cummax'}. Datetime, Timedelta, and Period arrays only support cumulative min/max — cumsum/cumprod/cummin/etc. on datetimes are numerically meaningless and explicitly disallowed.
Solutions
- Use cummin() or cummax() instead, which are supported for these dtypes.
- Exclude datetime/timedelta/period columns before applying cumsum/cumprod: select numeric columns first.
- If a numeric accumulation is genuinely needed, convert: df[col].view('i8').cumsum() (advanced, mind the resolution and NaT sentinel).
Example fix
// before df['date'].cumsum() # TypeError // after df['date'].cummax() # supported accumulation
Defensive patterns
Strategy: validation
Validate before calling
import pandas as pd
SUPPORTED_ACCUM = {'cummin', 'cummax'}
def safe_accumulate(arr, how, **kw):
if how not in SUPPORTED_ACCUM:
raise TypeError(f'datetimelike arrays only support {SUPPORTED_ACCUM}, got {how}')
return getattr(arr, how)(**kw) Type guard
import pandas as pd
def is_datetimelike_array(a) -> bool:
d = getattr(a, 'dtype', None)
return d is not None and (d.kind in 'mM' or isinstance(d, pd.PeriodDtype)) Try / catch
try:
res = getattr(df[col], how)()
except TypeError as e:
if 'Accumulation' in str(e) and 'not supported' in str(e):
res = df[col].cummax() # fallback to a supported accumulation
else:
raise Prevention
- Restrict accumulation dispatch to cummin/cummax for datetimelike columns.
- Select numeric columns before applying cumsum/cumprod across a frame.
- Type-check dtype before forwarding accumulation names from generic pipelines.
When it happens
Trigger: Calling DatetimeArray.cumsum(), TimedeltaIndex.cumprod(), PeriodIndex.cumsum(), or any df.cumsum()/df.cumprod() on a column of these dtypes; df.rolling(...).apply with an accumulation dispatcher that routes to _accumulate.
Common situations: Generic pipelines that call cumsum/cumprod across all numeric and datetime columns; reporting code that accumulates over a date axis.
Related errors
- Accumulation not supported for
- cannot add Period to a
- Cannot add and
- cannot add and
- cannot subtract a datelike from a
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/a8d548081af874cb.
Report an issue: GitHub.
Appendix: source
Thrown at pandas/core/arrays/datetimelike.py:1309
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-likeView on GitHub (pinned to 3b7651241d)