A Saturday 26 January 2008, Vince Fulco escrigué:
> Dear Pytable Experts-
>
> Would someone provide a trailhead or working example of a condition
> (using row iterators I believe), whereby a row's field could be
> compared to a prior row's field?  I.E. if a river's average
> temperature today is > than the average temp yesterday, fetch all
> fields from today.  I would welcome examples of even more complex
> queries.

This is not possible right now, and frankly, it would be rather messy to 
implement for all the iterators, not because the difficulty of 
accessing previous values in rows (all the I/O in tables is buffered, 
so it would be just a matter of using values in previous rows), but 
because the .where() iterators are meant to deal with values on a 
single row (since NumExpr, the row-by-row fast evaluator, is used 
behind the scenes).

However, you have a couple of options here:

1) Compute your own trailhead on the average temp on-the-flight.  For 
example:

hist_temp = []
for row in table:
    hist_temp.append((row['temp'], row['time']))
    avg_temp_yesterday = your_computation(row, hist_temp)
    if row['temp'] < avg_temp_yesterday:
        ....

2) Precompute and add a column on your table with the trailhead average 
temp.  For example:

table2 = add_temptrailhead(table)  # adds 'avg_tmp_yesterday' column
for row in table2.where('temp < avg_tmp_yesterday'):
    ...

Option 1) doesn't need to rebuild the table, but selections can be 
expensive.  With option 2) you have to regenerate the table, but once 
this is done, selects can be very fast because you can use in-kernel 
selections.

HTH,

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

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to