GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor(bigquerystorage): `to_dataframe` on an arrow stream uses faster `to_arrow` + `to_pandas`, internally by tswast · Pull Request #9997 · googleapis/google-cloud-python

Conversation

@tswast

@tswast tswast commented Dec 18, 2019

Copy link
Copy Markdown
Contributor

…to_arrow + to_pandas, internally

Towards https://issuetracker.google.com/140579733

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tswast
tswast requested a review from a team December 18, 2019 20:02
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 18, 2019
@tswast tswast added api: bigquerystorage Issues related to the BigQuery Storage API. and removed cla: yes This human has signed the Contributor License Agreement. labels Dec 18, 2019
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 18, 2019
@tswast
tswast requested a review from plamut December 19, 2019 16:25
@tswast tswast assigned plamut Dec 19, 2019
@tswast tswast mentioned this pull request Dec 30, 2019
refactor(bigquery): to_dataframe uses faster to_arrow + to_pandas when pyarrow is available #10027
Merged
@tswast
tswast requested a review from shollyman January 7, 2020 17:20
@tswast
fix(bigquerystorage): to_dataframe on an arrow stream uses 2x faster …
ef291eb
…to_arrow + to_pandas, internally

Towards https://issuetracker.google.com/140579733
@tswast
tswast force-pushed the b140579733-bq-to_dataframe branch from 2009c86 to ef291eb Compare January 7, 2020 17:21
plamut
plamut reviewed Jan 9, 2020
View reviewed changes

@plamut plamut left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me code-wise, but I still need to verify the performance gain on a "big" table (ran out of time in this review pass 😃 ).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@plamut

plamut commented Jan 11, 2020

Copy link
Copy Markdown
Contributor

Unfortunately, I cannot confirm the speedup, the timings with and without this fix are about the same on my machine (i7, 16GB RAM, ~25 Mbs network).

It's probably because I also wasn't able to reproduce the speed difference in the first place using the sample from the issue description (tested on 2x 10e6 table with random floats).

@tswast What data did you use in testing? Maybe I can try with that ...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tswast

tswast commented Jan 13, 2020

Copy link
Copy Markdown
Contributor Author

I'm getting a more modest speed-up than I was getting this past summer, too. It's at least some speedup, though. The taxi cab data has a more variety of data types. I wonder if the latest Pandas does a better job of combining floating point columns with concatenate now?

From a VM in us-central:

sudo apt-get install python3-pip git
pip3 install --upgrade pandas
pip3 install --upgrade pyarrow
pip3 install --upgrade google-cloud-core
pip3 install --upgrade google-api-core[grpc]
git clone https://github.com/tswast/google-cloud-python.git
cd google-cloud-python/bigquery_storage
git checkout b140579733-bq-to_dataframe
pip3 install -e .
cd ../..

benchmark_bqstorage.py

import sys
from google.cloud import bigquery_storage_v1beta1

# TODO(developer): Set the project_id variable.
project_id = 'swast-scratch'
#
# The read session is created in this project. This project can be
# different from that which contains the table.

client = bigquery_storage_v1beta1.BigQueryStorageClient()

# This example reads baby name data from the public datasets.
table_ref = bigquery_storage_v1beta1.types.TableReference()
table_ref.project_id = "swast-scratch"
table_ref.dataset_id = "to_dataframe_benchmark"
table_ref.table_id = "tlc_green_{}pct".format(sys.argv[1])

parent = "projects/{}".format(project_id)
session = client.create_read_session(
    table_ref,
    parent,
    format_=bigquery_storage_v1beta1.enums.DataFormat.ARROW,
    sharding_strategy=(bigquery_storage_v1beta1.enums.ShardingStrategy.LIQUID),
    requested_streams=1,
)  # API request.

reader = client.read_rows(
    bigquery_storage_v1beta1.types.StreamPosition(stream=session.streams[0])
)

dataframe = reader.rows(session).to_dataframe()
print("Got {} rows.".format(len(dataframe.index)))

After this change:

swast@instance-1:~$ time python3 benchmark_bqstorage.py 6
Got 950246 rows.

real    0m7.219s
user    0m3.296s
sys     0m1.564s

swast@instance-1:~$ time python3 benchmark_bqstorage.py 12_5
Got 1980854 rows.

real    0m10.859s
user    0m5.952s
sys     0m2.156s

swast@instance-1:~$ time python3 benchmark_bqstorage.py 25
Got 3963696 rows.

real    0m22.156s
user    0m11.188s
sys     0m4.340s

swast@instance-1:~$ time python3 benchmark_bqstorage.py 50
Got 7917713 rows.

real    0m44.529s
user    0m21.124s
sys     0m8.976s

Before this change:

cd google-cloud-python
git checkout master
cd ..

swast@instance-1:~$ time python3 benchmark_bqstorage.py 6
Got 950246 rows.

real    0m7.301s
user    0m6.572s
sys     0m1.148s

swast@instance-1:~$ time python3 benchmark_bqstorage.py 12_5
Got 1980854 rows.

real    0m13.595s
user    0m12.584s
sys     0m2.056s

swast@instance-1:~$ time python3 benchmark_bqstorage.py 25
Got 3963696 rows.

real    0m26.442s
user    0m24.552s
sys     0m3.904s

swast@instance-1:~$ time python3 benchmark_bqstorage.py 50
Got 7917713 rows.

