pandas-dev/pandas · error · SyntaxError

left hand side of an assignment must be a single resolvable…

Error message

left hand side of an assignment must be a single resolvable name

What it means

Raised by visit_Assign() when, after visiting the assignment target, the resolved assigner name is None. This happens when the left-hand side Name resolves to something whose .name attribute is None or which yields no usable name — meaning the lhs is not a single resolvable name. It is a secondary guard after the ast.Name check, covering cases where the Name node exists but does not resolve to a concrete identifier.

Solutions

  1. Ensure the lhs is a simple, defined column name that pandas can resolve.
  2. Simplify the assignment lhs to a plain identifier string.
  3. If building expressions programmatically, validate that every assignment target is a non-empty name.

Example fix

// before
df.eval('@obj = col_a + col_b')  # obj resolves to nameless term

// after
df.eval('new_col = col_a + col_b')
Defensive patterns

Strategy: validation

Validate before calling

import re
def lhs_is_resolvable_name(expr: str) -> bool:
    m = re.match(r'^\s*([A-Za-z_]\w*)\s*=', expr)
    return bool(m) and m.group(1) != ''
if not lhs_is_resolvable_name(expr):
    raise ValueError('Assignment lhs must resolve to a single name')
df.eval(expr)

Try / catch

try:
    df.eval(expr)
except SyntaxError as e:
    if 'resolvable name' in str(e):
        # simplify the lhs
        ...

Prevention

When it happens

Trigger: Assignment lhs is an ast.Name whose id resolves to an object with name=None, or a corner case where getattr(assigner, 'name', assigner) returns None. Rare in practice; usually preceded by the ast.Name check.

Common situations: Edge cases with custom resolvers or scope objects that return Terms with no name; programmatic expression construction that produces malformed Name nodes.

Related errors


AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11). Data as JSON: /api/errors/02c7712490254a56. Report an issue: GitHub.

Appendix: source

Thrown at pandas/core/computation/expr.py:637

        set the assigner at the top level, must be a Name node which
        might or might not exist in the resolvers

        """
        if len(node.targets) != 1:
            raise SyntaxError("can only assign a single expression")
        if not isinstance(node.targets[0], ast.Name):
            raise SyntaxError("left hand side of an assignment must be a single name")
        if self.env.target is None:
            raise ValueError("cannot assign without a target object")

        try:
            assigner = self.visit(node.targets[0], **kwargs)
        except UndefinedVariableError:
            assigner = node.targets[0].id

        self.assigner = getattr(assigner, "name", assigner)
        if self.assigner is None:
            raise SyntaxError(
                "left hand side of an assignment must be a single resolvable name"
            )

        return self.visit(node.value, **kwargs)

    def visit_Attribute(self, node, **kwargs):
        attr = node.attr
        value = node.value

        ctx = node.ctx
        if isinstance(ctx, ast.Load):
            # resolve the value
            visited_value = self.visit(value)
            if hasattr(visited_value, "value"):
                resolved = visited_value.value
            else:
                resolved = visited_value(self.env)
            try:

View on GitHub (pinned to 3b7651241d)