google-cloud-python icon indicating copy to clipboard operation
google-cloud-python copied to clipboard

feature request: pandas connector

Open tswast opened this issue 6 years ago • 8 comments

Is your feature request related to a problem? Please describe.

I'd like to be able to run a query against a Spanner database and download (possibly large-ish -- MBs to GBs) results to a pandas DataFrame. Specifically, I'd like to eventually use this as a component in an ibis connector, but it'd also be useful for general data processing pipelines.

Describe the solution you'd like

It seems that StreamedResultSet is the most natural place to put a to_dataframe method, similar to the RowIterator.to_dataframe method in the BigQuery client library.

Since pandas needn't be required to use this client library, the import should be conditional

https://github.com/googleapis/python-bigquery/blob/fb401bd94477323bba68cf252dd88166495daf54/google/cloud/bigquery/table.py#L29-L32

and the dependency listed in "extras".

https://github.com/googleapis/python-bigquery/blob/fb401bd94477323bba68cf252dd88166495daf54/setup.py#L50

Describe alternatives you've considered

It's possible this is simpler than realized, so maybe could just be a code sample.

If there were a SQLAlchemy connector (a much bigger project than read-only pandas dataframe), then pandas support is basically free via pandas.read_sql.

Additional context

Related StackOverflow questions:

  • https://stackoverflow.com/questions/63041922/how-do-i-run-a-query-in-cloud-spanner-and-download-the-results-to-a-pandas-dataf
  • https://stackoverflow.com/questions/57421665/how-to-query-spanner-and-get-metadata-especially-columns-names

tswast avatar Oct 14 '20 18:10 tswast

Thank you for your patience!

We've started work on an SQLAlchemy connector and will continue with work for a couple of quarters. As mentioned, this should cover your use case.

larkee avatar Dec 15 '20 02:12 larkee

Thank you for your patience!

We've started work on an SQLAlchemy connector and will continue with work for a couple of quarters. As mentioned, this should cover your use case.

I just stumbled across this. I've wanted this for a long time and it would be a game changer for my company. Is there an issue we can track for updates on this development?

daniellehanks avatar Feb 26 '21 08:02 daniellehanks

@daniellehanks Thank you for sharing your interest in this work! The SQLAlchemy connector work is being done here. You can follow the progress there. As noted in the README, it is still under production and is not ready for production use.

larkee avatar Mar 09 '21 11:03 larkee

@larkee @vi3k6i5 : Given python-spanner-SQLAlchemy is now GA, is this use case covered?

ansh0l avatar Jan 17 '22 04:01 ansh0l

It'd be good to check that it does indeed work with pandas.read_sql in a code sample or something. I would expect it to work, though.

Since Spanner is row-oriented, I don't see there being all that much of a performance reason to avoid SQLAlchemy (compared to BigQuery which is column-oriented).

tswast avatar Jan 18 '22 15:01 tswast

@IlyaFaer Can you check for this?

asthamohta avatar Jul 08 '22 08:07 asthamohta

This issue was moved from the following repo as part of the monorepo migration: googleapis/python-spanner

chalmerlowe avatar Mar 02 '26 14:03 chalmerlowe

Closing due to inactivity

parthea avatar Apr 28 '26 18:04 parthea