pandas-dev/pandas · error · ValueError
cannot process expression [{self.expr}], [{self}] is not a v
Error message
cannot process expression [{self.expr}], [{self}] is not a valid condition What it means
Raised by PyTablesExpr.evaluate in pandas.core.computation.pytables when pruning the term tree toward a ConditionBinOp raises AttributeError - meaning the expression could not be reduced to a valid numexpr condition. The most common cause is a syntactically valid but semantically empty or non-conditional expression (e.g. a bare column reference, a constant, or an arithmetic-only tree that yields no comparison). It is a ValueError chained from the AttributeError.
Source
Thrown at pandas/core/computation/pytables.py:646
self.env,
queryables=queryables,
parser="pytables",
engine="pytables",
encoding=encoding,
)
self.terms = self.parse()
def __repr__(self) -> str:
if self.terms is not None:
return pprint_thing(self.terms)
return pprint_thing(self.expr)
def evaluate(self):
"""create and return the numexpr condition and filter"""
try:
self.condition = self.terms.prune(ConditionBinOp)
except AttributeError as err:
raise ValueError(
f"cannot process expression [{self.expr}], [{self}] "
"is not a valid condition"
) from err
try:
self.filter = self.terms.prune(FilterBinOp)
except AttributeError as err:
raise ValueError(
f"cannot process expression [{self.expr}], [{self}] "
"is not a valid filter"
) from err
return self.condition, self.filter
class TermValue:
"""hold a term value that we use to construct a condition/filter"""
def __init__(self, value, converted, kind: str) -> None:View on GitHub (pinned to 71959b8cb9)
Solutions
- Ensure the where expression is a boolean condition: where='a > 0', where='a == 5', where='(a > 0) & (b < 10)'.
- If you want non-null filtering, use an explicit condition: where='a == a' (NaN-aware) or precompute a notna column.
- Validate the where string before passing: ensure it contains a comparison or boolean operator.
- For bare column references, read the frame and use the column as a mask: df[df['a'].notna()].
Example fix
# before
store.select('df', where='a') # ValueError: cannot process expression, not a valid condition
# after (make it a condition)
store.select('df', where='a > 0')
# or non-null:
store.select('df', where='a == a') Defensive patterns
Strategy: validation
Validate before calling
import re
def assert_is_condition(where: str) -> str:
operators = ('>', '<', '>=', '<=', '==', '!=', ' in ', ' not in ')
if not any(op in where for op in operators):
raise ValueError(f'where must contain a comparison; got {where!r}')
return where Type guard
def is_condition_expression(where: str) -> bool:
operators = ('>', '<', '>=', '<=', '==', '!=', ' in ', ' not in ')
return isinstance(where, str) and any(op in where for op in operators)
Try / catch
try:
store.select('df', where=where)
except ValueError as e:
if 'is not a valid condition' in str(e):
df = store.get('df')
result = df[df[where] > 0] if where in df.columns else df
else:
raise Prevention
- Always include a comparison operator in where clauses.
- Avoid bare column references or constants as where strings.
- For truthy filtering, precompute a boolean column and compare to True.
When it happens
Trigger: store.select('df', where='a') (bare column, no comparison); store.select('df', where='5'); store.select('df', where='a + b') (arithmetic with no comparison); expressions that resolve to a term rather than a boolean condition.
Common situations: Building where strings programmatically and forgetting the comparison operator; passing a column name alone expecting it to mean 'is truthy'; typo that drops the operator.
Related errors
- name {self.name!r} is not defined
- arithmetic operations are not supported inside an HDFStore '
- Cannot compare {conv_val} of type {type(conv_val)} to {kind}
- query term is not valid [{self}]
- passing a filterable condition to a non-table indexer [{self
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/d0352ab316d7f81d.
Report an issue: GitHub.