pandas-dev/pandas · error · TypeError

Function " " does not support keyword arguments

Error message

Function "{res.name}" does not support keyword arguments

What it means

Raised by pandas.eval()/query() when a whitelisted numpy math function (FuncNode: sin, cos, exp, log, ...) is invoked with keyword arguments. These functions are dispatched straight to numpy ufuncs through positional arguments only; the keyword path is intentionally rejected with a TypeError to keep the eval grammar simple and unambiguous.

Solutions

  1. Rewrite the function call to use positional arguments only: df.query('sin(A)').
  2. If a keyword-named argument is actually a column, drop the keyword name: df.query('log(A)') instead of 'log(x=A)'.
  3. For functions needing a base or other parameter numpy does not accept positionally (e.g. log base), precompute in Python and inject via @-local: base2 = np.log2(df['A']); df.query('@base2 > 0').

Example fix

// before
df.query("sin(x=A) > 0.5")
df.eval("log(x=A)")

// after
df.query("sin(A) > 0.5")
df.eval("log(A)")
Defensive patterns

Strategy: validation

Validate before calling

import ast
import pandas.core.computation.ops as _ops

def has_kwarg_to_mathop(expr: str) -> bool:
    tree = ast.parse(expr, mode='eval')
    for node in ast.walk(tree):
        if isinstance(node, ast.Call) and isinstance(node.func, ast.Name) and node.func.id in _ops.MATHOPS:
            if node.keywords:
                return True
    return False

assert not has_kwarg_to_mathop('sin(x=A)'), 'math fns must be called positionally'

Type guard

import ast
import pandas.core.computation.ops as _ops

def call_is_positional_mathop(node: ast.Call) -> bool:
    return (
        isinstance(node.func, ast.Name)
        and node.func.id in _ops.MATHOPS
        and not node.keywords
    )

Try / catch

try:
    df.query('sin(x=A)')
except TypeError as e:
    if 'does not support keyword arguments' in str(e):
        df.query('sin(A)')
    else:
        raise

Prevention

When it happens

Trigger: df.query('sin(x=A)'), df.eval('log(x=A, base=2)'), or any call of the form 'mathfn(name=value)' where mathfn is a supported MATHOPS function. Also fires when an expression builder forwards **kwargs into a FuncNode call.

Common situations: Users familiar with numpy keyword-style APIs (np.sin(x=...)) trying the same syntax in a query string. Copy-pasting a Python call that uses keyword arguments into an eval expression. Auto-generated query strings that emit keyword args for clarity.

Related errors


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

Appendix: source

Thrown at pandas/core/computation/expr.py:695

                try:
                    res = FuncNode(node.func.id)
                except ValueError:
                    # Raise original error
                    raise

        if res is None:
            # error: "expr" has no attribute "id"
            raise ValueError(
                f"Invalid function call {node.func.id}"  # type: ignore[union-attr]
            )
        if hasattr(res, "value"):
            res = res.value

        if isinstance(res, FuncNode):
            new_args = [self.visit(arg) for arg in node.args]

            if node.keywords:
                raise TypeError(
                    f'Function "{res.name}" does not support keyword arguments'
                )

            return res(*new_args)

        else:
            new_args = [self.visit(arg)(self.env) for arg in node.args]

            for key in node.keywords:
                if not isinstance(key, ast.keyword):
                    # error: Item "Attribute" of "Attribute | Name" has no
                    # attribute "id"
                    raise ValueError(
                        f"keyword error in function call '{node.func.id}'"  # type: ignore[union-attr]
                    )

                if key.arg:
                    kwargs[key.arg] = self.visit(key.value)(self.env)

View on GitHub (pinned to 3b7651241d)