{"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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/computation/engines.py#L25-L61","documentation":"Raised by _check_ne_builtin_clash (called from the numexpr engine path of DataFrame.eval/query) when a column name in the expression collides with a numexpr builtin name (the union of MATHOPS and REDUCTIONS, e.g. sum, min, max, log, exp, sin). The check is a footgun guard: numexpr would otherwise silently treat `sum` as the reduction instead of the column, returning a scalar instead of per-row values. NumExprClobberingError is a ValueError subclass.","triggerScenarios":"df.eval('sum + 1') where 'sum' is a column; df.query('min > 5'); df.eval('log > 0') with a column named 'log'. Only triggers with engine='numexpr' (default when numexpr is installed); the python engine does not raise.","commonSituations":"Domain columns named after math/reduction functions (common in finance/logs, statistics with 'min'/'max'); legacy datasets; reserved-word column names from CSVs.","solutions":["Rename the column: df = df.rename(columns={'sum': 'total'}).","Reference it via @ local: total = df['sum']; df.eval('total + 1').","Force the python engine: df.eval('sum + 1', engine='python').","Quote with backticks (pandas supports `sum` in eval for non-identifier names but it does not bypass this builtin check — rename is the safe option)."],"exampleFix":"// before\ndf.eval('sum + 1')\n// after\ndf = df.rename(columns={'sum': 'total'})\ndf.eval('total + 1')","handlingStrategy":"validation","validationCode":"import pandas.core.computation.expr as _expr\nreserved = set(_expr.MATHOPS) | set(_expr.REDUCTIONS)\nclash = set(df.columns) & reserved\nif clash:\n    raise ValueError(f'rename columns clashing with numexpr builtins: {clash}')","typeGuard":null,"tryCatchPattern":"try:\n    result = df.eval(expr, engine='numexpr')\nexcept NumExprClobberingError:\n    result = df.eval(expr, engine='python')","preventionTips":["Avoid naming columns after math/reduction words (sum, min, max, log, sin).","Rename or use @ local variables for clashing columns before eval/query.","Be aware the python engine does not raise this error."],"tags":["numexpr-clobbering","eval","query","builtin-clash","column-naming"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}