pandas-dev/pandas · error · ValueError

cannot process expression

Error message

cannot process expression [{self.expr}], [{self}] is not a valid condition

What it means

Raised by PyTablesExpr.evaluate when self.terms.prune(ConditionBinOp) raises AttributeError, meaning the parsed expression cannot be reduced to a numexpr boolean condition. numexpr only handles indexable/data_column comparisons, so an expression that is a bare term, references a non-queryable column, or doesn't bottom out in a comparison produces this ValueError.

Solutions

  1. Rewrite the store with data_columns specifying the columns you query on: store.put('df', df, format='table', data_columns=['A','B']).
  2. Make the where clause a real boolean comparison, e.g. store.select('df', where='A > 5').
  3. If the column is non-queryable, read the frame and filter in pandas: df = store.get('df'); df = df[df.A > 5].
  4. Verify the queryable columns with store.get_storer('df').non_index_axes / data_columns before selecting.

Example fix

// before
store.put('df', df, format='table')
store.select('df', where='A > 5')  # A not a data_column -> invalid condition

// after
store.put('df', df, format='table', data_columns=['A'])
store.select('df', where='A > 5')
Defensive patterns

Strategy: validation

Validate before calling

storer = store.get_storer('df')
queryable = set(getattr(storer, 'data_columns', []) or []) | {storer.index.name} if storer.index.name else set()
needed = {'A'}
missing = needed - queryable
if missing:
    raise ValueError(f'columns not queryable (re-write with data_columns): {missing}')

Try / catch

try:
    selected = store.select('df', where='A > 5')
except ValueError as err:
    if 'is not a valid condition' in str(err):
        df = store.get('df')
        selected = df[df['A'] > 5]
    else:
        raise

Prevention

When it happens

Trigger: store.select('df', where='A') where A is a bare column with no comparison; querying a column that was not stored as a data_column and is not the index; using an expression whose terms are pure FilterBinOps (membership/in-table lookups) that yield no numexpr condition; arithmetic-only predicates.

Common situations: Forgetting to declare data_columns=True when writing the HDF5 table, then trying to where-filter on those columns; mixing a filterable (in) clause with no actual condition; assuming every column is queryable when only indexed columns and declared data_columns are.

Related errors


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

Appendix: 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 3b7651241d)