{"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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/computation/expr.py#L677-L713","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Rewrite the function call to use positional arguments only: df.query('sin(A)').","If a keyword-named argument is actually a column, drop the keyword name: df.query('log(A)') instead of 'log(x=A)'.","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')."],"exampleFix":"// before\ndf.query(\"sin(x=A) > 0.5\")\ndf.eval(\"log(x=A)\")\n\n// after\ndf.query(\"sin(A) > 0.5\")\ndf.eval(\"log(A)\")","handlingStrategy":"validation","validationCode":"import ast\nimport pandas.core.computation.ops as _ops\n\ndef has_kwarg_to_mathop(expr: str) -> bool:\n    tree = ast.parse(expr, mode='eval')\n    for node in ast.walk(tree):\n        if isinstance(node, ast.Call) and isinstance(node.func, ast.Name) and node.func.id in _ops.MATHOPS:\n            if node.keywords:\n                return True\n    return False\n\nassert not has_kwarg_to_mathop('sin(x=A)'), 'math fns must be called positionally'","typeGuard":"import ast\nimport pandas.core.computation.ops as _ops\n\ndef call_is_positional_mathop(node: ast.Call) -> bool:\n    return (\n        isinstance(node.func, ast.Name)\n        and node.func.id in _ops.MATHOPS\n        and not node.keywords\n    )","tryCatchPattern":"try:\n    df.query('sin(x=A)')\nexcept TypeError as e:\n    if 'does not support keyword arguments' in str(e):\n        df.query('sin(A)')\n    else:\n        raise","preventionTips":["Lint query strings for keyword args inside math-function calls.","Prefer positional-only numpy-style calls in generated query strings.","Document the MATHOPS whitelist next to query-building code."],"tags":["pandas","eval","query","keyword-arguments","function-call"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}