In that case, I wouldn't bother having the DAL create a Rows object.
Instead, the database cursor will return a list of tuples, which you can
feed directly to numpy to create an array. There are two approaches to do
this:
import numpy as np
my_array = np.asarray(db.executesql(db(query)._select(*fields)))
When you call ._select() instead of .select(), it simply returns the SQL
string, which then gets passed to db.executesql(), which returns the raw
results from the database (i.e., a list of tuples) without any further
processing by the DAL.
A similar option is to use the "processor" argument to .select(), which
allows you to specify a custom processor rather than having the DAL create
a Rows object:
def np_array(records, fields, columns, cacheable):
return np.asarray(records)
my_array = db(query).select(*fields, processor=np_array)
In the above case, the DAL will take the raw results from the database and
pass them to the custom np_array function.
Anthony
On Thursday, January 1, 2015 4:07:23 PM UTC-5, aapaap wrote:
>
> thanks Anthony,
>
> No, I don't need a list of dictionairies.
> From your question, I assume there's also a way to get a plain table ?
>
> I need a list of lists or even better a 2D-numpy array (so I can easily
> perform some conversions).
> The final list of lists (or numpy array) must be converted to a csv file
> (by a service)
>
> cheers,
> Stef
>
>
> On 01-Jan-15 21:22, Anthony wrote:
>
> The problem is that you call .as_list(), which converts to a list of
> dictionaries, and dictionaries do not preserve the order of keys. Do you
> need a list of dictionaries?
>
> On Thursday, January 1, 2015 3:09:22 PM UTC-5, aapaap wrote:
>>
>> hello,
>>
>> I'm using dygraph to plot a number of parameters.
>> Dygraph needs a csv file as it's input.
>> So I made a service:
>>
>> @service.csv
>> def service_platdak():
>> ToDay = date.today()
>> Tomorrow = ( ToDay + timedelta (1) )
>>
>> Fields = [ db.Compare_Model.Date,
>> db.Compare_Model.M2,db.Compare_Model.M2_s1 ]
>> Rows = db ( ( db.Compare_Model.Date >= ToDay ) &
>> ( db.Compare_Model.Date < Tomorrow ) &
>> ( db.Compare_Model.M2 > 0.01 ) ).select(
>> *Fields,
>> orderby = db.Compare_Model.Date ).as_list()
>> return Rows
>>
>> This works almost, except the order of the fileds is not maintained (M2
>> and M2_s1 are exchanged):
>>
>> Date,M2_s1,M2
>> 2015-01-01 09:20:00,,0.666666666667
>> 2015-01-01 09:30:00,,3.92857142857
>> 2015-01-01 09:40:00,,8.5
>> ....
>>
>> is there a way (other than raw SQL) to maintain the column order ?
>>
>> thanks,
>> Stef
>>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.