{"record":{"id":"6abbfdce2d817b44","repo":"pandas-dev/pandas","slug":"name-is-not-a-supported-function","errorCode":null,"errorMessage":"\"{name}\" is not a supported function","messagePattern":"\"(.+?)\" is not a supported function","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/computation/ops.py","lineNumber":561,"sourceCode":"class MathCall(Op):\n    def __init__(self, func, args) -> None:\n        super().__init__(func.name, args)\n        self.func = func\n\n    def __call__(self, env):\n        # error: \"Op\" not callable\n        operands = [op(env) for op in self.operands]  # type: ignore[operator]\n        return self.func.func(*operands)\n\n    def __repr__(self) -> str:\n        operands = map(str, self.operands)\n        return pprint_thing(f\"{self.op}({','.join(operands)})\")\n\n\nclass FuncNode:\n    def __init__(self, name: str) -> None:\n        if name not in MATHOPS:\n            raise ValueError(f'\"{name}\" is not a supported function')\n        self.name = name\n        self.func = getattr(np, name)\n\n    def __call__(self, *args) -> MathCall:\n        return MathCall(self, args)\n","sourceCodeStart":543,"sourceCodeEnd":567,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/computation/ops.py#L543-L567","documentation":"Raised in FuncNode.__init__ when the requested function name is not in MATHOPS — the fixed whitelist of numpy math functions exposed through eval/query (sin, cos, tan, exp, log, expm1, log1p, sqrt, sinh, cosh, tanh, arcsin, arccos, arctan, arccosh, arcsinh, arctanh, abs, log10, floor, ceil, arctan2). FuncNode is the fallback constructor invoked when a call target is not resolvable in the user scope; if the name also misses the whitelist, this ValueError is raised and typically surfaces as the underlying cause of an UndefinedVariableError re-raise.","triggerScenarios":"df.query('foo(A)') where 'foo' is neither in scope nor in MATHOPS (this ValueError is raised inside the fallback try, then caught and the original UndefinedVariableError is re-raised — but direct FuncNode('foo') construction surfaces it). Programmatic use of FuncNode to validate a function name.","commonSituations":"Typos in math function names ('arcsinh' vs 'arcsinh'). Expecting arbitrary numpy functions (np.where, np.maximum, np.isnan) to be available in eval. Building query strings dynamically and forgetting to whitelist/escape custom functions.","solutions":["Use only whitelisted math function names; see MATHOPS in pandas/core/computation/ops.py.","For np.isnan/np.isinf/np.where, compute in Python first and inject via @-local: mask = np.isnan(df['A']); df[mask].","Pre-resolve custom functions in scope and reference them with @ prefix only if they accept positional Series args.","Validate function names against MATHOPS before assembling a dynamic query string."],"exampleFix":"// before\nfrom pandas.core.computation.ops import FuncNode\nFuncNode(\"isnan\")\ndf.query(\"isnan(A)\")\n\n// after\nmask = np.isnan(df['A'])\ndf[mask]\n# or use the whitelist\ndf.query(\"sin(A) > 0.5\")","handlingStrategy":"validation","validationCode":"import pandas.core.computation.ops as _ops\n\ndef is_supported_mathop(name: str) -> bool:\n    return name in _ops.MATHOPS\n\nassert is_supported_mathop(fn_name), f'{fn_name} is not a supported function; see MATHOPS'","typeGuard":"import pandas.core.computation.ops as _ops\nfrom typing import Any\n\ndef is_mathop_name(name: Any) -> bool:\n    return isinstance(name, str) and name in _ops.MATHOPS","tryCatchPattern":"try:\n    from pandas.core.computation.ops import FuncNode\n    FuncNode('isnan')\nexcept ValueError as e:\n    if 'not a supported function' in str(e):\n        mask = np.isnan(df['A'])\n    else:\n        raise","preventionTips":["Validate function names against MATHOPS before assembling query strings.","Precompute unsupported numpy functions (isnan, where, maximum) in Python and inject via @-locals.","Keep a copy of the MATHOPS tuple near query-building code."],"tags":["pandas","eval","query","function-call","whitelist","mathops"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}