-
Notifications
You must be signed in to change notification settings - Fork 50
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
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 269e964
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp 1abe1dc
add asserts
rey-esp 7aed234
snippet prefix
rey-esp edf1e38
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp 26d6909
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp 0005f2f
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp 0f34c0e
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp d30000d
rename and space
rey-esp e18d3af
fix snippet names
rey-esp a676bf1
fix snippet names
rey-esp 45db18c
edit sninppet groups
rey-esp ac7dc4e
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp f64c8f9
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp 847bb71
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp 46bc7ab
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp cd6fc3d
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp e22bb3b
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp f88c9df
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp 5393048
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp d400dbb
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp 0d38fc7
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp 3d10d0b
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp af2d231
Merge branch 'main' into b392889457-bigframes.bigquery-samples
rey-esp e76ba62
Update samples/snippets/bigquery_modules_test.py
tswast 12c39b1
Update samples/snippets/bigquery_modules_test.py
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
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] | ||
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 |
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.
Uh oh!
There was an error while loading. Please reload this page.