4646
4747
4848class TableWidget (WIDGET_BASE ):
49- """
50- An interactive, paginated table widget for BigFrames DataFrames.
49+ """An interactive, paginated table widget for BigFrames DataFrames.
50+
51+ This widget provides a user-friendly way to display and navigate through
52+ large BigQuery DataFrames within a Jupyter environment.
5153 """
5254
5355 def __init__ (self , dataframe : bigframes .dataframe .DataFrame ):
@@ -74,19 +76,20 @@ def __init__(self, dataframe: bigframes.dataframe.DataFrame):
7476 initial_page_size = bigframes .options .display .max_rows
7577
7678 # Initialize data fetching attributes.
77- self ._batches = dataframe ._to_pandas_batches (page_size = initial_page_size )
79+ self ._batches = dataframe .to_pandas_batches (page_size = initial_page_size )
80+
81+ # Access total_rows through type casting (internal use only)
82+ from bigframes .core .blocks import PandasBatches
83+
84+ if isinstance (self ._batches , PandasBatches ):
85+ self .row_count = self ._batches .total_rows or 0
86+ else :
87+ # Fallback for compatibility
88+ self .row_count = 0
7889
7990 # set traitlets properties that trigger observers
8091 self .page_size = initial_page_size
8192
82- # len(dataframe) is expensive, since it will trigger a
83- # SELECT COUNT(*) query. It is a must have however.
84- # TODO(b/428238610): Start iterating over the result of `to_pandas_batches()`
85- # before we get here so that the count might already be cached.
86- # TODO(b/452747934): Allow row_count to be None and check to see if
87- # there are multiple pages and show "page 1 of many" in this case.
88- self .row_count = self ._batches .total_rows or 0
89-
9093 # get the initial page
9194 self ._set_table_html ()
9295
0 commit comments