Read from HDF with empty where throws an error · Issue #26610 · pandas-dev/pandas (original) (raw)

Wanted to be able construct "by hands" and save where condition for later, so declare it as variable. But some times constructed where becomes empty and code throws an error.

Traceback (most recent call last):

File "/home/beforeflight/Coding/Python/venvs/main/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3267, in run_code exec(code_obj, self.user_global_ns, self.user_ns)

File "", line 6, in store.select('df', where = where)

File "/home/beforeflight/Coding/Python/venvs/main/lib/python3.7/site-packages/pandas/io/pytables.py", line 740, in select return it.get_result()

File "/home/beforeflight/Coding/Python/venvs/main/lib/python3.7/site-packages/pandas/io/pytables.py", line 1518, in get_result results = self.func(self.start, self.stop, where)

File "/home/beforeflight/Coding/Python/venvs/main/lib/python3.7/site-packages/pandas/io/pytables.py", line 733, in func columns=columns)

File "/home/beforeflight/Coding/Python/venvs/main/lib/python3.7/site-packages/pandas/io/pytables.py", line 4254, in read if not self.read_axes(where=where, **kwargs):

File "/home/beforeflight/Coding/Python/venvs/main/lib/python3.7/site-packages/pandas/io/pytables.py", line 3443, in read_axes self.selection = Selection(self, where=where, **kwargs)

File "/home/beforeflight/Coding/Python/venvs/main/lib/python3.7/site-packages/pandas/io/pytables.py", line 4815, in init self.terms = self.generate(where)

File "/home/beforeflight/Coding/Python/venvs/main/lib/python3.7/site-packages/pandas/io/pytables.py", line 4828, in generate return Expr(where, queryables=q, encoding=self.table.encoding)

File "/home/beforeflight/Coding/Python/venvs/main/lib/python3.7/site-packages/pandas/core/computation/pytables.py", line 548, in init self.terms = self.parse()

File "/home/beforeflight/Coding/Python/venvs/main/lib/python3.7/site-packages/pandas/core/computation/expr.py", line 766, in parse return self._visitor.visit(self.expr)

File "/home/beforeflight/Coding/Python/venvs/main/lib/python3.7/site-packages/pandas/core/computation/expr.py", line 331, in visit return visitor(node, **kwargs)

File "/home/beforeflight/Coding/Python/venvs/main/lib/python3.7/site-packages/pandas/core/computation/expr.py", line 335, in visit_Module raise SyntaxError('only a single expression is allowed')

File "", line unknown SyntaxError: only a single expression is allowed

When empty string is passed to where - just select whole DataFrame. It may be easily achieved by changing last statement to store.select('df', where = where if where else None). But it would be better to add this checking inside pandas, so user may not worry about it all the times using selection from HDF with where.