pandas-dev/pandas · error · TypeError
Function "{res.name}" does not support keyword arguments
Error message
Function "{res.name}" does not support keyword arguments What it means
When the resolved function is a FuncNode (the built-in math/reduction set: sin, cos, log, abs, sqrt, sum, mean, etc.), visit_Call takes the branch at expr.py:691 and explicitly rejects keyword arguments, because FuncNode.__call__ evaluates positionally against numexpr/math signatures. Any node.keywords present trigger TypeError naming the function.
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 71959b8cb9)
Solutions
- Pass arguments positionally: df.eval('sin(a)'), df.eval('log(a)').
- For multi-arg functions, check supported signatures and pass positionally.
- Compute the function call in plain Python/numpy if keyword semantics are required.
Example fix
// before
df.eval('sin(x=a)')
// after
df.eval('sin(a)') Defensive patterns
Strategy: validation
Validate before calling
import ast
MATH_FUNCS = {'sin', 'cos', 'tan', 'arcsin', 'arccos', 'arctan', 'arctan2',
'sinh', 'cosh', 'tanh', 'arcsinh', 'arccosh', 'arctanh',
'log', 'log10', 'log1p', 'exp', 'expm1', 'sqrt', 'abs',
'sum', 'mean', 'median', 'min', 'max', 'std', 'var'}
def validate_no_kwargs_for_math_fns(expr: str) -> None:
for node in ast.walk(ast.parse(expr, mode='eval')):
if (isinstance(node, ast.Call)
and isinstance(node.func, ast.Name)
and node.func.id in MATH_FUNCS
and node.keywords):
raise TypeError(
f'{node.func.id}() does not accept keyword args; pass positionally'
)
validate_no_kwargs_for_math_fns(expr) Type guard
import ast
def math_calls_are_positional(expr: str) -> bool:
MATH = {'sin', 'cos', 'log', 'sqrt', 'abs', 'sum', 'mean'}
return all(
not (isinstance(n, ast.Call) and isinstance(n.func, ast.Name)
and n.func.id in MATH and n.keywords)
for n in ast.walk(ast.parse(expr, mode='eval'))
) Try / catch
try:
df.eval(expr)
except TypeError as e:
if 'does not support keyword arguments' in str(e):
# strip keyword names, rebuild as positional
df.eval('sin(a)')
raise Prevention
- Pass arguments to math/reduction functions positionally.
- When generating call strings, do not emit kwarg names for FuncNode functions.
- Consult the supported-function list before parameterizing calls.
When it happens
Trigger: df.eval('sin(x=a)'), df.eval('log(x=a, base=10)'), df.query('abs(col=x)') — passing the argument by keyword to a built-in math function.
Common situations: Auto-generating function-call strings with keyword names. Porting sklearn/numpy-style keyword calls into eval. Copying signatures from docs that name parameters.
Related errors
- unsupported operand type(s) for {res.op}: '{lhs.type}' and '
- Only named functions are supported
- Invalid function call {node.func.id}
- keyword error in function call '{node.func.id}'
- "{name}" is not a supported function
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/0e41ec8ea6b26f24.
Report an issue: GitHub.