Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

docs: add samples using SQL methods via the bigframes.bigquery module #1358

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 26 commits into from
Feb 24, 2025
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fa418ae
docs: add bigquery_modeules_test.py file with bigframes.bigquery exam…
rey-esp Feb 4, 2025
269e964
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp Feb 4, 2025
1abe1dc
add asserts
rey-esp Feb 5, 2025
7aed234
snippet prefix
rey-esp Feb 5, 2025
edf1e38
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp Feb 5, 2025
26d6909
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp Feb 5, 2025
0005f2f
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp Feb 5, 2025
0f34c0e
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp Feb 6, 2025
d30000d
rename and space
rey-esp Feb 6, 2025
e18d3af
fix snippet names
rey-esp Feb 10, 2025
a676bf1
fix snippet names
rey-esp Feb 10, 2025
45db18c
edit sninppet groups
rey-esp Feb 10, 2025
ac7dc4e
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp Feb 10, 2025
f64c8f9
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp Feb 10, 2025
847bb71
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp Feb 11, 2025
46bc7ab
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp Feb 12, 2025
cd6fc3d
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp Feb 12, 2025
e22bb3b
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp Feb 13, 2025
f88c9df
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp Feb 14, 2025
5393048
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp Feb 19, 2025
d400dbb
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp Feb 19, 2025
0d38fc7
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp Feb 20, 2025
3d10d0b
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp Feb 20, 2025
af2d231
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp Feb 24, 2025
e76ba62
Update samples/snippets/bigquery_modules_test.py
tswast Feb 24, 2025
12c39b1
Update samples/snippets/bigquery_modules_test.py
tswast Feb 24, 2025
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
69 changes: 69 additions & 0 deletions 69 samples/snippets/bigquery_modules_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2023 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_bigquery_dataframes_examples() -> None:
# [START bigquery_dataframes_bigquery_methods_struct]
import bigframes.bigquery as bbq
import bigframes.pandas as bpd

# Load data from BigQuery
query_or_table = "bigquery-public-data.ml_datasets.penguins"
bq_df = bpd.read_gbq(query_or_table)

# Create a new STRUCT Series with subfields for each column in a DataFrames.
lengths = bbq.struct(
bq_df[["culmen_length_mm", "culmen_depth_mm", "flipper_length_mm"]]
)

lengths.peek()
# 146 {'culmen_length_mm': 51.1, 'culmen_depth_mm': ...
# 278 {'culmen_length_mm': 48.2, 'culmen_depth_mm': ...
# 337 {'culmen_length_mm': 36.4, 'culmen_depth_mm': ...
# 154 {'culmen_length_mm': 46.5, 'culmen_depth_mm': ...
# 185 {'culmen_length_mm': 50.1, 'culmen_depth_mm': ...
# dtype: struct[pyarrow]
# [END bigquery_dataframes_bigquery_methods_struct]

# [START bigquery_dataframes_bigquery_methods_scalar]
tswast marked this conversation as resolved.
Show resolved Hide resolved
import bigframes.bigquery as bbq
import bigframes.pandas as bpd

# Load data from BigQuery
query_or_table = "bigquery-public-data.ml_datasets.penguins"

# The sql_scalar function can be used to inject SQL syntax that is not supported
# or difficult to express with the bigframes.pandas APIs.
bq_df = bpd.read_gbq(query_or_table)
tswast marked this conversation as resolved.
Show resolved Hide resolved
shortest = bbq.sql_scalar(
"LEAST({0}, {1}, {2})",
columns=[
bq_df["culmen_depth_mm"],
bq_df["culmen_length_mm"],
bq_df["flipper_length_mm"],
],
)

shortest.peek()
# 0
# 149 18.9
# 33 16.3
# 296 17.2
# 287 17.0
# 307 15.0
# dtype: Float64
# [END bigquery_dataframes_bigquery_methods_scalar]
assert bq_df is not None
assert lengths is not None
assert shortest is not None
Morty Proxy This is a proxified and sanitized view of the page, visit original site.