pandas-dev/pandas · error · ValueError

is both the pipe target and a keyword argument

Error message

{target} is both the pipe target and a keyword argument

What it means

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.

Solutions

  1. Remove the duplicate kwarg so the pipe target can fill it.
  2. Rename the target alias to a parameter that the callable accepts and that is not already in kwargs.
  3. Fall back to the plain form: df.pipe(lambda df: func(df, **kwargs)).

Example fix

// before
df.pipe((fit, 'X'), X=X_train)
// after
df.pipe((fit, 'X'))  # X injected by pipe
Defensive patterns

Strategy: validation

Validate before calling

if isinstance(func, tuple) and func[1] in kwargs:
    raise ValueError(f'{func[1]} collides with kwargs {list(kwargs)}')
result = df.pipe(func, **kwargs)

Prevention

When it happens

Trigger: df.pipe((func, 'df'), df=other); df.pipe((sklearn_func, 'X'), X=something). Any call where the second tuple element duplicates a kwarg key.

Common situations: Refactoring pipe calls and forgetting to remove the explicit kwarg; wrapping a library function whose parameter name collides with a chosen target alias.

Related errors


AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11). Data as JSON: /api/errors/07caeb5bc9c54605. Report an issue: GitHub.

Appendix: source

Thrown at pandas/core/common.py:536

        Function to apply to this object or, alternatively, a
        ``(callable, data_keyword)`` tuple where ``data_keyword`` is a
        string indicating the keyword of ``callable`` that expects the
        object.
    *args : iterable, optional
        Positional arguments passed into ``func``.
    **kwargs : dict, optional
        A dictionary of keyword arguments passed into ``func``.

    Returns
    -------
    object : the return type of ``func``.
    """
    if isinstance(func, tuple):
        # Assigning to func_ so pyright understands that it's a callable
        func_, target = func
        if target in kwargs:
            msg = f"{target} is both the pipe target and a keyword argument"
            raise ValueError(msg)
        kwargs[target] = obj
        return func_(*args, **kwargs)
    else:
        return func(obj, *args, **kwargs)


def get_rename_function(mapper: Any) -> Callable:
    """
    Returns a function that will map names/labels, dependent if mapper
    is a dict, Series or just a function.
    """

    def f(x: Hashable) -> Any:
        if x in mapper:
            return mapper[x]
        else:
            return x

View on GitHub (pinned to 3b7651241d)