pandas-dev/pandas · error · TypeError
Accumulation not supported for
Error message
Accumulation {name} not supported for {type(self)} What it means
Raised in Categorical._accumulate when the requested accumulation name is neither 'cummin' nor 'cummax'. Categoricals only support order-based accumulations; arithmetic accumulations like cumsum/cumprod are meaningless for non-numeric category labels, so they are rejected. The check fires before the ordered check, so even an ordered categorical will fail for cumsum.
Solutions
- For cummin/cummax, mark the categorical ordered (see error 240).
- For arithmetic accumulations, convert to the underlying numeric dtype first: df['col'].astype('int64').cumsum() — only valid if categories are numeric.
- Drop or exclude categorical columns before calling df.cumsum() across the frame.
- Use .cat.codes if you need integer accumulation over code positions (semantics differ).
Example fix
# before
s = pd.Series(pd.Categorical(['a','b','c'], ordered=True))
s.cumsum() # TypeError: Accumulation cumsum not supported
# after (if categories are numeric)
s = pd.Series(pd.Categorical([1,2,3], ordered=True))
s.astype('int64').cumsum() Defensive patterns
Strategy: type-guard
Validate before calling
name = 'cumsum'
if isinstance(s.dtype, pd.CategoricalDtype) and name not in ('cummin', 'cummax'):
raise ValueError(f'{name} not supported on categorical; cast first')
s.__getattribute__(name)() Type guard
def supports_accumulate(s: pd.Series, name: str) -> bool:
if isinstance(s.dtype, pd.CategoricalDtype):
return name in ('cummin', 'cummax')
return True Try / catch
try:
s.cumsum()
except TypeError as e:
if 'not supported for' in str(e) and isinstance(s.dtype, pd.CategoricalDtype):
s.astype('int64').cumsum()
else:
raise Prevention
- Exclude categorical columns before calling df.cumsum()/cumprod().
- For numeric categoricals, cast to int64/float64 before arithmetic accumulation.
When it happens
Trigger: df['catcol'].cumsum(), df['catcol'].cumprod(), df['catcol'].cummin() on an unordered categorical (this error fires only for names other than cummin/cummax), np.add.accumulate on a categorical. df.cummax() on a DataFrame containing a categorical column (the categorical's _accumulate is dispatched to).
Common situations: User calls df.cumsum() on a wide DataFrame that includes a string-typed categorical column. Migrating code that previously ran on object dtype where cumsum silently concatenated. Expecting numeric behavior from a categorically-typed column of integer categories (still rejected because accumulation is by category, not arithmetic).
Related errors
- Accumulation not supported for
- > 1 ndim Categorical are not supported at this time
- axis is out of bounds for array of dimension
- axis(= ) out of bounds
- Can only use .cat accessor with a 'category' dtype
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/590bdea6829af19f.
Report an issue: GitHub.
Appendix: 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 3b7651241d)