Skip to content

docs: use partial ordering mode in the quickstart sample #1734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions samples/snippets/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@


def run_quickstart(project_id: str) -> None:
import bigframes

session_options = bigframes.BigQueryOptions()
session = bigframes.connect(session_options)

your_gcp_project_id = project_id
query_or_table = "bigquery-public-data.ml_datasets.penguins"
df_session = session.read_gbq(query_or_table)
average_body_mass = df_session["body_mass_g"].mean()
print(f"average_body_mass (df_session): {average_body_mass}")

# [START bigquery_bigframes_quickstart]
import bigframes.pandas as bpd
Expand All @@ -33,10 +24,20 @@ def run_quickstart(project_id: str) -> None:
# On BigQuery Studio, the project ID is automatically detected.
bpd.options.bigquery.project = your_gcp_project_id

# Use "partial" ordering mode to generate more efficient queries, but the
# order of the rows in DataFrames may not be deterministic if you have not
# explictly sorted it. Some operations that depend on the order, such as
# head() will not function until you explictly order the DataFrame. Set the
# ordering mode to "strict" (default) for more pandas compatibility.
bpd.options.bigquery.ordering_mode = "partial"

# Create a DataFrame from a BigQuery table
query_or_table = "bigquery-public-data.ml_datasets.penguins"
df = bpd.read_gbq(query_or_table)

# Efficiently preview the results using the .peek() method.
df.peek()

# Use the DataFrame just as you would a pandas DataFrame, but calculations
# happen in the BigQuery query engine instead of the local system.
average_body_mass = df["body_mass_g"].mean()
Expand Down
2 changes: 1 addition & 1 deletion samples/snippets/quickstart_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ def test_quickstart(

quickstart.run_quickstart(your_project_id)
out, _ = capsys.readouterr()
assert "average_body_mass (df_session):" in out
assert "average_body_mass:" in out