Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column name prevents use of Table.where() #638

Open
ljleppan opened this issue Jul 5, 2017 · 0 comments
Open

Column name prevents use of Table.where() #638

ljleppan opened this issue Jul 5, 2017 · 0 comments

Comments

@ljleppan
Copy link

ljleppan commented Jul 5, 2017

Using "where" as a column name gives no indication of anything being wrong while creating/filling table, but produces an ValueError when filtering by said column.

Code to demonstrate issue:

from tables import *

class Thing(IsDescription):
    where = StringCol(1)
    where_ = StringCol(1)

h5file = open_file('test.h5', mode='w', title='Test file')
group = h5file.create_group('/', 'test', 'Test')
table = h5file.create_table(group, 'readout', Thing, 'Test')

print("{!r}".format(h5file))

table.row['where'] = "A"
table.row['where_'] = "B"
table.row.append()
table.flush()

table = h5file.root.test.readout

for result in table.where("where_ == b'B'"):
    print(result['where'], result['where_'], "\n") # As expected

for result in table.where("where == b'A'"): # Raises ValueError
    print(result['where'], result['where_']) 

Output:

$ python test.py 
File(filename=test.h5, title='Test file', mode='w', root_uep='/', filters=Filters(complevel=0, shuffle=False, bitshuffle=False, fletcher32=False, least_significant_digit=None))
/ (RootGroup) 'Test file'
/test (Group) 'Test'
/test/readout (Table(0,)) 'Test'
  description := {
  "where": StringCol(itemsize=1, shape=(), dflt=b'', pos=0),
  "where_": StringCol(itemsize=1, shape=(), dflt=b'', pos=1)}
  byteorder := 'little'
  chunkshape := (32768,)

b'A' b'B' 

Traceback (most recent call last):
  File "test.py", line 23, in <module>
    for result in table.where("where == b'A'"):
  File "/home/ljleppan/venv/lib/python3.5/site-packages/tables/table.py", line 1483, in where
    return self._where(condition, condvars, start, stop, step)
  File "/home/ljleppan/venv/lib/python3.5/site-packages/tables/table.py", line 1501, in _where
    compiled = self._compile_condition(condition, condvars)
  File "/home/ljleppan/venv/lib/python3.5/site-packages/tables/table.py", line 1361, in _compile_condition
    "in condition ``%s``" % (condition,))
ValueError: there are no columns taking part in condition ``where == b'A'``
Closing remaining open files:test.h5...done

Python version: 3.5.2
PyTables version: 3.4.2

It's understandable if this is a "wontfix" in terms of allowing the column name, but even then I'd hope for a slightly more informative error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant