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(bigquery): `to_dataframe` uses faster `to_arrow` + `to_pandas` when `pyarrow` is available by tswast · Pull Request #10027 · googleapis/google-cloud-python

Conversation

@tswast

@tswast tswast commented Dec 30, 2019

Copy link
Copy Markdown
Contributor

…pyarrow is available

Related to similar PR #9997 but for the google-cloud-bigquery library.

Fixes 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 30, 2019 19:39
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 30, 2019
@tswast
tswast requested a review from plamut December 30, 2019 19:41
@tswast tswast added the kokoro:run Add this label to force Kokoro to re-run the tests. label Jan 3, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Jan 3, 2020
@tswast
tswast force-pushed the b140579733-bq-to_dataframe-part-2 branch from 12654c9 to 374608b Compare January 7, 2020 20:01
@tswast
tswast requested a review from shollyman January 7, 2020 20:01
@tswast tswast assigned shollyman and plamut Jan 7, 2020
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 fine code-wise IMO.

Two remarks:

  • Do we have a common representative table at hand to verify the stated performance gains and compare the results? If not, I can still manually create a dummy table with 10M floats, just like in the bug description.
  • The coverage check failure is legitimate and should be fixed.

Sorry, something went wrong.

Uh oh!

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

All reactions
@tswast tswast mentioned this pull request Jan 10, 2020
BigQuery: use union categorical to concatenate pages in to_dataframe when categorical dtype is requested #8044
Closed
@tswast

tswast commented Jan 10, 2020

Copy link
Copy Markdown
Contributor Author

In https://friendliness.dev/2019/07/29/bigquery-arrow/, we sampled the tlc_green_trips public data by running a SQL query like:

SELECT *
FROM table_name
WHERE RAND() < 0.06

and writing to a destination table so that we can read directly from the table (making query time not part of the benchmark).

All reactions

Sorry, something went wrong.

Uh oh!

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

tswast added 5 commits January 10, 2020 15:08
@tswast
fix(bigquery): to_dataframe uses 2x faster to_arrow + to_pandas when …
e07e326
…pyarrow is available
@tswast
fix: skip to_arrow tests when pyarrow is missing
05bb784
@tswast
test: update test to work around numpy array encoding of nested arrays
99aa5b7
@tswast
test: add test for tabledata.list with no rows
2e35f78
@tswast
Merge remote-tracking branch 'upstream/master' into b140579733-bq-to_…
de7af59
…dataframe-part-2
@tswast
tswast force-pushed the b140579733-bq-to_dataframe-part-2 branch from 45ea992 to de7af59 Compare January 10, 2020 21:26
tswast added 2 commits January 13, 2020 11:52
@tswast
test: boost test coverage
49f0d3c
@tswast
chore: fix lint
5208f71
@tswast

tswast commented Jan 13, 2020

Copy link
Copy Markdown
Contributor Author

Using the same (n1-standard-4) instance from #9997, I tested the speedup in the same way.

cd google-cloud-python/bigquery
git checkout b140579733-bq-to_dataframe-part-2
pip3 install -e .
cd ../..

benchmark_bq.py

import sys
from google.cloud import bigquery

client = bigquery.Client()

table_id = "swast-scratch.to_dataframe_benchmark.tlc_green_{}pct".format(sys.argv[1])
dataframe = client.list_rows(table_id).to_dataframe(create_bqstorage_client=True)
print("Got {} rows.".format(len(dataframe.index)))

After:

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

real    0m6.856s
user    0m3.644s
sys     0m1.132s

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

real    0m10.847s
user    0m6.012s
sys     0m1.464s

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

real    0m18.387s
user    0m11.240s
sys     0m2.564s

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

real    0m31.600s
user    0m21.752s
sys     0m4.432s

Before:

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

real    0m8.255s
user    0m8.008s
sys     0m1.324s

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

real    0m14.623s
user    0m15.284s
sys     0m1.980s

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

real    0m26.064s
user    0m30.008s
sys     0m3.344s

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

real    0m48.729s
user    1m1.356s
sys     0m7.452s

The speedup is a bit better than what we saw in #9997 at 1.542x here. Still not quite the 2x I was seeing in the summer, though. I think the reason we're seeing a larger difference here is that we're reading from multiple streams in parallel. This makes the download time go faster and maybe more dataframes to concatenate for the final dataframe result.

All reactions

Sorry, something went wrong.

Uh oh!

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

@tswast tswast changed the title fix(bigquery): to_dataframe uses 2x faster to_arrow + to_pandas when … refactor(bigquery): to_dataframe uses faster to_arrow + to_pandas when pyarrow is available Jan 13, 2020
@tswast
tswast requested a review from plamut January 13, 2020 20:50
plamut
plamut approved these changes Jan 15, 2020
View reviewed changes

@plamut plamut left a comment •
edited
Loading

Uh oh!

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

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.

Similarly to #9997, the observed performance gains are not huge on my 50 Mbps internet connection (network I/O consumes most of the time), but nevertheless more or less consistently reproducible.

Sorry, something went wrong.

Uh oh!

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

All reactions
@plamut
plamut merged commit c71d5f8 into googleapis:master Jan 15, 2020
@tswast
tswast deleted the b140579733-bq-to_dataframe-part-2 branch January 15, 2020 21:18
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
This was referenced Jan 29, 2020
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
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
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

@shollyman shollyman

@plamut plamut

Labels

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.

5 participants

@tswast @plamut @shollyman @googlebot @yoshi-kokoro
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.