Skip to content

Commit 476b7dd

Browse files
authored
docs: use partial ordering mode in the quickstart sample (#1734)
1 parent b2261cc commit 476b7dd

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

samples/snippets/quickstart.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,7 @@
1414

1515

1616
def run_quickstart(project_id: str) -> None:
17-
import bigframes
18-
19-
session_options = bigframes.BigQueryOptions()
20-
session = bigframes.connect(session_options)
21-
2217
your_gcp_project_id = project_id
23-
query_or_table = "bigquery-public-data.ml_datasets.penguins"
24-
df_session = session.read_gbq(query_or_table)
25-
average_body_mass = df_session["body_mass_g"].mean()
26-
print(f"average_body_mass (df_session): {average_body_mass}")
2718

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

27+
# Use "partial" ordering mode to generate more efficient queries, but the
28+
# order of the rows in DataFrames may not be deterministic if you have not
29+
# explictly sorted it. Some operations that depend on the order, such as
30+
# head() will not function until you explictly order the DataFrame. Set the
31+
# ordering mode to "strict" (default) for more pandas compatibility.
32+
bpd.options.bigquery.ordering_mode = "partial"
33+
3634
# Create a DataFrame from a BigQuery table
3735
query_or_table = "bigquery-public-data.ml_datasets.penguins"
3836
df = bpd.read_gbq(query_or_table)
3937

38+
# Efficiently preview the results using the .peek() method.
39+
df.peek()
40+
4041
# Use the DataFrame just as you would a pandas DataFrame, but calculations
4142
# happen in the BigQuery query engine instead of the local system.
4243
average_body_mass = df["body_mass_g"].mean()

samples/snippets/quickstart_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ def test_quickstart(
3333

3434
quickstart.run_quickstart(your_project_id)
3535
out, _ = capsys.readouterr()
36-
assert "average_body_mass (df_session):" in out
36+
assert "average_body_mass:" in out

0 commit comments

Comments
 (0)