feat: add dry run to the read_gbq function#979
Conversation
|
@antoineeripret Could you please check the failed tests? Thanks a lot. |
|
@shuoweil , I've added a new commit with some changes to fix tests. I've ran |
Hi @antoineeripret, could you please check the failed check please? It should be a quick fix. Thanks a lot. |
|
Hi @shuoweil, the last commit should fix it. Got the following on my local env: python -m black --check docs pandas_gbq tests noxfile.py setup.py
All done! ✨ 🍰 ✨
45 files would be left unchanged. |
pandas_gbq/gbq_connector.py
Outdated
| # we need to get it from the query result | ||
| # For query_and_wait_via_client_library, the RowIterator should have job set | ||
| raise ValueError("Cannot access QueryJob from RowIterator for dry_run") | ||
| return query_job.total_bytes_processed / 1024**3 |
There was a problem hiding this comment.
Could we simply return query_job.total_bytes_processed without further processing?
Reasons:
- The
total_bytes_processedhas integer type, which is more precise than a float type - For small tables (ones with 1-10 MB sizes), converting the size to GB makes the result less readable
- It aligns more with the behavior of BigQuery Python client to return size in bytes.
Generally speaking, we want the caller of this function to perform unit conversions.
There was a problem hiding this comment.
@sycai, good call ! I've though about my own usage, but didn't think about the bigger picture here. I'll commit the change. :)
sycai
left a comment
There was a problem hiding this comment.
Thank you! I think we should be good to go once the doc and tests are updated.
|
@sycai : updated :) |
|
@antoineeripret I believe lint fails. Could you please update it? It still fails with the new commit. |
|
@shuoweil, fixed with last commit (I left a trailing space) in a file. |
|
@antoineeripret Could you please take a look at the failed testcases? They seem to related to your change. Thanks a lot. |
There was a problem hiding this comment.
@antoineeripret Please check the failed testcase tests/system/test_gbq.py::TestReadGBQIntegration::test_read_gbq_with_dry_run
|
@shuoweil: Can I have the details of what has failed? I can't read the Kokoro's results (permission denied). Thank you ! |
|
Hey @antoineeripret I took the liberty to directly enhance your code. Now when we do dry run, we will get more stats like table schema and creation time in addition to the total bytes processed. The results are aggregated into a pandas Series like this: I will make sure all the tests pass this time. Also tagging @shuoweil and @tswast as it aligns more with our BigFrames code: https://github.com/googleapis/python-bigquery-dataframes/blob/69fa7f404cde5a202df68ed21a6faeac98fb1e4d/bigframes/session/dry_runs.py#L112 |
Amazing improvement, thanks for adding your input and knowledge @sycai ! The output is beter than what I had envisioned ! Thank you ! |
PR created by the Librarian CLI to initialize a release. Merging this PR will auto trigger a release. Librarian Version: v0.7.0 Language Image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator@sha256:c8612d3fffb3f6a32353b2d1abd16b61e87811866f7ec9d65b59b02eb452a620 <details><summary>pandas-gbq: 0.33.0</summary> ## [0.33.0](v0.32.0...v0.33.0) (2026-01-05) ### Features * add dry run to the read_gbq function (#979) ([516f986](516f986f)) </details> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This change allows the user to run a dry run query using the
read_gbqfunction. Instead of returning apd.DataFrame, the behavior is changed and the amount of data processed (in GB) is returned.