pandas-dev/pandas · error · SpecificationError

Function names must be unique if there is no new column name

Error message

Function names must be unique if there is no new column names assigned

What it means

Raised during `transform` when a list-like `func` argument contains duplicate entries (e.g. `['mean', 'mean']`). Because there is no dict mapping to assign new column names, duplicate function names would produce ambiguous output column labels. This was added in GH#54929 to fail fast rather than silently overwrite columns.

Source

Thrown at pandas/core/apply.py:372

            If the transform function fails or does not transform.
        """
        obj = self.obj
        func = self.func
        axis = self.axis
        args = self.args
        kwargs = self.kwargs

        is_series = obj.ndim == 1

        if obj._get_axis_number(axis) == 1:
            assert not is_series
            return obj.T.transform(func, 0, *args, **kwargs).T

        if is_list_like(func) and not is_dict_like(func):
            func = cast("list[AggFuncTypeBase]", func)
            # GH#54929 - raise if duplicate function names are passed
            if len(func) > len(set(func)):
                raise SpecificationError(
                    "Function names must be unique if there is no new column names "
                    "assigned"
                )
            # Convert func equivalent dict
            if is_series:
                func = {com.get_callable_name(v) or v: v for v in func}
            else:
                func = dict.fromkeys(obj, func)

        if is_dict_like(func):
            func = cast("AggFuncTypeDict", func)
            return self.transform_dict_like(func)

        # func is either str or callable
        func = cast("AggFuncTypeBase", func)
        try:
            result = self.transform_str_or_callable(func)
        except TypeError:

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Deduplicate the function list before passing it: `list(dict.fromkeys(funcs))` preserves order and removes duplicates.
  2. If you genuinely need the same function applied multiple times with different arguments, use a dict form with distinct output names, e.g. `{'out1': ('mean', a), 'out2': ('mean', b)}`.
  3. Audit the source of the function list to confirm duplicates are unintended.

Example fix

# before
df.transform(['mean', 'sum', 'mean'])
# after
df.transform(['mean', 'sum'])
# or with explicit names
df.transform({'col1': ['mean', 'sum']})
Defensive patterns

Strategy: validation

Validate before calling

def dedupe_funcs(funcs):
    seen = list(dict.fromkeys(funcs))  # order-preserving dedup
    if len(seen) != len(funcs):
        # decide: warn or fail
        pass
    return seen

# usagedf.transform(dedupe_funcs(my_func_list))

Type guard

def has_unique_funcs(funcs) -> bool:
    return len(funcs) == len(set(funcs))

Try / catch

from pandas.errors import SpecificationError
try:
    df.transform(funcs)
except SpecificationError as e:
    if 'Function names must be unique' in str(e):
        df.transform(list(dict.fromkeys(funcs)))
    else:
        raise

Prevention

When it happens

Trigger: Calling `df.transform(['mean', 'mean'])` or `df.transform(['sum', 'sum', 'mean'])` on a DataFrame/Series without a dict wrapper. Also `groupby.transform([...duplicates...])`.

Common situations: Programmatically building a function list from a config or loop that may contain repeats; merging function lists from multiple sources without dedup; refactoring from `agg` (which tolerates repeats under some paths) to `transform`.

Related errors


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