A Dilluns 16 Octubre 2006 21:15, Daniel Mahler va escriure:
> Is there a way to retrive  data from a table sorted on a column without
> having to sort in memory?
> It seems if a column is indexed one should be able to just walk the index,
> but I do not see anything in the docs that would do this.

This is not documented because indexes are part of *internal* information of 
pytables, and not meant for being accessed by users. If you want to have to a 
sorted column, the best is to sort it and place in a separate container (an 
Array, EArray or CArray could be good candidates).

Moreover, the indexes in pytables does not completely sort the columns (the 
cost for doing a complete sort for very large columns can be too expensive), 
so you cannot trust on them in order to retrieve a sorted version of the 
column.

Having said that, you can still access this data (beware, at your own risk!) 
by using File.getNode() method. For example, I've a file with a table and 2 
indexed columns, like this:

$ h5ls -r data.nobackup/std-rnd-1m.h5
/_i_table                Group
/_i_table/col2           Group
/_i_table/col2/indices   Dataset {10/Inf, 100000}
/_i_table/col2/sorted    Dataset {10/Inf, 100000}
/_i_table/col4           Group
/_i_table/col4/indices   Dataset {10/Inf, 100000}
/_i_table/col4/sorted    Dataset {10/Inf, 100000}
/table                   Dataset {1000000/Inf}

The (partially) sorted information is in the 'sorted' EArrays, but the paths 
to access them are hidden when you use the natural naming. However, you can 
still access them by using the next trick:

>>> f=tables.openFile("data.nobackup/std-rnd-1m.h5")
>>> scol=f.getNode('/_i_table/col4/sorted')
>>> scol
IndexArray(path=/_i_table/col4/sorted)
  atom = Atom(dtype='Float64', shape=(0, 100000L), flavor='numarray')
  nrows = 10
  nelemslice = 100000
  chunksize = 2000
  byteorder = 'little'

But again, this is data that is not meant for public consumption. You have 
been warned!.

Cheers,

-- 
>0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 "-"

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Pytables-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to