pandas-dev/pandas · error · NotImplementedError
arithmetic operations are not supported inside an HDFStore…
Error message
arithmetic operations are not supported inside an HDFStore 'where' filter; instead store a precomputed column as a data_column and query that, or read the data and apply the filter in pandas (e.g. df[df['A'] % 3 == 0]).
What it means
Raised in the PyTables BinOp.prune when self.op is in ARITH_OPS_SYMS ('+', '-', '*', '/', '**', '//', '%'). HDFStore 'where' filters are translated into PyTables/numexpr conditions on stored data_columns; arithmetic inside the condition would require computing new columns on disk, which PyTables does not support. Per GH#41100, rather than grow the query grammar the team chose to raise NotImplementedError with a pointer to alternatives, since PyTables support is in maintenance mode.
Solutions
- Precompute the arithmetic result into a new column and store it as a data_column: df['A_plus_B'] = df['A'] + df['B']; store.put('df', df, format='table', data_columns=['A_plus_B']); store.select('df', where='A_plus_B > 1').
- Read the data and filter in pandas: df = store.get('df'); df[df['A'] + df['B'] > 1].
- Avoid HDFStore where filters for derived expressions; use Parquet + boolean indexing for new code.
Example fix
// before
store.select('df', where='A + B > 1')
// after
df['A_plus_B'] = df['A'] + df['B']
store.put('df', df, format='table', data_columns=['A_plus_B'])
store.select('df', where='A_plus_B > 1')
# or simply
df = store.get('df')
df[df['A'] + df['B'] > 1] Defensive patterns
Strategy: validation
Validate before calling
from pandas.core.computation.ops import ARITH_OPS_SYMS
import re
def where_has_arith(where: str) -> bool:
# crude check: any arithmetic operator token outside string literals
return bool(re.search(r'[+\-*/%]|\*\*|//', where))
assert not where_has_arith(where_clause), 'arithmetic is not allowed in HDFStore where clauses' Type guard
from pandas.core.computation.ops import ARITH_OPS_SYMS
def is_arith_op(op: str) -> bool:
return op in ARITH_OPS_SYMS Try / catch
try:
store.select('df', where='A + B > 1')
except NotImplementedError as e:
if 'arithmetic operations are not supported' in str(e):
df = store.get('df')
df[(df['A'] + df['B']) > 1]
else:
raise Prevention
- Precompute derived columns and store them as data_columns.
- Read fixed/complex predicates into pandas and filter in memory.
- Reject arithmetic tokens in where-clause builders.
When it happens
Trigger: store.select('df', where='A + B > 1'), store.select('df', where='A % 3 == 0'), or any arithmetic operator inside the where clause. Also df.query() evaluated against an HDFStore-backed TermVisitor.
Common situations: Porting a pandas boolean expression (df[df['A'] + df['B'] > 1]) to an HDFStore select without precomputing. Expecting numexpr/PyTables to evaluate derived expressions. Trying to filter on a ratio (A/B) without a stored column.
Related errors
- Cannot compare of type to column
- cannot subscript with
- cannot use an invert condition when passing to numexpr
- name is not defined
- passing a filterable condition to a non-table indexer
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/b4214346d172170f.
Report an issue: GitHub.
Appendix: source
Thrown at pandas/core/computation/pytables.py:136
op: str
queryables: dict[str, Any]
condition: str | None
def __init__(self, op: str, lhs, rhs, queryables: dict[str, Any], encoding) -> None:
super().__init__(op, lhs, rhs)
self.queryables = queryables
self.encoding = encoding
self.condition = None
def _disallow_scalar_only_bool_ops(self) -> None:
pass
def prune(self, klass):
if self.op in ARITH_OPS_SYMS:
# GH#41100: arithmetic in a where-clause is not supported. PyTables
# support is in maintenance mode, so rather than grow the query
# grammar we raise with a pointer to a working alternative.
raise NotImplementedError(
"arithmetic operations are not supported inside an HDFStore "
"'where' filter; instead store a precomputed column as a "
"data_column and query that, or read the data and apply the "
"filter in pandas (e.g. df[df['A'] % 3 == 0])."
)
def pr(left, right):
"""create and return a new specialized BinOp from myself"""
if left is None:
return right
elif right is None:
return left
k = klass
if isinstance(left, ConditionBinOp):
if isinstance(right, ConditionBinOp):
k = JointConditionBinOp
elif isinstance(left, k):View on GitHub (pinned to 3b7651241d)