Skip to content

Commit b442fce

Browse files
committed
avoid two query calls
1 parent 6b87339 commit b442fce

File tree

2 files changed

+11
-49
lines changed

2 files changed

+11
-49
lines changed

bigframes/display/anywidget.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ def __init__(self, dataframe: bigframes.dataframe.DataFrame):
8989
# Create pandas batches from the ExecuteResult
9090
self._batches = execute_result.to_pandas_batches(page_size=initial_page_size)
9191

92-
# Set page_size after _batches is available since traitlets observers
93-
# may depend on _batches being initialized when the change trigger happens
94-
self.page_size = initial_page_size
92+
# Set page_size after _batches is available, but avoid triggering observers
93+
# by setting the underlying traitlet value directly
94+
self._trait_values["page_size"] = initial_page_size
95+
self._trait_notifiers["page_size"] = {} # Initialize notifiers if needed
9596

9697
self._set_table_html()
9798

@@ -168,11 +169,8 @@ def _get_next_batch(self) -> bool:
168169
batch = next(iterator)
169170
self._cached_batches.append(batch)
170171
return True
171-
except StopIteration as e:
172+
except StopIteration:
172173
self._all_data_loaded = True
173-
if not isinstance(e, StopIteration):
174-
# If we fail to get a batch, assume no more data is available.
175-
self.row_count = 0
176174
return False
177175

178176
@property

notebooks/dataframes/anywidget_mode.ipynb

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,7 @@
130130
{
131131
"data": {
132132
"text/html": [
133-
"Query job 3245c62b-5969-4b78-b1f2-4330592d3c65 is DONE. 171.4 MB processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=bigframes-dev&j=bq:US:3245c62b-5969-4b78-b1f2-4330592d3c65&page=queryresults\">Open Job</a>"
134-
],
135-
"text/plain": [
136-
"<IPython.core.display.HTML object>"
137-
]
138-
},
139-
"metadata": {},
140-
"output_type": "display_data"
141-
},
142-
{
143-
"data": {
144-
"text/html": [
145-
"Query job 1a5cec48-7128-4986-86a6-369a8f366974 is DONE. 171.4 MB processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=bigframes-dev&j=bq:US:1a5cec48-7128-4986-86a6-369a8f366974&page=queryresults\">Open Job</a>"
133+
"Query job 087c4276-8c26-467f-852b-c0d31848f666 is DONE. 171.4 MB processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=bigframes-dev&j=bq:US:087c4276-8c26-467f-852b-c0d31848f666&page=queryresults\">Open Job</a>"
146134
],
147135
"text/plain": [
148136
"<IPython.core.display.HTML object>"
@@ -154,7 +142,7 @@
154142
{
155143
"data": {
156144
"application/vnd.jupyter.widget-view+json": {
157-
"model_id": "d59362abcff6445ea879b5f43e0ca9b3",
145+
"model_id": "c2a4111b39c3462a8d0f4f2e4a01635b",
158146
"version_major": 2,
159147
"version_minor": 1
160148
},
@@ -198,19 +186,7 @@
198186
{
199187
"data": {
200188
"text/html": [
201-
"Query job 356f561b-5017-413f-950b-2bc4c7798a24 is DONE. 171.4 MB processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=bigframes-dev&j=bq:US:356f561b-5017-413f-950b-2bc4c7798a24&page=queryresults\">Open Job</a>"
202-
],
203-
"text/plain": [
204-
"<IPython.core.display.HTML object>"
205-
]
206-
},
207-
"metadata": {},
208-
"output_type": "display_data"
209-
},
210-
{
211-
"data": {
212-
"text/html": [
213-
"Query job 72162728-56a3-47ce-bdb1-61b038cc2146 is DONE. 171.4 MB processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=bigframes-dev&j=bq:US:72162728-56a3-47ce-bdb1-61b038cc2146&page=queryresults\">Open Job</a>"
189+
"Query job 86d748cf-699c-407c-8eba-2d6421375aad is DONE. 171.4 MB processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=bigframes-dev&j=bq:US:86d748cf-699c-407c-8eba-2d6421375aad&page=queryresults\">Open Job</a>"
214190
],
215191
"text/plain": [
216192
"<IPython.core.display.HTML object>"
@@ -229,7 +205,7 @@
229205
{
230206
"data": {
231207
"application/vnd.jupyter.widget-view+json": {
232-
"model_id": "8fac39e9b92e42d283883137f155526f",
208+
"model_id": "401985bd2b3f40f3a2f7e48eeabb272d",
233209
"version_major": 2,
234210
"version_minor": 1
235211
},
@@ -316,19 +292,7 @@
316292
{
317293
"data": {
318294
"text/html": [
319-
"Query job 77f0582b-b68c-46a7-bf25-463837a4ef3f is DONE. 171.4 MB processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=bigframes-dev&j=bq:US:77f0582b-b68c-46a7-bf25-463837a4ef3f&page=queryresults\">Open Job</a>"
320-
],
321-
"text/plain": [
322-
"<IPython.core.display.HTML object>"
323-
]
324-
},
325-
"metadata": {},
326-
"output_type": "display_data"
327-
},
328-
{
329-
"data": {
330-
"text/html": [
331-
"Query job ec2bcbc2-0f5a-45e9-affc-485183cb245e is DONE. 171.4 MB processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=bigframes-dev&j=bq:US:ec2bcbc2-0f5a-45e9-affc-485183cb245e&page=queryresults\">Open Job</a>"
295+
"Query job 2cb31c3a-ccbc-40fc-b548-ce8503fd2cc3 is DONE. 171.4 MB processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=bigframes-dev&j=bq:US:2cb31c3a-ccbc-40fc-b548-ce8503fd2cc3&page=queryresults\">Open Job</a>"
332296
],
333297
"text/plain": [
334298
"<IPython.core.display.HTML object>"
@@ -347,7 +311,7 @@
347311
{
348312
"data": {
349313
"application/vnd.jupyter.widget-view+json": {
350-
"model_id": "fe6358fd83d6431198944e601ea00372",
314+
"model_id": "9d2e3ced089a4cadbec9eb06d3724237",
351315
"version_major": 2,
352316
"version_minor": 1
353317
},

0 commit comments

Comments
 (0)