{"record":{"id":"c3f3aff095ab0db6","repo":"pandas-dev/pandas","slug":"function-names-must-be-unique-if-there-is-no-new-c","errorCode":null,"errorMessage":"Function names must be unique if there is no new column names assigned","messagePattern":"Function names must be unique if there is no new column names assigned","errorType":"exception","errorClass":"SpecificationError","httpStatus":null,"severity":"error","filePath":"pandas/core/apply.py","lineNumber":372,"sourceCode":"            If the transform function fails or does not transform.\n        \"\"\"\n        obj = self.obj\n        func = self.func\n        axis = self.axis\n        args = self.args\n        kwargs = self.kwargs\n\n        is_series = obj.ndim == 1\n\n        if obj._get_axis_number(axis) == 1:\n            assert not is_series\n            return obj.T.transform(func, 0, *args, **kwargs).T\n\n        if is_list_like(func) and not is_dict_like(func):\n            func = cast(\"list[AggFuncTypeBase]\", func)\n            # GH#54929 - raise if duplicate function names are passed\n            if len(func) > len(set(func)):\n                raise SpecificationError(\n                    \"Function names must be unique if there is no new column names \"\n                    \"assigned\"\n                )\n            # Convert func equivalent dict\n            if is_series:\n                func = {com.get_callable_name(v) or v: v for v in func}\n            else:\n                func = dict.fromkeys(obj, func)\n\n        if is_dict_like(func):\n            func = cast(\"AggFuncTypeDict\", func)\n            return self.transform_dict_like(func)\n\n        # func is either str or callable\n        func = cast(\"AggFuncTypeBase\", func)\n        try:\n            result = self.transform_str_or_callable(func)\n        except TypeError:","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/apply.py#L354-L390","documentation":"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.","triggerScenarios":"Calling `df.transform(['mean', 'mean'])` or `df.transform(['sum', 'sum', 'mean'])` on a DataFrame/Series without a dict wrapper. Also `groupby.transform([...duplicates...])`.","commonSituations":"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`.","solutions":["Deduplicate the function list before passing it: `list(dict.fromkeys(funcs))` preserves order and removes duplicates.","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)}`.","Audit the source of the function list to confirm duplicates are unintended."],"exampleFix":"# before\ndf.transform(['mean', 'sum', 'mean'])\n# after\ndf.transform(['mean', 'sum'])\n# or with explicit names\ndf.transform({'col1': ['mean', 'sum']})","handlingStrategy":"validation","validationCode":"def dedupe_funcs(funcs):\n    seen = list(dict.fromkeys(funcs))  # order-preserving dedup\n    if len(seen) != len(funcs):\n        # decide: warn or fail\n        pass\n    return seen\n\n# usagedf.transform(dedupe_funcs(my_func_list))","typeGuard":"def has_unique_funcs(funcs) -> bool:\n    return len(funcs) == len(set(funcs))","tryCatchPattern":"from pandas.errors import SpecificationError\ntry:\n    df.transform(funcs)\nexcept SpecificationError as e:\n    if 'Function names must be unique' in str(e):\n        df.transform(list(dict.fromkeys(funcs)))\n    else:\n        raise","preventionTips":["Deduplicate function lists before passing to transform.","Use a dict with explicit output names if you need the same function under different labels."],"tags":["pandas","transform","duplicate","specificationerror","validation"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}