{"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":"validation","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/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/base.py#L2462-L2498","documentation":"ExtensionArray._reduce (base.py:2480) dispatches by looking up an attribute named `name` (e.g. 'sum', 'mean', 'median') on self; if no such method exists it raises TypeError stating the class+dtype does not support that operation. This is the generic reduction fallback used by Series.min/max/sum/mean/median/std/var/prod/sem/kurt/skew.","triggerScenarios":"Calling an unsupported reduction on an EA-backed Series, e.g. s.median() on a string-dtype EA, s.prod() on a datetime EA, or s.kurt() on a boolean EA, where the EA lacks a method of that name.","commonSituations":"Applying df.mean(numeric_only=False) across heterogeneous columns; calling a statistical reduction on a non-numeric Series; using a custom EA that only implemented some reductions.","solutions":["Pass numeric_only=True (or select numeric columns) so the reduction skips unsupported dtypes.","Convert the Series to a supported numeric dtype before reducing: s.astype('Float64').mean().","Implement the missing reduction method on your ExtensionArray subclass so _reduce can dispatch to it.","Choose a reduction that the dtype supports (e.g. count/min/max instead of mean for non-numeric)."],"exampleFix":"# before\ns = pd.Series([\"1\", \"2\"], dtype=\"string\")\ns.mean()  # raises\n\n# after\ns.astype(\"Int64\").mean()","handlingStrategy":"validation","validationCode":"def safe_reduce(s, name):\n    import pandas as pd\n    if not pd.api.types.is_numeric_dtype(s) and name not in (\"count\", \"min\", \"max\"):\n        raise TypeError(f\"{s.dtype} does not support {name}\")\n    return getattr(s, name)()","typeGuard":"def supports_reduction(dtype, name) -> bool:\n    import pandas as pd\n    numeric_ops = {\"sum\",\"mean\",\"median\",\"prod\",\"std\",\"var\",\"sem\",\"kurt\",\"skew\"}\n    return name in (\"count\",\"min\",\"max\") or pd.api.types.is_numeric_dtype(dtype) or name not in numeric_ops","tryCatchPattern":"try:\n    val = s.mean()\nexcept TypeError as e:\n    if \"does not support operation\" in str(e):\n        val = s.astype(\"Float64\").mean()\n    else:\n        raise","preventionTips":["Use numeric_only=True on DataFrame reductions","Convert dtypes before reducing","Check method exists on the dtype before calling"],"tags":["extension-array","reduce","reduction","dtype-mismatch"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}