0

I am using Python 2.7, and trying to perform a PyTables query:

#Here the condition
selectedIndex = [1,6,7,9]
condition = 'IndexColumn in selectedIndex'

#here the query
for x1 in tab.where(condition,selectedIndex):
   ...
   ...
   ...

And I am getting:

TypeError: argument of type 'VariableNode' is not iterable

From the documentation about pytables, I am trying to use this:

Table.where(condition, condvars=None, start=None, stop=None, step=None)

And that:

condition = 'col1 == "AAAA"'

for record in table.where(condition):  # TypeError in Python3
    #do something with "record"

What I am doing wrong?

codeKiller
  • 5,493
  • 17
  • 60
  • 115
  • Have you tried using the `DataFrame.query` method instead? I don't think `where` takes string arguments ... – filmor Mar 07 '14 at 10:07

1 Answers1

1

I think the correct way to do the in-kernel query using a string argument in your case would be:

conditon="(IndexColumn==1)|(IndexColumn==6)|(IndexColumn==7)|(IndexColumn==9)"

and IndexColumn needs to be the actual name of the column as specfied in your IsDescription class. I believe the python condition "a in b" is not valid for Pytablles queries

EDIT concerning your comment:

"".join(["(IndexColumn==%i)|"%j for j in selectedIndex])[:-1]

should give you the correct string for the query.

Ben K.
  • 1,160
  • 6
  • 20
  • This is a problem then, because if I need to declare each condition, I cannot send the whole `selectedIndex` doing something like this `def processTable(selectedIndex)`, am I right? – codeKiller Mar 07 '14 at 10:41
  • no you can just concatenate the appropriate strings with something like this: ''.join(["(IndexColumn==%i)|"%j for j in selectedIndex])[:-1] – Ben K. Mar 07 '14 at 12:09