Skip to content

docs(bigquery/bigframes): add query_results_dataframe code sample - #14510

Closed
shuoweil wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
shuoweil:shuowei-bigframes-query-results-dataframe
Closed

docs(bigquery/bigframes): add query_results_dataframe code sample#14510
shuoweil wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
shuoweil:shuowei-bigframes-query-results-dataframe

Conversation

@shuoweil

Copy link
Copy Markdown
Contributor

Description

Adds a BigQuery DataFrames (bigframes) code sample demonstrating how to execute a query and load the results directly into a DataFrame, targeting the documentation page bigquery-query-results-dataframe.

Fixes b/546158959 (Subtask of b/522898394)

Summary of Changes

  • Added bigquery/bigframes/query_results_dataframe.py demonstrating reading query results into a BigQuery DataFrame via bpd.read_gbq(sql).
  • Added corresponding unit test query_results_dataframe_test.py.

@shuoweil
shuoweil requested review from a team and tswast as code owners August 13, 2026 21:50
@snippet-bot

snippet-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label Bot added api: bigquery Issues related to the BigQuery API. samples Issues that are directly related to samples. labels Aug 13, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new script to query BigQuery data and load the results into a BigQuery DataFrame using bigframes.pandas, along with a corresponding test file. The reviewer suggested moving the global configuration setting bpd.options.bigquery.ordering_mode inside the function to prevent side effects when the module is imported.

Comment on lines +18 to +24
# Set partial ordering mode as the default configuration for BigQuery
# DataFrames.
bpd.options.bigquery.ordering_mode = "partial"


def query_results_dataframe() -> bpd.DataFrame:
sql = """

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Setting global configuration options like bpd.options.bigquery.ordering_mode at the module level causes side effects immediately when the module is imported. This can unexpectedly alter the behavior of other parts of an application that imports this module. It is safer and more idiomatic to set this configuration inside the function so that it only executes when the function is called.

def query_results_dataframe() -> bpd.DataFrame:
    # Set partial ordering mode as the default configuration for BigQuery
    # DataFrames.
    bpd.options.bigquery.ordering_mode = "partial"

    sql = """

@shuoweil shuoweil closed this Aug 13, 2026
@shuoweil

Copy link
Copy Markdown
Contributor Author

Will check in the code change in Git-on-Borg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigquery Issues related to the BigQuery API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant