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 Categorical._accumulate when the accumulation name is neither 'cummin' nor 'cummax'. Categoricals only support order-based accumulations; sum-style accumulations (cumsum, cumprod) have no meaning on category labels. The method dispatches on name and raises TypeError for anything unrecognized before checking orderedness.
Source
Thrown at pandas/core/arrays/categorical.py:2671
Returns
-------
bool
"""
if not isinstance(other, Categorical):
return False
elif self._categories_match_up_to_permutation(other):
other = self._encode_with_my_categories(other)
return lib.array_equivalent_bytes(self._codes, other._codes)
return False
def _accumulate(self, name: str, skipna: bool = True, **kwargs) -> Self:
func: Callable
if name == "cummin":
func = np.minimum.accumulate
elif name == "cummax":
func = np.maximum.accumulate
else:
raise TypeError(f"Accumulation {name} not supported for {type(self)}")
self.check_for_ordered(name)
codes = self.codes.copy()
mask = self.isna()
if func == np.minimum.accumulate:
codes[mask] = np.iinfo(codes.dtype.type).max
# no need to change codes for maximum because codes[mask] is already -1
if not skipna:
mask = np.maximum.accumulate(mask)
codes = func(codes)
codes[mask] = -1
return self._simple_new(codes, dtype=self._dtype)
@classmethod
def _concat_same_type(cls, to_concat: Sequence[Self], axis: AxisInt = 0) -> Self:
from pandas.core.dtypes.concat import union_categoricals
View on GitHub (pinned to 71959b8cb9)
Solutions
- Cast to a numeric dtype first (.astype('int64') etc.) if the categories are numeric and you want arithmetic accumulation.
- Use .cummin() / .cummax() which are the only accumulations defined for categoricals (requires ordered=True).
- Re-evaluate whether the column should be categorical at all for arithmetic operations.
Example fix
// before
s = pd.Series(pd.Categorical([1,2,3], ordered=True))
s.cumsum() # TypeError: Accumulation cumsum not supported
// after
s.astype('int64').cumsum() Defensive patterns
Strategy: type-guard
Validate before calling
SUPPORTED_ACCUM = {'cummin', 'cummax'}
def safe_accum(s, name):
import pandas as pd
if isinstance(s.dtype, pd.CategoricalDtype) and name not in SUPPORTED_ACCUM:
raise TypeError(f'{name} unsupported on Categorical; cast to numeric first')
return getattr(s, name)() Type guard
import pandas as pd
from typing import Any
def supports_accumulation(obj: Any, name: str) -> bool:
if isinstance(getattr(obj, 'dtype', None), pd.CategoricalDtype):
return name in ('cummin', 'cummax')
return True Try / catch
try:
s.cumsum()
except TypeError as e:
if 'Accumulation' in str(e) and 'not supported' in str(e):
s.astype('int64').cumsum()
else:
raise Prevention
- Skip arithmetic accumulations on category columns; cast to numeric first.
- Restrict accumulation method lists per dtype.
When it happens
Trigger: Calling .cumsum() or .cumprod() on a categorical Series/Index; calling .cummin()/.cummax() routes here only if the name string is somehow altered; passing a custom accumulation name through internal APIs.
Common situations: Applying .cumsum() to a column mistakenly left as category dtype after pd.get_dummies was forgotten, or generic code that calls every accumulation method on each column type blindly.
Related errors
- Accumulation {name} not supported for {type(self)}
- overflow in timedelta operation
- No accumulation for {func} implemented on BaseMaskedArray
- No masked accumulation defined for dtype {values.dtype.type}
- No accumulation for {func} implemented on BaseMaskedArray
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/590bdea6829af19f.
Report an issue: GitHub.