{"record":{"id":"549e56450cdddbcb","repo":"pandas-dev/pandas","slug":"function-is-not-implemented-for-this-dtype-self","errorCode":null,"errorMessage":"function is not implemented for this dtype: {self.dtype}","messagePattern":"function is not implemented for this dtype: (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/base.py","lineNumber":3093,"sourceCode":"            ]:\n                raise TypeError(\n                    f\"dtype '{self.dtype}' does not support operation '{how}'\"\n                )\n            if op.how not in [\"any\", \"all\"]:\n                # Fail early to avoid conversion to object\n                op._get_cython_function(op.kind, op.how, np.dtype(object), False)\n\n            arr = self\n            if op.how == \"sum\":\n                initial = \"\"\n                # https://github.com/pandas-dev/pandas/issues/60229\n                # All NA should result in the empty string.\n                assert \"skipna\" in kwargs\n                if kwargs[\"skipna\"] and min_count == 0:\n                    arr = arr.fillna(\"\")\n            npvalues = arr.to_numpy(object, na_value=np.nan)\n        else:\n            raise NotImplementedError(\n                f\"function is not implemented for this dtype: {self.dtype}\"\n            )\n\n        res_values = op._cython_op_ndim_compat(\n            npvalues,\n            min_count=min_count,\n            ngroups=ngroups,\n            comp_ids=ids,\n            mask=None,\n            initial=initial,\n            **kwargs,\n        )\n\n        if op.how in op.cast_blocklist:\n            # i.e. how in [\"rank\"], since other cast_blocklist methods don't go\n            #  through cython_operation\n            return res_values\n","sourceCodeStart":3075,"sourceCodeEnd":3111,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/base.py#L3075-L3111","documentation":"ExtensionArray._groupby_op (base.py:3093) only has a code path for StringDtype; any other ExtensionArray dtype that reaches the else branch raises NotImplementedError stating the function is not implemented for that dtype. This is the catch-all for unsupported EA types in groupby cython ops.","triggerScenarios":"Calling a groupby aggregation/transformation (sum/prod/min/max/mean/median/var/std/cumsum/rank/etc.) on a column backed by a non-String ExtensionArray that has no dedicated groupby dispatch (e.g. some custom EA, or an EA not handled by the cython path).","commonSituations":"Third-party ExtensionArray dtype used as a groupby aggregation target; pandas version change that routed an EA through _groupby_op without an implementation; experimental EA APIs.","solutions":["Cast the column to a supported dtype (e.g. object, Float64, Int64) before grouping.","Implement _groupby_op on your ExtensionArray subclass.","Use a different aggregation that does not route through _groupby_op (e.g. apply with a Python function).","Report/upgrade the third-party EA library."],"exampleFix":"# before\ndf.groupby(\"id\")[\"custom_col\"].sum()  # raises for custom EA\n\n# after\ndf.groupby(\"id\")[\"custom_col\"].apply(lambda s: ...)  # Python-side\n# or\ndf[\"custom_col\"].astype(\"Float64\").groupby(df[\"id\"]).sum()","handlingStrategy":"fallback","validationCode":"def safe_groupby_sum(s, key):\n    import pandas as pd\n    if not pd.api.types.is_numeric_dtype(s) and str(s.dtype) != \"string\":\n        return s.groupby(key).apply(lambda x: x.tolist())\n    return s.groupby(key).sum()","typeGuard":"def is_groupby_supported_ea(dtype) -> bool:\n    import pandas as pd\n    return pd.api.types.is_numeric_dtype(dtype) or str(dtype) == \"string\"","tryCatchPattern":"try:\n    df.groupby(\"id\")[\"col\"].sum()\nexcept NotImplementedError as e:\n    if \"not implemented for this dtype\" in str(e):\n        df[\"col\"].astype(\"Float64\").groupby(df[\"id\"]).sum()\n    else:\n        raise","preventionTips":["Cast custom EAs to numeric/object before groupby","Implement _groupby_op on custom EAs","Use apply() as a Python fallback for unsupported EAs"],"tags":["groupby","extension-array","not-implemented","subclass"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}