{"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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/base.py#L3075-L3111","documentation":"_grouped_reduce only implements the cython groupby path for StringDtype (plus first/last handled earlier). For any other ExtensionArray dtype that reaches this branch, there is no cython implementation wired up, so it raises NotImplementedError naming the dtype. This indicates the custom EA has not integrated with pandas' groupby cython acceleration.","triggerScenarios":"Calling a groupby aggregation (sum, mean, min, max, etc. — but not first/last which are handled earlier) on a Series/DataFrame backed by a custom (non-StringDtype, non-numpy-backed) ExtensionArray. The aggregation routes to ExtensionArray._grouped_reduce, finds no matching dtype branch, and raises.","commonSituations":"A third-party extension dtype used as a groupby target without groupby-reduce support. A custom EA that supports scalar reductions but not the cython groupby path. Reaching this via df.groupby(...).agg(...) on a frame containing such a column.","solutions":["Cast the column to a backed numpy dtype before aggregating: df['col'] = df['col'].astype('float64') (accepting loss of NA semantics).","Implement _grouped_reduce on the subclass to dispatch to a cython/numba routine for your dtype, mirroring the StringDtype branch.","Aggregate only the supported columns and exclude the custom-EA column from the groupby reduction."],"exampleFix":"// before\ndf.groupby('g').sum()  # NotImplementedError: function is not implemented for this dtype: MyDtype\n\n// after\nnum_cols = df.select_dtypes(include='number').columns\ndf.groupby('g')[list(num_cols)].sum()\n# or convert the custom column\nout = df['custom'].astype('float64').groupby(df['g']).sum()","handlingStrategy":"fallback","validationCode":"from pandas.core.arrays.string_ import StringDtype\nif not isinstance(arr.dtype, StringDtype):\n    # _grouped_reduce only handles StringDtype (and first/last); cast to numpy\n    arr = arr.astype('float64')\n_ = arr","typeGuard":"def supports_groupby_reduce(arr) -> bool:\n    from pandas.core.arrays.string_ import StringDtype\n    return isinstance(arr.dtype, StringDtype) or not isinstance(arr, __import__('pandas').api.extensions.ExtensionArray)","tryCatchPattern":"try:\n    out = df.groupby('g').sum()\nexcept NotImplementedError:\n    num = df.select_dtypes(include='number').columns\n    out = df.groupby('g')[list(num)].sum()","preventionTips":["Restrict groupby reductions to numpy-backed columns when using custom EAs.","Implement _grouped_reduce on the EA to integrate with pandas' cython groupby path.","Cast custom-EA columns to a numpy dtype before aggregating when NA semantics are expendable."],"tags":["extension-array","groupby","not-implemented","pandas"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}