{"record":{"id":"590bdea6829af19f","repo":"pandas-dev/pandas","slug":"accumulation-name-not-supported-for-type-self","errorCode":null,"errorMessage":"Accumulation {name} not supported for {type(self)}","messagePattern":"Accumulation (.+?) not supported for (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/categorical.py","lineNumber":2671,"sourceCode":"        Returns\n        -------\n        bool\n        \"\"\"\n        if not isinstance(other, Categorical):\n            return False\n        elif self._categories_match_up_to_permutation(other):\n            other = self._encode_with_my_categories(other)\n            return lib.array_equivalent_bytes(self._codes, other._codes)\n        return False\n\n    def _accumulate(self, name: str, skipna: bool = True, **kwargs) -> Self:\n        func: Callable\n        if name == \"cummin\":\n            func = np.minimum.accumulate\n        elif name == \"cummax\":\n            func = np.maximum.accumulate\n        else:\n            raise TypeError(f\"Accumulation {name} not supported for {type(self)}\")\n        self.check_for_ordered(name)\n\n        codes = self.codes.copy()\n        mask = self.isna()\n        if func == np.minimum.accumulate:\n            codes[mask] = np.iinfo(codes.dtype.type).max\n        # no need to change codes for maximum because codes[mask] is already -1\n        if not skipna:\n            mask = np.maximum.accumulate(mask)\n\n        codes = func(codes)\n        codes[mask] = -1\n        return self._simple_new(codes, dtype=self._dtype)\n\n    @classmethod\n    def _concat_same_type(cls, to_concat: Sequence[Self], axis: AxisInt = 0) -> Self:\n        from pandas.core.dtypes.concat import union_categoricals\n","sourceCodeStart":2653,"sourceCodeEnd":2689,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/categorical.py#L2653-L2689","documentation":"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.","triggerScenarios":"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).","commonSituations":"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).","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)."],"exampleFix":"# before\ns = pd.Series(pd.Categorical(['a','b','c'], ordered=True))\ns.cumsum()  # TypeError: Accumulation cumsum not supported\n\n# after (if categories are numeric)\ns = pd.Series(pd.Categorical([1,2,3], ordered=True))\ns.astype('int64').cumsum()","handlingStrategy":"type-guard","validationCode":"name = 'cumsum'\nif isinstance(s.dtype, pd.CategoricalDtype) and name not in ('cummin', 'cummax'):\n    raise ValueError(f'{name} not supported on categorical; cast first')\ns.__getattribute__(name)()","typeGuard":"def supports_accumulate(s: pd.Series, name: str) -> bool:\n    if isinstance(s.dtype, pd.CategoricalDtype):\n        return name in ('cummin', 'cummax')\n    return True","tryCatchPattern":"try:\n    s.cumsum()\nexcept TypeError as e:\n    if 'not supported for' in str(e) and isinstance(s.dtype, pd.CategoricalDtype):\n        s.astype('int64').cumsum()\n    else:\n        raise","preventionTips":["Exclude categorical columns before calling df.cumsum()/cumprod().","For numeric categoricals, cast to int64/float64 before arithmetic accumulation."],"tags":["categorical","accumulation","cumsum","cummax"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}