{"record":{"id":"cefedee36ffe1e6d","repo":"pandas-dev/pandas","slug":"type-self-name-with-dtype-self-dtype-do-cefede","errorCode":null,"errorMessage":"'{type(self).__name__}' with dtype {self.dtype} does not support operation '{name}'","messagePattern":"'(.+?)' with dtype (.+?) does not support operation '(.+?)'","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/base.py","lineNumber":2480,"sourceCode":"        Series.kurt : Return the kurtosis.\n        Series.skew : Return the skewness.\n\n        Examples\n        --------\n        >>> pd.array([1, 2, 3])._reduce(\"min\")\n        np.int64(1)\n        >>> pd.array([1, 2, 3])._reduce(\"max\")\n        np.int64(3)\n        >>> pd.array([1, 2, 3])._reduce(\"sum\")\n        np.int64(6)\n        >>> pd.array([1, 2, 3])._reduce(\"mean\")\n        np.float64(2.0)\n        >>> pd.array([1, 2, 3])._reduce(\"median\")\n        np.float64(2.0)\n        \"\"\"\n        meth = getattr(self, name, None)\n        if meth is None:\n            raise TypeError(\n                f\"'{type(self).__name__}' with dtype {self.dtype} \"\n                f\"does not support operation '{name}'\"\n            )\n        if name != \"count\":\n            kwargs[\"skipna\"] = skipna\n        result = meth(**kwargs)\n        if keepdims:\n            if name in [\"min\", \"max\"]:\n                result = self._from_sequence([result], dtype=self.dtype)\n            else:\n                result = np.array([result])\n\n        return result\n\n    def count(self):\n        \"\"\"\n        Count the number of non-NA values in the array.\n","sourceCodeStart":2462,"sourceCodeEnd":2498,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/base.py#L2462-L2498","documentation":"_reduce looks up the reduction by name via getattr(self, name); if the EA subclass has no attribute matching the requested reduction (e.g. 'sum', 'mean', 'median', 'prod', 'std', 'sem', 'var', 'kurt', 'skew', 'min', 'max'), it raises TypeError naming the class, dtype, and unsupported operation. The docstring's Raises section documents this as the contract for subclasses that do not define a given operation.","triggerScenarios":"Calling Series.sum/mean/median/etc. (or df.<reduction>()) on a Series backed by a custom EA that does not implement the requested reduction method. The dispatch resolves to ExtensionArray._reduce(name) which finds no attribute and raises TypeError.","commonSituations":"A custom string/categorical-like dtype where arithmetic reductions are meaningless but the user invoked Series.mean. Mixed-dtype frames where one column's EA lacks a reduction. A reduction name typo or an unsupported custom reduction name.","solutions":["Select only columns whose dtype supports the reduction before applying: df.select_dtypes(include='number').mean().","If you own the EA, implement the method by the exact name pandas dispatches (e.g. def sum(self, *, skipna, ...)).","Catch the TypeError in a per-column reduction loop and skip/record the unsupported column."],"exampleFix":"// before\ndf.mean()  # TypeError: 'MyArray' with dtype ... does not support operation 'mean'\n\n// after\ndf.select_dtypes(include='number').mean()","handlingStrategy":"validation","validationCode":"name = 'mean'  # the reduction you plan to call\nif not callable(getattr(arr, name, None)):\n    raise TypeError(f'{type(arr).__name__} does not support {name}')\n_ = arr._reduce(name)","typeGuard":"def supports_reduction(arr, name: str) -> bool:\n    return callable(getattr(arr, name, None))","tryCatchPattern":"try:\n    val = series._reduce('mean')\nexcept TypeError:\n    val = series.astype('float64').mean()","preventionTips":["Restrict reductions to numeric columns via select_dtypes(include='number').","Implement reduction methods on the EA by the exact name pandas dispatches (sum, mean, min, max, ...).","Use per-column agg specs so unsupported columns are excluded."],"tags":["extension-array","reduction","type-error","pandas"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}