pandas-dev/pandas · error · NumExprClobberingError

Variables in expression "{expr}" overlap with builtins: ({s}

Error message

Variables in expression "{expr}" overlap with builtins: ({s})

What it means

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.

Source

Thrown at pandas/core/computation/engines.py:43

_ne_builtins = frozenset(MATHOPS + REDUCTIONS)


def _check_ne_builtin_clash(expr: Expr) -> None:
    """
    Attempt to prevent foot-shooting in a helpful way.

    Parameters
    ----------
    expr : Expr
        Terms can contain
    """
    names = expr.names
    overlap = names & _ne_builtins

    if overlap:
        s = ", ".join([repr(x) for x in overlap])
        raise NumExprClobberingError(
            f'Variables in expression "{expr}" overlap with builtins: ({s})'
        )


class AbstractEngine(metaclass=abc.ABCMeta):
    """Object serving as a base class for all engines."""

    has_neg_frac = False

    def __init__(self, expr) -> None:
        self.expr = expr
        self.aligned_axes = None
        self.result_type = None
        self.result_name = None

    def convert(self) -> str:
        """
        Convert an expression for evaluation.

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Rename the column to avoid the builtin name: `df.rename(columns={'log':'log_val'})`.
  2. Switch the engine to python: `df.query('log > 2', engine='python')` which resolves names against your data, not numexpr builtins.
  3. Reference the variable through @local if it is a Python variable with a non-clashing name.

Example fix

# before
df.query('log > 2', engine='numexpr')

# after
df2 = df.rename(columns={'log': 'log_value'})
df2.query('log_value > 2')
Defensive patterns

Strategy: validation

Validate before calling

from pandas.core.computation.engines import _ne_builtins

def check_no_builtin_clash(expr, columns):
    clashes = set(map(str, columns)) & _ne_builtins
    if clashes:
        raise ValueError(f'Column names clash with numexpr builtins: {clashes}')

Type guard

from pandas.core.computation.engines import _ne_builtins

def has_builtin_clash(columns) -> bool:
    return bool(set(map(str, columns)) & _ne_builtins)

Try / catch

from pandas.errors import NumExprClobberingError
try:
    result = df.query('log > 2', engine='numexpr')
except NumExprClobberingError:
    result = df.query('log > 2', engine='python')

Prevention

When it happens

Trigger: `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'.

Common situations: Columns named after math functions (log, exp, sin, max, min, sum, count). Dataset schema collisions discovered after switching to numexpr for speed.

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/7880f7da5a1d744e. Report an issue: GitHub.