From 88e57cdb716168b501044b535f085b18fe6cf839 Mon Sep 17 00:00:00 2001 From: Shuowei Li Date: Thu, 16 Jul 2026 18:59:49 +0000 Subject: [PATCH 1/6] docs: add code sample snippets for welcome page documentation --- .../samples/snippets/samples_test.py | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 packages/bigframes/samples/snippets/samples_test.py diff --git a/packages/bigframes/samples/snippets/samples_test.py b/packages/bigframes/samples/snippets/samples_test.py new file mode 100644 index 000000000000..23090e6ba786 --- /dev/null +++ b/packages/bigframes/samples/snippets/samples_test.py @@ -0,0 +1,138 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +def test_query_standard_sql(): + # [START bigquery_bigframes_query] + 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 alongside existing SQL. The project will be determined from default credentials. + df = bpd.read_gbq(sql) + + # Run a query after explicitly specifying a project. + bpd.options.bigquery.project = "your-project-id" + df = bpd.read_gbq(sql) + # [END bigquery_bigframes_query] + assert df is not None + + +def test_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] + assert df is not None + + +def test_query_bqstorage(): + # [START bigquery_bigframes_query_bqstorage] + 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 + """ + + # Read query results into a server-side DataFrame without downloading data. + df = bpd.read_gbq(sql) + + # When downloading results to an in-memory pandas DataFrame, bigquery-dataframes + # automatically uses the BigQuery Storage API if installed. + pandas_df = df.to_pandas() + # [END bigquery_bigframes_query_bqstorage] + assert pandas_df is not None + + +def test_query_parameters(): + # [START bigquery_bigframes_query_parameters] + 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 = @state + LIMIT 100 + """ + + query_config = { + "query": { + "parameterMode": "NAMED", + "queryParameters": [ + { + "name": "state", + "parameterType": {"type": "STRING"}, + "parameterValue": {"value": "TX"}, + } + ], + } + } + + df = bpd.read_gbq(sql, configuration=query_config) + # [END bigquery_bigframes_query_parameters] + assert df is not None + + +def test_upload_from_dataframe(): + # [START bigquery_bigframes_upload_from_dataframe] + import pandas as pd + + import bigframes.pandas as bpd + + # Set partial ordering mode as the default configuration for BigQuery DataFrames. + bpd.options.bigquery.ordering_mode = "partial" + + # Create a local pandas DataFrame. + df = pd.DataFrame( + { + "my_string": ["a", "b", "c"], + "my_int64": [1, 2, 3], + "my_float64": [4.0, 5.0, 6.0], + } + ) + + # Convert the local pandas DataFrame to a BigQuery DataFrame. + bq_df = bpd.read_pandas(df) + + # Write the DataFrame to a BigQuery table. + table_id = "your-project.your_dataset.your_table_name" + bq_df.to_gbq(table_id, if_exists="replace") + # [END bigquery_bigframes_upload_from_dataframe] + assert bq_df is not None From ade6557a1ff27691e162f8a50da048dee233e4fe Mon Sep 17 00:00:00 2001 From: Shuowei Li Date: Thu, 16 Jul 2026 19:11:40 +0000 Subject: [PATCH 2/6] Skip bigframes sample snippet tests --- .../bigframes/samples/snippets/samples_test.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/bigframes/samples/snippets/samples_test.py b/packages/bigframes/samples/snippets/samples_test.py index 23090e6ba786..2ee26b26c814 100644 --- a/packages/bigframes/samples/snippets/samples_test.py +++ b/packages/bigframes/samples/snippets/samples_test.py @@ -12,7 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import pytest + +@pytest.mark.skip(reason="Documentation sample code snippet") def test_query_standard_sql(): # [START bigquery_bigframes_query] import bigframes.pandas as bpd @@ -33,9 +36,10 @@ def test_query_standard_sql(): bpd.options.bigquery.project = "your-project-id" df = bpd.read_gbq(sql) # [END bigquery_bigframes_query] - assert df is not None + return df +@pytest.mark.skip(reason="Documentation sample code snippet") def test_query_legacy_sql(): # [START bigquery_bigframes_query_legacy] import bigframes.pandas as bpd @@ -53,9 +57,10 @@ def test_query_legacy_sql(): query_config = {"query": {"useLegacySql": True}} df = bpd.read_gbq(sql, configuration=query_config) # [END bigquery_bigframes_query_legacy] - assert df is not None + return df +@pytest.mark.skip(reason="Documentation sample code snippet") def test_query_bqstorage(): # [START bigquery_bigframes_query_bqstorage] import bigframes.pandas as bpd @@ -76,9 +81,10 @@ def test_query_bqstorage(): # automatically uses the BigQuery Storage API if installed. pandas_df = df.to_pandas() # [END bigquery_bigframes_query_bqstorage] - assert pandas_df is not None + return pandas_df +@pytest.mark.skip(reason="Documentation sample code snippet") def test_query_parameters(): # [START bigquery_bigframes_query_parameters] import bigframes.pandas as bpd @@ -107,9 +113,10 @@ def test_query_parameters(): df = bpd.read_gbq(sql, configuration=query_config) # [END bigquery_bigframes_query_parameters] - assert df is not None + return df +@pytest.mark.skip(reason="Documentation sample code snippet") def test_upload_from_dataframe(): # [START bigquery_bigframes_upload_from_dataframe] import pandas as pd @@ -135,4 +142,4 @@ def test_upload_from_dataframe(): table_id = "your-project.your_dataset.your_table_name" bq_df.to_gbq(table_id, if_exists="replace") # [END bigquery_bigframes_upload_from_dataframe] - assert bq_df is not None + return bq_df From 3db2b495f74ca0e444410b8534d188e27f929758 Mon Sep 17 00:00:00 2001 From: Shuowei Li Date: Thu, 16 Jul 2026 19:12:50 +0000 Subject: [PATCH 3/6] Add b/522845525 to pytest skip reasons --- packages/bigframes/samples/snippets/samples_test.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/bigframes/samples/snippets/samples_test.py b/packages/bigframes/samples/snippets/samples_test.py index 2ee26b26c814..6588120fae2f 100644 --- a/packages/bigframes/samples/snippets/samples_test.py +++ b/packages/bigframes/samples/snippets/samples_test.py @@ -15,7 +15,7 @@ import pytest -@pytest.mark.skip(reason="Documentation sample code snippet") +@pytest.mark.skip(reason="Documentation sample code snippet (b/522845525)") def test_query_standard_sql(): # [START bigquery_bigframes_query] import bigframes.pandas as bpd @@ -39,7 +39,7 @@ def test_query_standard_sql(): return df -@pytest.mark.skip(reason="Documentation sample code snippet") +@pytest.mark.skip(reason="Documentation sample code snippet (b/522845525)") def test_query_legacy_sql(): # [START bigquery_bigframes_query_legacy] import bigframes.pandas as bpd @@ -60,7 +60,7 @@ def test_query_legacy_sql(): return df -@pytest.mark.skip(reason="Documentation sample code snippet") +@pytest.mark.skip(reason="Documentation sample code snippet (b/522845525)") def test_query_bqstorage(): # [START bigquery_bigframes_query_bqstorage] import bigframes.pandas as bpd @@ -84,7 +84,7 @@ def test_query_bqstorage(): return pandas_df -@pytest.mark.skip(reason="Documentation sample code snippet") +@pytest.mark.skip(reason="Documentation sample code snippet (b/522845525)") def test_query_parameters(): # [START bigquery_bigframes_query_parameters] import bigframes.pandas as bpd @@ -116,7 +116,7 @@ def test_query_parameters(): return df -@pytest.mark.skip(reason="Documentation sample code snippet") +@pytest.mark.skip(reason="Documentation sample code snippet (b/522845525)") def test_upload_from_dataframe(): # [START bigquery_bigframes_upload_from_dataframe] import pandas as pd From 1cede2e97897d6722e8b21e27a0d4c6d80a59848 Mon Sep 17 00:00:00 2001 From: Shuowei Li Date: Thu, 16 Jul 2026 19:18:45 +0000 Subject: [PATCH 4/6] Enable runnable sample snippet tests --- .../samples/snippets/samples_test.py | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/bigframes/samples/snippets/samples_test.py b/packages/bigframes/samples/snippets/samples_test.py index 6588120fae2f..b34705bbd032 100644 --- a/packages/bigframes/samples/snippets/samples_test.py +++ b/packages/bigframes/samples/snippets/samples_test.py @@ -12,10 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os + import pytest -@pytest.mark.skip(reason="Documentation sample code snippet (b/522845525)") def test_query_standard_sql(): # [START bigquery_bigframes_query] import bigframes.pandas as bpd @@ -33,13 +34,17 @@ def test_query_standard_sql(): df = bpd.read_gbq(sql) # Run a query after explicitly specifying a project. - bpd.options.bigquery.project = "your-project-id" + project = "your-project-id" + # [END bigquery_bigframes_query] + project = os.environ.get("GOOGLE_CLOUD_PROJECT", "bigframes-dev-perf") + bpd.close_session() + # [START bigquery_bigframes_query] + bpd.options.bigquery.project = project df = bpd.read_gbq(sql) # [END bigquery_bigframes_query] - return df + assert df is not None -@pytest.mark.skip(reason="Documentation sample code snippet (b/522845525)") def test_query_legacy_sql(): # [START bigquery_bigframes_query_legacy] import bigframes.pandas as bpd @@ -57,10 +62,9 @@ def test_query_legacy_sql(): query_config = {"query": {"useLegacySql": True}} df = bpd.read_gbq(sql, configuration=query_config) # [END bigquery_bigframes_query_legacy] - return df + assert df is not None -@pytest.mark.skip(reason="Documentation sample code snippet (b/522845525)") def test_query_bqstorage(): # [START bigquery_bigframes_query_bqstorage] import bigframes.pandas as bpd @@ -81,10 +85,9 @@ def test_query_bqstorage(): # automatically uses the BigQuery Storage API if installed. pandas_df = df.to_pandas() # [END bigquery_bigframes_query_bqstorage] - return pandas_df + assert pandas_df is not None -@pytest.mark.skip(reason="Documentation sample code snippet (b/522845525)") def test_query_parameters(): # [START bigquery_bigframes_query_parameters] import bigframes.pandas as bpd @@ -113,10 +116,10 @@ def test_query_parameters(): df = bpd.read_gbq(sql, configuration=query_config) # [END bigquery_bigframes_query_parameters] - return df + assert df is not None -@pytest.mark.skip(reason="Documentation sample code snippet (b/522845525)") +@pytest.mark.skip(reason="Requires a writable table destination (b/522845525)") def test_upload_from_dataframe(): # [START bigquery_bigframes_upload_from_dataframe] import pandas as pd From 92c38cd459872de65ed03646b9dec631058b26cc Mon Sep 17 00:00:00 2001 From: Shuowei Li Date: Thu, 16 Jul 2026 19:22:49 +0000 Subject: [PATCH 5/6] Skip non-runnable snippet tests in samples_test.py --- .../bigframes/samples/snippets/samples_test.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/bigframes/samples/snippets/samples_test.py b/packages/bigframes/samples/snippets/samples_test.py index b34705bbd032..51d2e79e048f 100644 --- a/packages/bigframes/samples/snippets/samples_test.py +++ b/packages/bigframes/samples/snippets/samples_test.py @@ -12,11 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os - import pytest +@pytest.mark.skip(reason="Placeholder project ID 'your-project-id' (b/522845525)") def test_query_standard_sql(): # [START bigquery_bigframes_query] import bigframes.pandas as bpd @@ -34,17 +33,13 @@ def test_query_standard_sql(): df = bpd.read_gbq(sql) # Run a query after explicitly specifying a project. - project = "your-project-id" - # [END bigquery_bigframes_query] - project = os.environ.get("GOOGLE_CLOUD_PROJECT", "bigframes-dev-perf") - bpd.close_session() - # [START bigquery_bigframes_query] - bpd.options.bigquery.project = project + bpd.options.bigquery.project = "your-project-id" df = bpd.read_gbq(sql) # [END bigquery_bigframes_query] - assert df is not None + return df +@pytest.mark.skip(reason="Legacy SQL syntax not supported by BigQuery DataFrames (b/522845525)") def test_query_legacy_sql(): # [START bigquery_bigframes_query_legacy] import bigframes.pandas as bpd @@ -62,7 +57,7 @@ def test_query_legacy_sql(): query_config = {"query": {"useLegacySql": True}} df = bpd.read_gbq(sql, configuration=query_config) # [END bigquery_bigframes_query_legacy] - assert df is not None + return df def test_query_bqstorage(): From 65588725d3edac97ff004464773350b2ace0be44 Mon Sep 17 00:00:00 2001 From: Shuowei Li Date: Thu, 16 Jul 2026 21:58:38 +0000 Subject: [PATCH 6/6] docs: remove sample snippets moved to python-docs-samples --- .../samples/snippets/samples_test.py | 143 ------------------ 1 file changed, 143 deletions(-) delete mode 100644 packages/bigframes/samples/snippets/samples_test.py diff --git a/packages/bigframes/samples/snippets/samples_test.py b/packages/bigframes/samples/snippets/samples_test.py deleted file mode 100644 index 51d2e79e048f..000000000000 --- a/packages/bigframes/samples/snippets/samples_test.py +++ /dev/null @@ -1,143 +0,0 @@ -# Copyright 2026 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import pytest - - -@pytest.mark.skip(reason="Placeholder project ID 'your-project-id' (b/522845525)") -def test_query_standard_sql(): - # [START bigquery_bigframes_query] - 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 alongside existing SQL. The project will be determined from default credentials. - df = bpd.read_gbq(sql) - - # Run a query after explicitly specifying a project. - bpd.options.bigquery.project = "your-project-id" - df = bpd.read_gbq(sql) - # [END bigquery_bigframes_query] - return df - - -@pytest.mark.skip(reason="Legacy SQL syntax not supported by BigQuery DataFrames (b/522845525)") -def test_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 - - -def test_query_bqstorage(): - # [START bigquery_bigframes_query_bqstorage] - 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 - """ - - # Read query results into a server-side DataFrame without downloading data. - df = bpd.read_gbq(sql) - - # When downloading results to an in-memory pandas DataFrame, bigquery-dataframes - # automatically uses the BigQuery Storage API if installed. - pandas_df = df.to_pandas() - # [END bigquery_bigframes_query_bqstorage] - assert pandas_df is not None - - -def test_query_parameters(): - # [START bigquery_bigframes_query_parameters] - 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 = @state - LIMIT 100 - """ - - query_config = { - "query": { - "parameterMode": "NAMED", - "queryParameters": [ - { - "name": "state", - "parameterType": {"type": "STRING"}, - "parameterValue": {"value": "TX"}, - } - ], - } - } - - df = bpd.read_gbq(sql, configuration=query_config) - # [END bigquery_bigframes_query_parameters] - assert df is not None - - -@pytest.mark.skip(reason="Requires a writable table destination (b/522845525)") -def test_upload_from_dataframe(): - # [START bigquery_bigframes_upload_from_dataframe] - import pandas as pd - - import bigframes.pandas as bpd - - # Set partial ordering mode as the default configuration for BigQuery DataFrames. - bpd.options.bigquery.ordering_mode = "partial" - - # Create a local pandas DataFrame. - df = pd.DataFrame( - { - "my_string": ["a", "b", "c"], - "my_int64": [1, 2, 3], - "my_float64": [4.0, 5.0, 6.0], - } - ) - - # Convert the local pandas DataFrame to a BigQuery DataFrame. - bq_df = bpd.read_pandas(df) - - # Write the DataFrame to a BigQuery table. - table_id = "your-project.your_dataset.your_table_name" - bq_df.to_gbq(table_id, if_exists="replace") - # [END bigquery_bigframes_upload_from_dataframe] - return bq_df