{"record":{"id":"07caeb5bc9c54605","repo":"pandas-dev/pandas","slug":"target-is-both-the-pipe-target-and-a-keyword-arg","errorCode":null,"errorMessage":"{target} is both the pipe target and a keyword argument","messagePattern":"(.+?) is both the pipe target and a keyword argument","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/common.py","lineNumber":536,"sourceCode":"        Function to apply to this object or, alternatively, a\n        ``(callable, data_keyword)`` tuple where ``data_keyword`` is a\n        string indicating the keyword of ``callable`` that expects the\n        object.\n    *args : iterable, optional\n        Positional arguments passed into ``func``.\n    **kwargs : dict, optional\n        A dictionary of keyword arguments passed into ``func``.\n\n    Returns\n    -------\n    object : the return type of ``func``.\n    \"\"\"\n    if isinstance(func, tuple):\n        # Assigning to func_ so pyright understands that it's a callable\n        func_, target = func\n        if target in kwargs:\n            msg = f\"{target} is both the pipe target and a keyword argument\"\n            raise ValueError(msg)\n        kwargs[target] = obj\n        return func_(*args, **kwargs)\n    else:\n        return func(obj, *args, **kwargs)\n\n\ndef get_rename_function(mapper: Any) -> Callable:\n    \"\"\"\n    Returns a function that will map names/labels, dependent if mapper\n    is a dict, Series or just a function.\n    \"\"\"\n\n    def f(x: Hashable) -> Any:\n        if x in mapper:\n            return mapper[x]\n        else:\n            return x\n","sourceCodeStart":518,"sourceCodeEnd":554,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/common.py#L518-L554","documentation":"Raised by pandas.util._pipe (called by DataFrame.pipe/Series.pipe) when the callable-position form — pipe((callable, target_name), ...) — is used and `target_name` is also present in **kwargs. The tuple form exists so the piped object can be injected into a named parameter of the callable; if that parameter is already supplied, pandas refuses to silently overwrite it. The message names the conflicting target.","triggerScenarios":"df.pipe((func, 'df'), df=other); df.pipe((sklearn_func, 'X'), X=something). Any call where the second tuple element duplicates a kwarg key.","commonSituations":"Refactoring pipe calls and forgetting to remove the explicit kwarg; wrapping a library function whose parameter name collides with a chosen target alias.","solutions":["Remove the duplicate kwarg so the pipe target can fill it.","Rename the target alias to a parameter that the callable accepts and that is not already in kwargs.","Fall back to the plain form: df.pipe(lambda df: func(df, **kwargs))."],"exampleFix":"// before\ndf.pipe((fit, 'X'), X=X_train)\n// after\ndf.pipe((fit, 'X'))  # X injected by pipe","handlingStrategy":"validation","validationCode":"if isinstance(func, tuple) and func[1] in kwargs:\n    raise ValueError(f'{func[1]} collides with kwargs {list(kwargs)}')\nresult = df.pipe(func, **kwargs)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not supply the target parameter twice in pipe((callable, target), ...).","Choose a target alias that does not collide with existing kwargs.","Fall back to a lambda when in doubt."],"tags":["value-error","pipe","kwargs","api-misuse"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}