{"record":{"id":"fdd768c5c103304c","repo":"pandas-dev/pandas","slug":"dtype-self-dtype-does-not-support-operation","errorCode":null,"errorMessage":"dtype '{self.dtype}' does not support operation '{how}'","messagePattern":"dtype '(.+?)' does not support operation '(.+?)'","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/arrow/array.py","lineNumber":3516,"sourceCode":"        has_dropped_na: bool,\n        min_count: int,\n        ngroups: int,\n        ids: npt.NDArray[np.intp],\n        **kwargs,\n    ):\n        if isinstance(self.dtype, StringDtype):\n            if how in [\n                \"prod\",\n                \"mean\",\n                \"median\",\n                \"cumsum\",\n                \"cumprod\",\n                \"std\",\n                \"sem\",\n                \"var\",\n                \"skew\",\n            ]:\n                raise TypeError(\n                    f\"dtype '{self.dtype}' does not support operation '{how}'\"\n                )\n            # Fall through to Arrow-native path below\n\n        pa_type = self._pa_array.type\n\n        # Try PyArrow-native path for decimal and string types where it's faster.\n        # For integer/float/boolean, the fallback path via _to_masked() is faster.\n        if (\n            pa.types.is_decimal(pa_type)\n            or pa.types.is_string(pa_type)\n            or pa.types.is_large_string(pa_type)\n        ):\n            native_result = self._groupby_op_pyarrow(\n                how=how,\n                min_count=min_count,\n                ngroups=ngroups,\n                ids=ids,","sourceCodeStart":3498,"sourceCodeEnd":3534,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/arrow/array.py#L3498-L3534","documentation":"Raised in _groupby_op for a StringDtype column when the requested groupby aggregation is inherently numeric (prod, mean, median, cumsum, cumprod, std, sem, var, skew). String columns cannot participate in these reductions, so pandas rejects them before dispatch.","triggerScenarios":"Calling `df.groupby('g').prod()` (or mean/median/cumsum/etc.) on a DataFrame that contains a `string[pyarrow]` column among its value columns.","commonSituations":"Applying a numeric aggregation across all columns without selecting numeric ones, or after a column was auto-inferred as string.","solutions":["Select only numeric columns before aggregating: `df.groupby('g')[numeric_cols].prod()`.","Drop or exclude string columns from the aggregation.","Cast genuinely-numeric string columns to a numeric dtype first."],"exampleFix":"// before\ndf = pd.DataFrame({\"g\": [\"a\", \"a\", \"b\"], \"x\": [\"1\", \"2\", \"3\"]}, dtype=\"string[pyarrow]\")\ndf.groupby(\"g\").sum()\n\n// after\ndf[\"x\"] = df[\"x\"].astype(\"int64[pyarrow]\")\ndf.groupby(\"g\").sum()","handlingStrategy":"validation","validationCode":"NUMERIC_GB_OPS = {\"sum\", \"prod\", \"mean\", \"median\", \"std\", \"var\", \"sem\", \"skew\", \"cumsum\", \"cumprod\", \"cummax\", \"cummin\"}\n\ndef select_numeric_for_op(df, op):\n    if op in NUMERIC_GB_OPS:\n        return df.select_dtypes(include=\"number\")\n    return df","typeGuard":"def column_supports_op(series, how) -> bool:\n    import pandas as pd\n    if isinstance(series.dtype, pd.StringDtype) and how in {\"prod\", \"mean\", \"median\", \"cumsum\", \"cumprod\", \"std\", \"sem\", \"var\", \"skew\"}:\n        return False\n    return True","tryCatchPattern":"try:\n    df.groupby(\"g\").prod()\nexcept TypeError as e:\n    if \"does not support operation\" in str(e):\n        df.groupby(\"g\")[df.select_dtypes(\"number\").columns].prod()\n    else:\n        raise","preventionTips":["Filter to numeric columns before numeric groupby aggregations.","Use select_dtypes(include='number') in generic aggregation helpers.","Cast stringified numeric columns to numeric dtype during cleaning."],"tags":["arrow","groupby","string-dtype","aggregation"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}