docs(bigquery/bigframes): add query_results_dataframe code sample - #14510
docs(bigquery/bigframes): add query_results_dataframe code sample#14510shuoweil wants to merge 1 commit into
Conversation
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
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.
| # Set partial ordering mode as the default configuration for BigQuery | ||
| # DataFrames. | ||
| bpd.options.bigquery.ordering_mode = "partial" | ||
|
|
||
|
|
||
| def query_results_dataframe() -> bpd.DataFrame: | ||
| sql = """ |
There was a problem hiding this comment.
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 = """|
Will check in the code change in Git-on-Borg. |
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 pagebigquery-query-results-dataframe.Fixes b/546158959 (Subtask of b/522898394)
Summary of Changes
bigquery/bigframes/query_results_dataframe.pydemonstrating reading query results into a BigQuery DataFrame viabpd.read_gbq(sql).query_results_dataframe_test.py.