{"record":{"id":"0e41ec8ea6b26f24","repo":"pandas-dev/pandas","slug":"function-res-name-does-not-support-keyword-arg","errorCode":null,"errorMessage":"Function \"{res.name}\" does not support keyword arguments","messagePattern":"Function \"(.+?)\" does not support keyword arguments","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/computation/expr.py","lineNumber":695,"sourceCode":"                try:\n                    res = FuncNode(node.func.id)\n                except ValueError:\n                    # Raise original error\n                    raise\n\n        if res is None:\n            # error: \"expr\" has no attribute \"id\"\n            raise ValueError(\n                f\"Invalid function call {node.func.id}\"  # type: ignore[union-attr]\n            )\n        if hasattr(res, \"value\"):\n            res = res.value\n\n        if isinstance(res, FuncNode):\n            new_args = [self.visit(arg) for arg in node.args]\n\n            if node.keywords:\n                raise TypeError(\n                    f'Function \"{res.name}\" does not support keyword arguments'\n                )\n\n            return res(*new_args)\n\n        else:\n            new_args = [self.visit(arg)(self.env) for arg in node.args]\n\n            for key in node.keywords:\n                if not isinstance(key, ast.keyword):\n                    # error: Item \"Attribute\" of \"Attribute | Name\" has no\n                    # attribute \"id\"\n                    raise ValueError(\n                        f\"keyword error in function call '{node.func.id}'\"  # type: ignore[union-attr]\n                    )\n\n                if key.arg:\n                    kwargs[key.arg] = self.visit(key.value)(self.env)","sourceCodeStart":677,"sourceCodeEnd":713,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/computation/expr.py#L677-L713","documentation":"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.","triggerScenarios":"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.","commonSituations":"Auto-generating function-call strings with keyword names. Porting sklearn/numpy-style keyword calls into eval. Copying signatures from docs that name parameters.","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."],"exampleFix":"// before\ndf.eval('sin(x=a)')\n// after\ndf.eval('sin(a)')","handlingStrategy":"validation","validationCode":"import ast\n\nMATH_FUNCS = {'sin', 'cos', 'tan', 'arcsin', 'arccos', 'arctan', 'arctan2',\n              'sinh', 'cosh', 'tanh', 'arcsinh', 'arccosh', 'arctanh',\n              'log', 'log10', 'log1p', 'exp', 'expm1', 'sqrt', 'abs',\n              'sum', 'mean', 'median', 'min', 'max', 'std', 'var'}\n\ndef validate_no_kwargs_for_math_fns(expr: str) -> None:\n    for node in ast.walk(ast.parse(expr, mode='eval')):\n        if (isinstance(node, ast.Call)\n                and isinstance(node.func, ast.Name)\n                and node.func.id in MATH_FUNCS\n                and node.keywords):\n            raise TypeError(\n                f'{node.func.id}() does not accept keyword args; pass positionally'\n            )\n\nvalidate_no_kwargs_for_math_fns(expr)","typeGuard":"import ast\n\ndef math_calls_are_positional(expr: str) -> bool:\n    MATH = {'sin', 'cos', 'log', 'sqrt', 'abs', 'sum', 'mean'}\n    return all(\n        not (isinstance(n, ast.Call) and isinstance(n.func, ast.Name)\n             and n.func.id in MATH and n.keywords)\n        for n in ast.walk(ast.parse(expr, mode='eval'))\n    )","tryCatchPattern":"try:\n    df.eval(expr)\nexcept TypeError as e:\n    if 'does not support keyword arguments' in str(e):\n        # strip keyword names, rebuild as positional\n        df.eval('sin(a)')\n    raise","preventionTips":["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."],"tags":["pandas","eval","functions","numexpr","kwargs"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}