{"record":{"id":"7880f7da5a1d744e","repo":"pandas-dev/pandas","slug":"variables-in-expression-expr-overlap-with-buil","errorCode":null,"errorMessage":"Variables in expression \"{expr}\" overlap with builtins: ({s})","messagePattern":"Variables in expression \"(.+?)\" overlap with builtins: \\((.+?)\\)","errorType":"exception","errorClass":"NumExprClobberingError","httpStatus":null,"severity":"error","filePath":"pandas/core/computation/engines.py","lineNumber":43,"sourceCode":"\n_ne_builtins = frozenset(MATHOPS + REDUCTIONS)\n\n\ndef _check_ne_builtin_clash(expr: Expr) -> None:\n    \"\"\"\n    Attempt to prevent foot-shooting in a helpful way.\n\n    Parameters\n    ----------\n    expr : Expr\n        Terms can contain\n    \"\"\"\n    names = expr.names\n    overlap = names & _ne_builtins\n\n    if overlap:\n        s = \", \".join([repr(x) for x in overlap])\n        raise NumExprClobberingError(\n            f'Variables in expression \"{expr}\" overlap with builtins: ({s})'\n        )\n\n\nclass AbstractEngine(metaclass=abc.ABCMeta):\n    \"\"\"Object serving as a base class for all engines.\"\"\"\n\n    has_neg_frac = False\n\n    def __init__(self, expr) -> None:\n        self.expr = expr\n        self.aligned_axes = None\n        self.result_type = None\n        self.result_name = None\n\n    def convert(self) -> str:\n        \"\"\"\n        Convert an expression for evaluation.","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/computation/engines.py#L25-L61","documentation":"Raised by _check_ne_builtin_clash (pandas/core/computation/engines.py:43) as a NumExprClobberingError when a query/eval expression references a variable whose name collides with a numexpr builtin (from MATHOPS + REDUCTIONS, e.g. sum, max, min, log, exp). Because numexpr cannot distinguish column/variable names from its own functions, pandas refuses the expression to prevent silently calling a builtin instead of resolving your data.","triggerScenarios":"`df.query('log > 2')` where 'log' is intended as a column but clashes with numexpr's log; `df.eval('sum = a + b')`; any expression referencing a column named after a math/reduction function while using engine='numexpr'.","commonSituations":"Columns named after math functions (log, exp, sin, max, min, sum, count). Dataset schema collisions discovered after switching to numexpr for speed.","solutions":["Rename the column to avoid the builtin name: `df.rename(columns={'log':'log_val'})`.","Switch the engine to python: `df.query('log > 2', engine='python')` which resolves names against your data, not numexpr builtins.","Reference the variable through @local if it is a Python variable with a non-clashing name."],"exampleFix":"# before\ndf.query('log > 2', engine='numexpr')\n\n# after\ndf2 = df.rename(columns={'log': 'log_value'})\ndf2.query('log_value > 2')","handlingStrategy":"validation","validationCode":"from pandas.core.computation.engines import _ne_builtins\n\ndef check_no_builtin_clash(expr, columns):\n    clashes = set(map(str, columns)) & _ne_builtins\n    if clashes:\n        raise ValueError(f'Column names clash with numexpr builtins: {clashes}')","typeGuard":"from pandas.core.computation.engines import _ne_builtins\n\ndef has_builtin_clash(columns) -> bool:\n    return bool(set(map(str, columns)) & _ne_builtins)","tryCatchPattern":"from pandas.errors import NumExprClobberingError\ntry:\n    result = df.query('log > 2', engine='numexpr')\nexcept NumExprClobberingError:\n    result = df.query('log > 2', engine='python')","preventionTips":["Avoid naming columns after math/reduction functions (log, sum, max, min, exp).","Fall back to engine='python' when schema clashes are unavoidable.","Rename clash columns before query/eval."],"tags":["numexpr","eval","query","builtin-clash","name-collision"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}