pandas-dev/pandas · error · NotImplementedError

function is not implemented for this dtype: {self.dtype}

Error message

function is not implemented for this dtype: {self.dtype}

What it means

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.

Source

Thrown at pandas/core/arrays/base.py:3093

            ]:
                raise TypeError(
                    f"dtype '{self.dtype}' does not support operation '{how}'"
                )
            if op.how not in ["any", "all"]:
                # Fail early to avoid conversion to object
                op._get_cython_function(op.kind, op.how, np.dtype(object), False)

            arr = self
            if op.how == "sum":
                initial = ""
                # https://github.com/pandas-dev/pandas/issues/60229
                # All NA should result in the empty string.
                assert "skipna" in kwargs
                if kwargs["skipna"] and min_count == 0:
                    arr = arr.fillna("")
            npvalues = arr.to_numpy(object, na_value=np.nan)
        else:
            raise NotImplementedError(
                f"function is not implemented for this dtype: {self.dtype}"
            )

        res_values = op._cython_op_ndim_compat(
            npvalues,
            min_count=min_count,
            ngroups=ngroups,
            comp_ids=ids,
            mask=None,
            initial=initial,
            **kwargs,
        )

        if op.how in op.cast_blocklist:
            # i.e. how in ["rank"], since other cast_blocklist methods don't go
            #  through cython_operation
            return res_values

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Cast the column to a supported dtype (e.g. object, Float64, Int64) before grouping.
  2. Implement _groupby_op on your ExtensionArray subclass.
  3. Use a different aggregation that does not route through _groupby_op (e.g. apply with a Python function).
  4. Report/upgrade the third-party EA library.

Example fix

# before
df.groupby("id")["custom_col"].sum()  # raises for custom EA

# after
df.groupby("id")["custom_col"].apply(lambda s: ...)  # Python-side
# or
df["custom_col"].astype("Float64").groupby(df["id"]).sum()
Defensive patterns

Strategy: fallback

Validate before calling

def safe_groupby_sum(s, key):
    import pandas as pd
    if not pd.api.types.is_numeric_dtype(s) and str(s.dtype) != "string":
        return s.groupby(key).apply(lambda x: x.tolist())
    return s.groupby(key).sum()

Type guard

def is_groupby_supported_ea(dtype) -> bool:
    import pandas as pd
    return pd.api.types.is_numeric_dtype(dtype) or str(dtype) == "string"

Try / catch

try:
    df.groupby("id")["col"].sum()
except NotImplementedError as e:
    if "not implemented for this dtype" in str(e):
        df["col"].astype("Float64").groupby(df["id"]).sum()
    else:
        raise

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/549e56450cdddbcb. Report an issue: GitHub.