real    0m50.157s
user    0m48.556s
sys     0m7.876s
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tswast tswast changed the title fix(bigquerystorage): to_dataframe on an arrow stream uses 2x faster … fix(bigquerystorage): to_dataframe on an arrow stream uses faster to_arrow + to_pandas, internally Jan 13, 2020
@tswast tswast changed the title fix(bigquerystorage): to_dataframe on an arrow stream uses faster to_arrow + to_pandas, internally refactor(bigquerystorage): to_dataframe on an arrow stream uses faster to_arrow + to_pandas, internally Jan 13, 2020
@tswast
tswast requested a review from plamut January 13, 2020 20:09
@tswast

tswast commented Jan 13, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I made the swast-scratch.to_dataframe_benchmark.tlc_green_6pct, etc. tables publicly readable, so you should be able to reproduce my results as well.

I've updated the PR title to remove the "2x", as it's a more modest 1.126x speedup.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@plamut

plamut commented Jan 15, 2020

Copy link
Copy Markdown
Contributor

@tswast Thanks for the data, and the benchmarking results!

I was finally able to reproduce a significant difference pretty consistently (~33 seconds vs. ~35 seconds for the 6pct test, for example).

As this was much slower than your results, it became apparent that the network I/O dominated the timings on my end (I'm on a 50 Mbps fiber optic). By shutting down everything that might have affected the average download speed, I was able to bring the variance down by enough to not lose the signal in the noise (didn't initially expect that such measures would be necessary based on the reported 2x gains 🙂).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

plamut
plamut approved these changes Jan 15, 2020
View reviewed changes

@plamut plamut left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The speedup is indeed noticeable 👍

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@plamut
plamut merged commit 121394c into googleapis:master Jan 15, 2020
@tswast
tswast deleted the b140579733-bq-to_dataframe branch January 15, 2020 21:19
This was referenced Jan 29, 2020
chore(asset): bump copyright year to 2020, tweak docstring formatting (via synth) #10223
Merged
chore(automl): bump copyright year to 2020, tweak docstring formatting (via synth) #10224
Merged
chore(bigquery): bump copyright year to 2020, tweak docstring formatting (via synth) #10225
Merged
chore(billingbudgets): bump copyright year to 2020, tweak docstring formatting (via synth) #10227
Merged
docs(datalabeling): update docstrings; bump copyright year to 2020 (via synth) #10229
Merged
feat(documentai): bump copyright year to 2020, tweak docstring formatting (via synth) #10230
Merged
fix(iam): bump copyright year to 2020 (via synth) #10231
Merged
chore(iot): bump copyright year to 2020 (via synth) #10232
Merged
This was referenced Jan 29, 2020
fix(irm): change default retry and timeout config; bump copyright year to 2020 (via synth) #10233
Merged
docs(language): change docstring formatting; bump copyright year to 2020 (via synth) #10234
Merged
chore(phishingprotection): bump copyright year to 2020 (via synth) #10235
Merged
chore(redis): bump copyright year to 2020, tweak docstring formatting (via synth) #10237
Merged
chore(speech): bump copyright year to 2020, tweak docstring formatting (via synth) #10238
Merged
fix(talent): change default timeout values; edit docstrings; bump copyright year to 2020 (via synth) #10239
Merged
chore(texttospeech): bump copyright year to 2020, tweak docstring formatting (via synth) #10240
Merged
chore(trace): bump copyright year to 2020, tweak docstring formatting (via synth) #10241
Merged
chore(vision): bump copyright year to 2020, tweak docstring formatting (via synth) #10242
Merged
chore(websecurityscanner): bump copyright year to 2020, tweak docstring formatting (via synth) #10243
Merged
[CHANGE ME] Re-generated container to pick up changes in the API or client library generator. #10256
Closed
[CHANGE ME] Re-generated datastore to pick up changes in the API or client library generator. #10261
Closed
@OmarMAmin

OmarMAmin commented Dec 12, 2022

Copy link
Copy Markdown

@tswast
Sorry for asking here, not sure if there's somewhere else to ask,
Does that mean that results from here aren't currently valid?
https://medium.com/google-cloud/announcing-google-cloud-bigquery-version-1-17-0-1fc428512171

using to_dataframe() is equivalent to to_arrow().to_pandas() if pyarrow is installed, and fastavro is no longer a requirement?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tswast

tswast commented Dec 12, 2022

Copy link
Copy Markdown
Contributor Author

Yes, that's true. We should see similar performance for to_dataframe() compared to to_arrow().to_pandas() after this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

parthea pushed a commit that referenced this pull request Aug 21, 2025
@tswast @plamut
fix(bigquerystorage): to_dataframe on an arrow stream uses 2x faster …
75a3284
…to_arrow + to_pandas, internally (#9997)

Towards https://issuetracker.google.com/140579733
parthea pushed a commit that referenced this pull request Sep 16, 2025
@tswast @parthea
fix(bigquerystorage): to_dataframe on an arrow stream uses 2x faster …
bad9289
…to_arrow + to_pandas, internally (#9997)

Towards https://issuetracker.google.com/140579733
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@shollyman shollyman Awaiting requested review from shollyman
1 more reviewer
@plamut plamut plamut approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@plamut plamut

Labels

api: bigquerystorage Issues related to the BigQuery Storage API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@tswast @plamut @OmarMAmin @googlebot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.