TableProxy equivalent to RowProxies

17 views
Skip to first unread message

sumau

unread,
Oct 27, 2019, 7:06:08 AM10/27/19
to sqlalchemy
RowProxy have useful functionality like row.keys() and row['column']

If I use fetchmany/fetchall I return a list of RowProxies. Is the best way of keeping the functionality of RowProxies to convert the list to a pandas data frame? Are there any plans to create "Table"Proxy equivalent to RowProxy?

Mike Bayer

unread,
Oct 27, 2019, 10:48:19 AM10/27/19
to noreply-spamdigest via sqlalchemy


On Sun, Oct 27, 2019, at 7:06 AM, sumau wrote:
RowProxy have useful functionality like row.keys() and row['column']

If I use fetchmany/fetchall I return a list of RowProxies. Is the best way of keeping the functionality of RowProxies to convert the list to a pandas data frame? Are there any plans to create "Table"Proxy equivalent to RowProxy?


The "row proxy" is no longer a "proxy" in 1.4, however this is an implementation detail that won't be noticable.

The table equivalent is the Table object.  Just like the Row(Proxy) represents a row in a database fetched over, Table represents the structure of the Table, which can be fetched over if you use Table(..., autoload_with=connection).

What this has to do with a dataframe, not really sure, which suggests this is not really what you're asking, so, would use some more specifics.




-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper


To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.


Soumaya Mauthoor

unread,
Oct 27, 2019, 2:49:07 PM10/27/19
to sqlal...@googlegroups.com
With a dataframe you can do df.columns to get the column labels and df[["col1","col2"]] to extract column1 and column2 

rowProxy has similar functionality as explained before

However if I use s= fetchmany() I return a string and it's not possible to do the equivalent s.keys() and s["col1"].

Mike Bayer

unread,
Oct 28, 2019, 12:35:21 PM10/28/19
to noreply-spamdigest via sqlalchemy


On Sun, Oct 27, 2019, at 2:48 PM, Soumaya Mauthoor wrote:
With a dataframe you can do df.columns to get the column labels and df[["col1","col2"]] to extract column1 and column2 

I'm going to guess this means that you're getting the col1/col2 from multiple rows at once.

In python we use a list comprehension to get this:

[(row["col1"], row["col2"]) for row in result.fetchmany()]

also the keys to each row are are present both via row.keys() as well as result.keys().

if you want full matrix operations available to a result set, it's best to load it into a pandas dataframe first, since the "fetch" is an exhaustive operation (e.g. only works once per row).  





sumau

unread,
Oct 28, 2019, 4:07:34 PM10/28/19
to sqlalchemy
Crystal clear thanks!
Reply all
Reply to author
Forward
0 new messages