1717from importlib import resources
1818import functools
1919import math
20- from typing import Any , Dict , Iterator , List , Optional , Type
20+ from typing import Any , cast , Dict , Iterator , List , Optional , Type
2121import uuid
2222
2323import pandas as pd
@@ -52,6 +52,17 @@ class TableWidget(WIDGET_BASE):
5252 large BigQuery DataFrames within a Jupyter environment.
5353 """
5454
55+ page_size = traitlets .Int (0 ).tag (sync = True )
56+ # Use dynamic default
57+ page_size = traitlets .Int ().tag (sync = True )
58+ row_count = traitlets .Int (0 ).tag (sync = True )
59+ table_html = traitlets .Unicode ().tag (sync = True )
60+
61+ @traitlets .default ("page_size" )
62+ def _page_size_default (self ):
63+ """Set the default page size from display options."""
64+ return bigframes .options .display .max_rows
65+
5566 def __init__ (self , dataframe : bigframes .dataframe .DataFrame ):
5667 """Initialize the TableWidget.
5768
@@ -76,21 +87,15 @@ def __init__(self, dataframe: bigframes.dataframe.DataFrame):
7687 # Respect display options for initial page size
7788 initial_page_size = bigframes .options .display .max_rows
7889
79- execute_result = dataframe ._block .session ._executor .execute (
80- dataframe ._block .expr ,
81- ordered = True ,
82- use_explicit_destination = True ,
90+ self ._batches : bigframes .core .blocks .PandasBatches = cast (
91+ bigframes .core .blocks .PandasBatches ,
92+ dataframe .to_pandas_batches (page_size = initial_page_size ),
8393 )
8494
8595 # The query issued by `to_pandas_batches()` already contains metadata
8696 # about how many results there were. Use that to avoid doing an extra
8797 # COUNT(*) query that `len(...)` would do.
88- self .row_count = execute_result .total_rows or 0
89-
90- # Create pandas batches from the ExecuteResult
91- self ._batches = execute_result .to_pandas_batches (page_size = initial_page_size )
92-
93- self .page_size = initial_page_size
98+ self .row_count = self ._batches .total_rows or 0
9499
95100 self ._set_table_html ()
96101 self ._initializing = False
@@ -106,7 +111,7 @@ def _css(self):
106111 return resources .read_text (bigframes .display , "table_widget.css" )
107112
108113 page = traitlets .Int (0 ).tag (sync = True )
109- page_size = traitlets .Int (25 ).tag (sync = True )
114+ page_size = traitlets .Int ().tag (sync = True )
110115 row_count = traitlets .Int (0 ).tag (sync = True )
111116 table_html = traitlets .Unicode ().tag (sync = True )
112117
@@ -187,16 +192,10 @@ def _cached_data(self) -> pd.DataFrame:
187192
188193 def _reset_batches_for_new_page_size (self ):
189194 """Reset the batch iterator when page size changes."""
190- # Execute with explicit destination for consistency with __init__
191- execute_result = self ._dataframe ._block .session ._executor .execute (
192- self ._dataframe ._block .expr ,
193- ordered = True ,
194- use_explicit_destination = True ,
195+ self ._batches = cast (
196+ bigframes .core .blocks .PandasBatches ,
197+ self ._dataframe .to_pandas_batches (page_size = self .page_size ),
195198 )
196-
197- # Create pandas batches from the ExecuteResult
198- self ._batches = execute_result .to_pandas_batches (page_size = self .page_size )
199-
200199 self ._cached_batches = []
201200 self ._batch_iter = None
202201 self ._all_data_loaded = False
0 commit comments