Skip to content

Commit 106ec21

Browse files
committed
change tests in read_gbq_colab
1 parent a8d35ab commit 106ec21

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ 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-
batches = df._to_pandas_batches(page_size=PAGE_SIZE)
32-
assert (tr := batches.total_rows) is not None and tr >= 0
33-
next(iter(batches))
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
33+
next(iter(df.to_pandas_batches(page_size=PAGE_SIZE)))
3434

3535

3636
if __name__ == "__main__":

tests/benchmark/read_gbq_colab/last_page.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ 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-
batches = df._to_pandas_batches(page_size=PAGE_SIZE)
32-
assert (tr := batches.total_rows) is not None and tr >= 0
33-
for _ in batches:
30+
execute_result = df._block.session._executor.execute(df._block.expr, ordered=True)
31+
execute_result.total_rows or 0
32+
for _ in df.to_pandas_batches(page_size=PAGE_SIZE):
3433
pass
3534

3635

0 commit comments

Comments
 (0)