{"record":{"id":"d0352ab316d7f81d","repo":"pandas-dev/pandas","slug":"cannot-process-expression-self-expr-self","errorCode":null,"errorMessage":"cannot process expression [{self.expr}], [{self}] is not a valid condition","messagePattern":"cannot process expression \\[(.+?)\\], \\[(.+?)\\] is not a valid condition","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/computation/pytables.py","lineNumber":646,"sourceCode":"                self.env,\n                queryables=queryables,\n                parser=\"pytables\",\n                engine=\"pytables\",\n                encoding=encoding,\n            )\n            self.terms = self.parse()\n\n    def __repr__(self) -> str:\n        if self.terms is not None:\n            return pprint_thing(self.terms)\n        return pprint_thing(self.expr)\n\n    def evaluate(self):\n        \"\"\"create and return the numexpr condition and filter\"\"\"\n        try:\n            self.condition = self.terms.prune(ConditionBinOp)\n        except AttributeError as err:\n            raise ValueError(\n                f\"cannot process expression [{self.expr}], [{self}] \"\n                \"is not a valid condition\"\n            ) from err\n        try:\n            self.filter = self.terms.prune(FilterBinOp)\n        except AttributeError as err:\n            raise ValueError(\n                f\"cannot process expression [{self.expr}], [{self}] \"\n                \"is not a valid filter\"\n            ) from err\n\n        return self.condition, self.filter\n\n\nclass TermValue:\n    \"\"\"hold a term value that we use to construct a condition/filter\"\"\"\n\n    def __init__(self, value, converted, kind: str) -> None:","sourceCodeStart":628,"sourceCodeEnd":664,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/computation/pytables.py#L628-L664","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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()]."],"exampleFix":"# before\nstore.select('df', where='a')  # ValueError: cannot process expression, not a valid condition\n\n# after (make it a condition)\nstore.select('df', where='a > 0')\n# or non-null:\nstore.select('df', where='a == a')","handlingStrategy":"validation","validationCode":"import re\n\ndef assert_is_condition(where: str) -> str:\n    operators = ('>', '<', '>=', '<=', '==', '!=', ' in ', ' not in ')\n    if not any(op in where for op in operators):\n        raise ValueError(f'where must contain a comparison; got {where!r}')\n    return where","typeGuard":"def is_condition_expression(where: str) -> bool:\n    operators = ('>', '<', '>=', '<=', '==', '!=', ' in ', ' not in ')\n    return isinstance(where, str) and any(op in where for op in operators)\n","tryCatchPattern":"try:\n    store.select('df', where=where)\nexcept ValueError as e:\n    if 'is not a valid condition' in str(e):\n        df = store.get('df')\n        result = df[df[where] > 0] if where in df.columns else df\n    else:\n        raise","preventionTips":["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."],"tags":["pandas","hdf5","pytables","where","condition"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}