Skip to content

Commit 080af57

Browse files
committed
change tests in read_gbq_colab
1 parent bdb2fde commit 080af57

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
@@ -77,28 +77,21 @@ def __init__(self, dataframe: bigframes.dataframe.DataFrame):
7777
# Respect display options for initial page size
7878
initial_page_size = bigframes.options.display.max_rows
7979

80-
try:
81-
# Fetches initial data batches and row count for display.
82-
batches = dataframe.to_pandas_batches(
83-
page_size=initial_page_size,
84-
)
85-
self._batches = cast(bigframes.core.blocks.PandasBatches, batches)
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)
8685

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

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

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

10396
@functools.cached_property
10497
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)