Skip to content

Commit e41b3ba

Browse files
committed
minor updates
1 parent 5989a76 commit e41b3ba

File tree

6 files changed

+24
-15
lines changed

6 files changed

+24
-15
lines changed

bigframes/display/anywidget.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,15 @@ def __init__(self, dataframe: bigframes.dataframe.DataFrame):
6969
)
7070

7171
self._dataframe = dataframe
72-
# This flag is used to prevent observers from firing during initialization.
73-
self._initializing = True
72+
7473
super().__init__()
7574

75+
# This flag prevents observers from firing during initialization.
76+
# When traitlets like `page` and `page_size` are set in `__init__`, we
77+
# don't want their corresponding `_..._changed` methods to execute
78+
# until the widget is fully constructed.
79+
self._initializing = True
80+
7681
# Initialize attributes that might be needed by observers first
7782
self._table_id = str(uuid.uuid4())
7883
self._all_data_loaded = False
@@ -170,7 +175,8 @@ def _get_next_batch(self) -> bool:
170175
@property
171176
def _batch_iterator(self) -> Iterator[pd.DataFrame]:
172177
"""Lazily initializes and returns the batch iterator."""
173-
self._batch_iter = iter(self._batches)
178+
if self._batch_iter is None:
179+
self._batch_iter = iter(self._batches)
174180
return self._batch_iter
175181

176182
@property

tests/benchmark/read_gbq_colab/aggregate_output.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ def aggregate_output(*, project_id, dataset_id, table_id):
2525
# e.g. "{local_inline}" or "{local_large}"
2626
df = bpd._read_gbq_colab(f"SELECT * FROM `{project_id}`.{dataset_id}.{table_id}")
2727

28-
# Simulate getting the first page, since we'll always do that first in the UI.
28+
# Call the executor directly to isolate the query execution time
29+
# from other DataFrame overhead for this benchmark.
2930
execute_result = df._block.session._executor.execute(
3031
df._block.expr,
3132
ordered=True,
3233
use_explicit_destination=True,
33-
)
34+
) # type: ignore[call-arg]
3435
assert execute_result.total_rows is not None and execute_result.total_rows >= 0
3536
batches = execute_result.to_pandas_batches(page_size=PAGE_SIZE)
3637
next(iter(batches))
@@ -52,7 +53,7 @@ def aggregate_output(*, project_id, dataset_id, table_id):
5253
df_aggregated._block.expr,
5354
ordered=True,
5455
use_explicit_destination=True,
55-
)
56+
) # type: ignore[call-arg]
5657
assert (
5758
execute_result_aggregated.total_rows is not None
5859
and execute_result_aggregated.total_rows >= 0

tests/benchmark/read_gbq_colab/filter_output.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ def filter_output(
3030
# e.g. "{local_inline}" or "{local_large}"
3131
df = bpd._read_gbq_colab(f"SELECT * FROM `{project_id}`.{dataset_id}.{table_id}")
3232

33-
# Simulate getting the first page, since we'll always do that first in the UI.
34-
# Force BigQuery execution to get total_rows metadata
33+
# Call the executor directly to isolate the query execution time
34+
# from other DataFrame overhead for this benchmark.
3535
execute_result = df._block.session._executor.execute(
3636
df._block.expr,
3737
ordered=True,
3838
use_explicit_destination=True,
39-
)
39+
) # type: ignore[call-arg]
4040
batches = execute_result.to_pandas_batches(page_size=PAGE_SIZE)
4141
next(iter(batches))
4242

tests/benchmark/read_gbq_colab/first_page.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ def first_page(*, project_id, dataset_id, table_id):
2727
f"SELECT * FROM `{project_id}`.{dataset_id}.{table_id}"
2828
)
2929

30-
# Get number of rows (to calculate number of pages) and the first page.
30+
# Call the executor directly to isolate the query execution time
31+
# from other DataFrame overhead for this benchmark.
3132
execute_result = df._block.session._executor.execute(
3233
df._block.expr,
3334
ordered=True,
3435
use_explicit_destination=True,
35-
)
36+
) # type: ignore[call-arg]
3637
assert execute_result.total_rows is not None and execute_result.total_rows >= 0
3738
batches = execute_result.to_pandas_batches(page_size=PAGE_SIZE)
3839
first_page = next(iter(batches))

tests/benchmark/read_gbq_colab/sort_output.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ def sort_output(*, project_id, dataset_id, table_id):
2727
f"SELECT * FROM `{project_id}`.{dataset_id}.{table_id}"
2828
)
2929

30-
# Simulate getting the first page, since we'll always do that first in the UI.
30+
# Call the executor directly to isolate the query execution time
31+
# from other DataFrame overhead for this benchmark.
3132
execute_result = df._block.session._executor.execute(
3233
df._block.expr,
3334
ordered=True,
3435
use_explicit_destination=True,
35-
)
36+
) # type: ignore[call-arg]
3637
assert execute_result.total_rows is not None and execute_result.total_rows >= 0
3738
batches = execute_result.to_pandas_batches(page_size=PAGE_SIZE)
3839
next(iter(batches))
@@ -47,7 +48,7 @@ def sort_output(*, project_id, dataset_id, table_id):
4748
df_sorted._block.expr,
4849
ordered=True,
4950
use_explicit_destination=True,
50-
)
51+
) # type: ignore[call-arg]
5152
assert (
5253
execute_result_sorted.total_rows is not None
5354
and execute_result_sorted.total_rows >= 0

tests/system/small/test_anywidget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ def __next__(self):
484484
raise ValueError("Simulated read error")
485485

486486

487-
def test_widget_should_fallback_to_zero_rows_with_invlid_total_rows(
487+
def test_widget_should_fallback_to_zero_rows_with_invalid_total_rows(
488488
paginated_bf_df: bf.dataframe.DataFrame,
489489
monkeypatch: pytest.MonkeyPatch,
490490
):

0 commit comments

Comments
 (0)