pandas-dev / pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
https://pandas.pydata.org
BSD 3-Clause "New" or "Revised" License
43.73k stars 17.95k forks source link

Should HDFStore.select respect local variable evaluation rules like query/eval? #6906

Open cpcloud opened 10 years ago

cpcloud commented 10 years ago

example from #6901:

test.csv

title,hits
Al Lawson',30
'Blind' Willie McTell,20
df = pd.read_csv('test.csv', index_col=0)
store = pd.HDFStore('test.h5')
store.append('df', df)

should querying work the same as query/eval for select queries?

title = "Al Lawson'"
result = store.select('df', 'index == title')

or

result = store.select('df', 'index == @title')

the latter currently doesn't work

jreback commented 10 years ago

can u show what title is

cpcloud commented 10 years ago

done

ariddell commented 10 years ago

Thanks for your work on this. I realize querying strings isn't the most prominent use case.

I'll mention again that grabbing a variable from locals is something one almost never sees in Python (although it does occur in R a bit -- which might be something of a warning).

Here's a parallel case in the standard library in the sqlite API:

# Do this instead
t = ('RHAT',)
c.execute('SELECT * FROM stocks WHERE symbol=?', t)
print(c.fetchone())