Skip to content

TST/API/BUG: resolve scoping issues in pytables query where rhs is a compound selection or scoped variable #5566

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

Merged
merged 1 commit into from
Nov 21, 2013

Conversation

jreback
Copy link
Contributor

@jreback jreback commented Nov 21, 2013

e.g. 'l1=selection.index' and 'l1=l', where l = selection.index were failing

example reproduced here:
http://stackoverflow.com/questions/20111542/selecting-rows-from-an-hdfstore-given-list-of-indexes

In [5]: parms = DataFrame({ 'A' : [1,1,2,2,3] })

In [6]: parms
Out[6]: 
   A
0  1
1  1
2  2
3  2
4  3

In [7]: parms.to_hdf('parms.hdf','df',mode='w',format='table',data_columns=['A'])

In [8]: selection = pd.read_hdf('parms.hdf','df',where='A=[2,3]')

In [9]: selection
Out[9]: 
   A
2  2
3  2
4  3

In [10]: hist = DataFrame(np.random.randn(25,1),columns=['data'],
   ....: index=MultiIndex.from_tuples([ (i,j) for i in range(5) for j in range(5) ],
   ....: names=['l1','l2']))

In [11]: hist
Out[11]: 
           data
l1 l2          
0  0   1.232358
   1  -2.677047
   2  -0.168854
   3   0.538848
   4  -0.678224
1  0   0.092575
   1   1.297578
   2  -1.489906
   3  -1.380054
   4   0.701762
2  0   1.397368
   1   0.198522
   2   1.034036
   3   0.650406
   4   1.823683
3  0   0.045635
   1  -0.213975
   2  -1.221950
   3  -0.145615
   4  -1.187883
4  0  -0.782221
   1  -0.626280
   2  -0.331885
   3  -0.975978
   4   2.006322

this works in 0.12

In [15]: pd.read_hdf('hist.hdf','df',where=pd.Term('l1','=',selection.index.tolist()))
Out[15]: 
           data
l1 l2          
2  0   1.397368
   1   0.198522
   2   1.034036
   3   0.650406
   4   1.823683
3  0   0.045635
   1  -0.213975
   2  -1.221950
   3  -0.145615
   4  -1.187883
4  0  -0.782221
   1  -0.626280
   2  -0.331885
   3  -0.975978
   4   2.006322

This works in 0.13 as well

In [16]: pd.read_hdf('hist.hdf','df',where='l1=selection.index')
Out[16]: 
           data
l1 l2          
2  0   1.397368
   1   0.198522
   2   1.034036
   3   0.650406
   4   1.823683
3  0   0.045635
   1  -0.213975
   2  -1.221950
   3  -0.145615
   4  -1.187883
4  0  -0.782221
   1  -0.626280
   2  -0.331885
   3  -0.975978
   4   2.006322

             compound selection or scoped variables

             e.g. 'l1=selection.index' and 'l1=l', where l = selection.index
                  were failing
jreback added a commit that referenced this pull request Nov 21, 2013
TST/API/BUG: resolve scoping issues in pytables query where rhs is a compound selection or scoped variable
@jreback jreback merged commit 7379833 into pandas-dev:master Nov 21, 2013
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

Successfully merging this pull request may close these issues.

1 participant