Skip to content

docs: add bigframes_queries sample snippets#14429

Open
shuoweil wants to merge 5 commits into
GoogleCloudPlatform:mainfrom
shuoweil:shuowei-add-bf-example
Open

docs: add bigframes_queries sample snippets#14429
shuoweil wants to merge 5 commits into
GoogleCloudPlatform:mainfrom
shuoweil:shuowei-add-bf-example

Conversation

@shuoweil

@shuoweil shuoweil commented Jul 16, 2026

Copy link
Copy Markdown

Adds sample code snippets with region tags (# [START ...] / # [END ...]) for BigQuery DataFrames documentation welcome page (python-libraries.md).

Note here, we need to place all imports inside testcase functions for the following reasons:

  1. Doc Ingestion Boundaries: Documentation generation tools only extract code between # [START] and # [END] tags. Any top-of-file imports get stripped out.
  2. Copy-Paste Runnable: Placing imports inside the function ensures the rendered code snippet on cloud.google.com includes the import statements, allowing users to copy and run it without hitting a NameError.

Fixes #<522845525> 🦕

@shuoweil
shuoweil requested review from a team and tswast as code owners July 16, 2026 22:13
@snippet-bot

snippet-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 5 region tags.

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 Jul 16, 2026
@shuoweil shuoweil changed the title docs(bigquery/bigframes): add bigframes_queries sample snippets docs: add bigframes_queries sample snippets Jul 16, 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 code examples and tests for BigQuery DataFrames, covering standard SQL queries, legacy SQL queries, storage API usage, parameterized queries, and uploading from a pandas DataFrame. The feedback recommends parameterizing placeholder values like project_id and table_id to make the examples flexible and enable their tests to run instead of being skipped. Additionally, it is recommended to remove the legacy SQL example and its test entirely, as legacy SQL is not supported by BigQuery DataFrames.

# limitations under the License.


def query_standard_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

To make this snippet testable and avoid global side effects, parameterize the project_id in the function signature with a default value of "your-project-id". This allows tests to pass a valid project ID while keeping the placeholder for documentation.

Suggested change
def query_standard_sql():
def query_standard_sql(project_id: str = "your-project-id"):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This test case is for adding samples in welcome page. No past in variables should be allowed.

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.

Gemini is correct in this case.

Comment thread bigquery/bigframes/bigframes_queries.py Outdated
Comment on lines +39 to +56
def query_legacy_sql():
# [START bigquery_bigframes_query_legacy]
import bigframes.pandas as bpd

# Set partial ordering mode as the default configuration for BigQuery DataFrames.
bpd.options.bigquery.ordering_mode = "partial"

sql = """
SELECT name FROM [bigquery-public-data:usa_names.usa_1910_current]
WHERE state = 'TX'
LIMIT 100
"""

# Run a query using legacy SQL syntax.
query_config = {"query": {"useLegacySql": True}}
df = bpd.read_gbq(sql, configuration=query_config)
# [END bigquery_bigframes_query_legacy]
return df

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

Since BigQuery DataFrames does not support Legacy SQL (as noted in the skipped test), providing a code snippet for it is misleading and will result in errors for users. Please remove the query_legacy_sql function entirely to avoid documenting unsupported behavior.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I update the error message to avoid confusion

return df


def upload_from_dataframe():

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

Parameterize the table_id in the function signature with a default value of "your-project.your_dataset.your_table_name". This makes the snippet more flexible and easier to test.

Suggested change
def upload_from_dataframe():
def upload_from_dataframe(table_id: str = "your-project.your_dataset.your_table_name"):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This test case is for adding samples in welcome page. No past in variables should be allowed.

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.

Gemini is correct.

bq_df = bpd.read_pandas(df)

# Write the DataFrame to a BigQuery table.
table_id = "your-project.your_dataset.your_table_name"

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

Remove the hardcoded table_id assignment since it is now passed as a parameter.

Suggested change
table_id = "your-project.your_dataset.your_table_name"
# Use the provided table_id parameter

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I prefer the original line better

Comment on lines +20 to +23
@pytest.mark.skip(reason="Placeholder project ID 'your-project-id' (b/522845525)")
def test_query_standard_sql():
df = bigframes_queries.query_standard_sql()
assert df is not None

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

Now that query_standard_sql is parameterized, we can remove the @pytest.mark.skip decorator and run the test using the project_id fixture.

Suggested change
@pytest.mark.skip(reason="Placeholder project ID 'your-project-id' (b/522845525)")
def test_query_standard_sql():
df = bigframes_queries.query_standard_sql()
assert df is not None
def test_query_standard_sql(project_id):
df = bigframes_queries.query_standard_sql(project_id=project_id)
assert df is not None

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This test case is for adding samples in welcome page. No past in variables should be allowed.

Comment on lines +26 to +29
@pytest.mark.skip(reason="Legacy SQL syntax not supported by BigQuery DataFrames (b/522845525)")
def test_query_legacy_sql():
df = bigframes_queries.query_legacy_sql()
assert df is not None

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

Since Legacy SQL is not supported by BigQuery DataFrames and the corresponding snippet should be removed, this test should also be removed.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@shuoweil

Copy link
Copy Markdown
Author

cc @sycai for review

# limitations under the License.


def query_standard_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.

Gemini is correct in this case.



def query_standard_sql():
# [START bigquery_bigframes_query]

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.

The Cloud samples rubric has the region tags outside of the function and move the imports to outside of the function. Refer to https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md

return df


def upload_from_dataframe():

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.

Gemini is correct.

Comment on lines +46 to +48
@pytest.mark.skip(
reason="Requires a writable destination table so pytest skips execution, but snippet is required for welcome page documentation."
)

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.

Don't skip this. Instead, parametrize the sample and pass in a writable destination.

Comment on lines +28 to +33
@pytest.mark.skip(
reason="Legacy SQL syntax is not supported for execution by BigQuery DataFrames, but snippet is required for welcome page documentation."
)
def test_query_legacy_sql():
df = bigframes_queries.query_legacy_sql()
assert df is not None

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.

Agreed with Gemini. It's better not to have a sample than to have one that doesn't work.

Comment on lines +20 to +22
@pytest.mark.skip(
reason="Placeholder project ID 'your-project-id' cannot be executed by pytest, but snippet is required for welcome page documentation."
)

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.

Don't skip this.

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.

2 participants