Skip to content

Commit 2756968

Browse files
committed
change tests in read_gbq_colab
1 parent c4204db commit 2756968

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

bigframes/display/anywidget.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,21 @@ def __init__(self, dataframe: bigframes.dataframe.DataFrame):
7676
# Respect display options for initial page size
7777
initial_page_size = bigframes.options.display.max_rows
7878

79-
try:
80-
# Fetches initial data batches and row count for display.
81-
batches = dataframe.to_pandas_batches(
82-
page_size=initial_page_size,
83-
)
84-
self._batches = cast(bigframes.core.blocks.PandasBatches, batches)
79+
# Fetches initial data batches and row count for display.
80+
batches = dataframe.to_pandas_batches(
81+
page_size=initial_page_size,
82+
)
83+
self._batches = cast(bigframes.core.blocks.PandasBatches, batches)
8584

86-
# Use total_rows if available, otherwise default to 0.
87-
if self._batches:
88-
self.row_count = self._batches.total_rows or 0
89-
else:
90-
self.row_count = 0
91-
self.page_size = initial_page_size
85+
# Use total_rwos from batches directly
86+
self.row_count = self._batches.total_rows or 0
9287

93-
# Generates the initial HTML table content
94-
self._set_table_html()
88+
# Set page_size after _batches is initialized so observers have
89+
# access to batch data
90+
self.page_size = initial_page_size
9591

96-
except Exception:
97-
self.row_count = 0
98-
self.page_size = initial_page_size
99-
self._batches = None
100-
self.table_html = ""
92+
# Generates the initial HTML table content
93+
self._set_table_html()
10194

10295
@functools.cached_property
10396
def _esm(self):

tests/benchmark/read_gbq_colab/first_page.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ 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.
31-
df.shape
30+
# Use total_rows from batches directly and the first page
31+
execute_result = df._block.session._executor.execute(df._block.expr, ordered=True)
32+
execute_result.total_rows or 0
3233
next(iter(df.to_pandas_batches(page_size=PAGE_SIZE)))
3334

3435

tests/benchmark/read_gbq_colab/last_page.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def last_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 then all pages.
31-
df.shape
30+
execute_result = df._block.session._executor.execute(df._block.expr, ordered=True)
31+
execute_result.total_rows or 0
3232
for _ in df.to_pandas_batches(page_size=PAGE_SIZE):
3333
pass
3434

0 commit comments

Comments
 (0)