Skip to content

Commit 38ab819

Browse files
authored
Merge branch 'main' into main_chelsealin_aggtests
2 parents 9e40021 + 9e8c426 commit 38ab819

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
def test_performance_optimizations() -> None:
17+
# [START bigquery_bigframes_use_peek_to_preview_data]
18+
import bigframes.pandas as bpd
19+
20+
# Read the "Penguins" table into a dataframe
21+
df = bpd.read_gbq("bigquery-public-data.ml_datasets.penguins")
22+
23+
# Preview 3 random rows
24+
df.peek(3)
25+
# [END bigquery_bigframes_use_peek_to_preview_data]
26+
assert df.peek(3) is not None
27+
28+
import bigframes.pandas as bpd
29+
30+
users = bpd.DataFrame({"user_name": ["John"]})
31+
groups = bpd.DataFrame({"group_id": ["group_1"]})
32+
transactions = bpd.DataFrame({"amount": [3], "completed": [True]})
33+
34+
# [START bigquery_bigframes_use_cache_after_expensive_operations]
35+
# Assume you have 3 large dataframes "users", "group" and "transactions"
36+
37+
# Expensive join operations
38+
final_df = users.join(groups).join(transactions)
39+
final_df.cache()
40+
# Subsequent derived results will reuse the cached join
41+
print(final_df.peek())
42+
print(len(final_df[final_df["completed"]]))
43+
print(final_df.groupby("group_id")["amount"].mean().peek(30))
44+
# [END bigquery_bigframes_use_cache_after_expensive_operations]
45+
assert final_df is not None
46+
47+
# [START bigquery_bigframes_enable_deferred_repr_for_debugging]
48+
import bigframes.pandas as bpd
49+
50+
bpd.options.display.repr_mode = "deferred"
51+
# [END bigquery_bigframes_enable_deferred_repr_for_debugging]
52+
assert bpd.options.display.repr_mode == "deferred"

tests/unit/session/test_io_bigquery.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,15 @@ def test_create_job_configs_labels_log_adaptor_call_method_under_length_limit():
109109
labels = io_bq.create_job_configs_labels(
110110
job_configs_labels=cur_labels, api_methods=api_methods
111111
)
112-
expected_dict = {
112+
expected_labels = {
113113
"source": "bigquery-dataframes-temp",
114114
"bigframes-api": "dataframe-columns",
115115
"recent-bigframes-api-0": "dataframe-max",
116116
"recent-bigframes-api-1": "dataframe-head",
117117
"recent-bigframes-api-2": "dataframe-__init__",
118118
}
119-
assert labels == expected_dict
119+
# Asserts that all items in expected_labels are present in labels
120+
assert labels.items() >= expected_labels.items()
120121

121122

122123
def test_create_job_configs_labels_length_limit_met_and_labels_is_none():

0 commit comments

Comments
 (0)