pandas-dev/pandas · error · NotImplementedError

Unary addition not supported

Error message

Unary addition not supported

What it means

Raised by PyTablesExprVisitor.visit_UnaryOp in pandas.core.computation.pytables when the AST node is ast.UAdd (a unary '+' prefix like '+x'). The visitor handles ast.Not/ast.Invert as '~' and ast.USub by negating a constant, but explicit unary plus is not supported in HDFStore where clauses and raises NotImplementedError.

Source

Thrown at pandas/core/computation/pytables.py:466

    term_type: ClassVar[type[Term]] = Term

    def __init__(self, env, engine, parser, **kwargs) -> None:
        super().__init__(env, engine, parser)
        for bin_op in self.binary_ops:
            bin_node = self.binary_op_nodes_map[bin_op]
            setattr(
                self,
                f"visit_{bin_node}",
                lambda node, bin_op=bin_op: partial(BinOp, bin_op, **kwargs),
            )

    def visit_UnaryOp(self, node, **kwargs) -> ops.Term | UnaryOp | None:
        if isinstance(node.op, (ast.Not, ast.Invert)):
            return UnaryOp("~", self.visit(node.operand))
        elif isinstance(node.op, ast.USub):
            return self.const_type(-self.visit(node.operand).value, self.env)
        elif isinstance(node.op, ast.UAdd):
            raise NotImplementedError("Unary addition not supported")
        # TODO: return None might never be reached
        return None

    def visit_Index(self, node, **kwargs):
        return self.visit(node.value).value

    def visit_Assign(self, node, **kwargs):
        cmpr = ast.Compare(
            ops=[ast.Eq()], left=node.targets[0], comparators=[node.value]
        )
        return self.visit(cmpr)

    def visit_Subscript(self, node, **kwargs) -> ops.Term:
        # only allow simple subscripts

        value = self.visit(node.value)
        slobj = self.visit(node.slice)
        try:

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Remove the unary '+' from the expression: where='a > 0' instead of where='+a > 0'.
  2. If the '+' was meant to coerce type, precompute the column with the desired dtype and store it.
  3. Simplify the where clause to plain identifiers and comparison operators.

Example fix

# before
store.select('df', where='+amount > 0')  # NotImplementedError: Unary addition not supported

# after
store.select('df', where='amount > 0')
Defensive patterns

Strategy: validation

Validate before calling

import re

def strip_unary_plus(where: str) -> str:
    return re.sub(r'(?<![A-Za-z0-9_)\]\s])\s*\+(?=[A-Za-z_(])', '', where)

where = strip_unary_plus(where)

Type guard

def has_unary_plus(where: str) -> bool:
    import re
    return bool(re.search(r'(?<![A-Za-z0-9_)\]\s])\s*\+(?=[A-Za-z_(])', where))

Try / catch

try:
    store.select('df', where=where)
except NotImplementedError as e:
    if 'Unary addition not supported' in str(e):
        where = strip_unary_plus(where)
        store.select('df', where=where)
    else:
        raise

Prevention

When it happens

Trigger: store.select('df', where='+a > 0'); pd.read_hdf(path, where='+index == 5'). Anywhere a leading '+' appears before an identifier in a pytables where expression.

Common situations: Copy-pasting expressions from numeric code that uses unary '+' for emphasis/clarity; programmatic generation of where strings that prepend '+' to numeric tokens.

Related errors


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