{"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/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/categorical.py#L2653-L2689","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ns = pd.Series(pd.Categorical([1,2,3], ordered=True))\ns.cumsum()  # TypeError: Accumulation cumsum not supported\n\n// after\ns.astype('int64').cumsum()","handlingStrategy":"type-guard","validationCode":"SUPPORTED_ACCUM = {'cummin', 'cummax'}\ndef safe_accum(s, name):\n    import pandas as pd\n    if isinstance(s.dtype, pd.CategoricalDtype) and name not in SUPPORTED_ACCUM:\n        raise TypeError(f'{name} unsupported on Categorical; cast to numeric first')\n    return getattr(s, name)()","typeGuard":"import pandas as pd\nfrom typing import Any\n\ndef supports_accumulation(obj: Any, name: str) -> bool:\n    if isinstance(getattr(obj, 'dtype', None), pd.CategoricalDtype):\n        return name in ('cummin', 'cummax')\n    return True","tryCatchPattern":"try:\n    s.cumsum()\nexcept TypeError as e:\n    if 'Accumulation' in str(e) and 'not supported' in str(e):\n        s.astype('int64').cumsum()\n    else:\n        raise","preventionTips":["Skip arithmetic accumulations on category columns; cast to numeric first.","Restrict accumulation method lists per dtype."],"tags":["categorical","accumulation","cumsum"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}