This repository was archived by the owner on Apr 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
docs: add notebooks to user guide page #2505
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
06e684b
docs: add notebooks to user guide page
tswast a7dcb83
Merge remote-tracking branch 'origin/main' into tswast-notebooks
tswast d96a53b
revert: extra files
tswast c153f17
add titles
tswast f9cff20
Merge remote-tracking branch 'origin/main' into tswast-notebooks
tswast efb095a
revert more files
tswast 87f4e3a
another revert
tswast ab7fe7d
address myst-nb warnings
tswast 97d5df7
reduce redundant locations tests
tswast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../notebooks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# Pandas Extension for BigQuery DataFrames\n", | ||
| "\n", | ||
| "BigQuery DataFrames provides a pandas extension to execute BigQuery SQL scalar functions directly on pandas DataFrames." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import pandas as pd\n", | ||
| "import bigframes.pandas as bpd\n", | ||
| "import bigframes" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Using `sql_scalar`\n", | ||
| "\n", | ||
| "The `bigquery.sql_scalar` method allows you to apply a SQL scalar function to a pandas DataFrame by converting it to BigFrames, executing the SQL in BigQuery, and returning the result as a pandas Series." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "df = pd.DataFrame({\"a\": [1.5, 2.5, 3.5]})\n", | ||
| "result = df.bigquery.sql_scalar(\"ROUND({0}, 0)\")\n", | ||
| "result" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "You can also use multiple columns." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "df = pd.DataFrame({\"a\": [1, 2, 3], \"b\": [10, 20, 30]})\n", | ||
| "result = df.bigquery.sql_scalar(\"{0} + {1}\")\n", | ||
| "result" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "Python 3", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 3 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3", | ||
| "version": "3.12.9" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 4 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # 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 unittest.mock as mock | ||
|
|
||
| import pandas as pd | ||
|
|
||
| # Importing bigframes registers the accessor. | ||
| import bigframes # noqa: F401 | ||
|
|
||
|
|
||
| def test_dataframe_accessor_sql_scalar(): | ||
| df = pd.DataFrame({"a": [1, 2], "b": [3, 4]}) | ||
|
|
||
| with mock.patch("bigframes.pandas.io.api.read_pandas") as mock_read_pandas: | ||
| with mock.patch("bigframes.bigquery.sql_scalar") as mock_sql_scalar: | ||
| mock_bf_df = mock.MagicMock() | ||
| mock_bf_df.columns = ["a", "b"] | ||
| mock_bf_df.__getitem__.side_effect = lambda x: f"series_{x}" | ||
| mock_read_pandas.return_value = mock_bf_df | ||
|
|
||
| mock_result_series = mock.MagicMock() | ||
| mock_sql_scalar.return_value = mock_result_series | ||
| mock_result_series.to_pandas.return_value = pd.Series([4, 6]) | ||
|
|
||
| # This should trigger the accessor | ||
| result = df.bigquery.sql_scalar("ROUND({0} + {1})") | ||
|
|
||
| mock_read_pandas.assert_called_once() | ||
| # check it was called with df | ||
| assert mock_read_pandas.call_args[0][0] is df | ||
|
|
||
| mock_sql_scalar.assert_called_once_with( | ||
| "ROUND({0} + {1})", ["series_a", "series_b"] | ||
| ) | ||
|
|
||
| pd.testing.assert_series_equal(result, pd.Series([4, 6])) | ||
|
|
||
|
|
||
| def test_dataframe_accessor_sql_scalar_with_session(): | ||
| df = pd.DataFrame({"a": [1]}) | ||
| mock_session = mock.MagicMock() | ||
|
|
||
| with mock.patch("bigframes.pandas.io.api.read_pandas") as mock_read_pandas: | ||
| with mock.patch("bigframes.bigquery.sql_scalar") as mock_sql_scalar: | ||
| mock_bf_df = mock.MagicMock() | ||
| mock_bf_df.columns = ["a"] | ||
| mock_bf_df.__getitem__.side_effect = lambda x: f"series_{x}" | ||
| mock_read_pandas.return_value = mock_bf_df | ||
|
|
||
| mock_result_series = mock.MagicMock() | ||
| mock_sql_scalar.return_value = mock_result_series | ||
|
|
||
| df.bigquery.sql_scalar("template", session=mock_session) | ||
|
|
||
| mock_read_pandas.assert_called_once_with(df, session=mock_session) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # 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 pandas as pd | ||
|
|
||
| # Importing bigframes registers the accessor. | ||
| import bigframes # noqa: F401 | ||
|
|
||
|
|
||
| def test_bigframes_import_registers_accessor(): | ||
| df = pd.DataFrame({"a": [1]}) | ||
| # If bigframes was imported, df.bigquery should exist | ||
| assert hasattr(df, "bigquery") | ||
| from bigframes.extensions.pandas.dataframe_accessor import BigQueryDataFrameAccessor | ||
|
|
||
| assert isinstance(df.bigquery, BigQueryDataFrameAccessor) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed this one when I was reverting.