@@ -827,58 +827,11 @@ def __repr__(self) -> str:
827827 lines .append (f"[{ row_count } rows x { column_count } columns]" )
828828 return "\n " .join (lines )
829829
830- def _repr_mimebundle_ (self , include = None , exclude = None ):
831- """
832- Custom display method for IPython/Jupyter environments.
833- This is called by IPython's display system when the object is displayed.
834- """
835- opts = bigframes .options .display
836-
837- # Only handle widget display in anywidget mode
838- if opts .repr_mode == "anywidget" :
839- try :
840- from bigframes import display
841-
842- # Process blob columns if needed
843- self ._cached ()
844- df = self .copy ()
845- if bigframes .options .display .blob_display :
846- blob_cols = [
847- series_name
848- for series_name , series in df .items ()
849- if series .dtype == bigframes .dtypes .OBJ_REF_DTYPE
850- ]
851- for col in blob_cols :
852- df [col ] = df [col ].blob ._get_runtime (
853- mode = "R" , with_metadata = True
854- )
855-
856- # Create and display the widget
857- widget = display .TableWidget (df )
858- widget_repr = widget ._repr_mimebundle_ (include = include , exclude = exclude )
859-
860- # Use deferred repr for text/plain of anywidget display.
861- # This avoids kicking off a query when the user is just
862- # printing the last expression in a cell.
863- widget_repr ["text/plain" ] = repr (self )
864- widget_repr ["text/html" ] = self ._repr_html_fallback ()
865- return widget_repr
866-
867- except (AttributeError , ValueError , ImportError ):
868- # Fallback: let IPython use _repr_html_() instead
869- warnings .warn (
870- "Anywidget mode is not available. "
871- "Please `pip install anywidget traitlets` or `pip install 'bigframes[anywidget]'` to use interactive tables. "
872- f"Falling back to static HTML. Error: { traceback .format_exc ()} "
873- )
874- # Don't return anything - let IPython fall back to _repr_html_()
875- pass
876-
877- return {"text/html" : self ._repr_html_fallback (), "text/plain" : repr (self )}
878-
879- def _repr_html_fallback (self ) -> str :
830+ def _repr_html_ (self ) -> str :
880831 """
881- Generates a static HTML table as a fallback representation.
832+ Returns an html string primarily for use by notebooks for displaying
833+ a representation of the DataFrame. Displays 20 rows by default since
834+ many notebooks are not configured for large tables.
882835 """
883836 opts = bigframes .options .display
884837 max_results = opts .max_rows
@@ -959,6 +912,55 @@ def obj_ref_rt_to_html(obj_ref_rt) -> str:
959912 html_string += f"[{ row_count } rows x { column_count } columns in total]"
960913 return html_string
961914
915+ def _repr_mimebundle_ (self , include = None , exclude = None ):
916+ """
917+ Custom display method for IPython/Jupyter environments.
918+ This is called by IPython's display system when the object is displayed.
919+ """
920+ opts = bigframes .options .display
921+
922+ # Only handle widget display in anywidget mode
923+ if opts .repr_mode == "anywidget" :
924+ try :
925+ from bigframes import display
926+
927+ # Process blob columns if needed
928+ self ._cached ()
929+ df = self .copy ()
930+ if bigframes .options .display .blob_display :
931+ blob_cols = [
932+ series_name
933+ for series_name , series in df .items ()
934+ if series .dtype == bigframes .dtypes .OBJ_REF_DTYPE
935+ ]
936+ for col in blob_cols :
937+ df [col ] = df [col ].blob ._get_runtime (
938+ mode = "R" , with_metadata = True
939+ )
940+
941+ # Create and display the widget
942+ widget = display .TableWidget (df )
943+ widget_repr = widget ._repr_mimebundle_ (include = include , exclude = exclude )
944+
945+ # Use deferred repr for text/plain of anywidget display.
946+ # This avoids kicking off a query when the user is just
947+ # printing the last expression in a cell.
948+ widget_repr ["text/plain" ] = repr (self )
949+ widget_repr ["text/html" ] = self ._repr_html_ ()
950+ return widget_repr
951+
952+ except (AttributeError , ValueError , ImportError ):
953+ # Fallback: let IPython use _repr_html_() instead
954+ warnings .warn (
955+ "Anywidget mode is not available. "
956+ "Please `pip install anywidget traitlets` or `pip install 'bigframes[anywidget]'` to use interactive tables. "
957+ f"Falling back to static HTML. Error: { traceback .format_exc ()} "
958+ )
959+ # Don't return anything - let IPython fall back to _repr_html_()
960+ pass
961+
962+ return {"text/html" : self ._repr_html_ (), "text/plain" : repr (self )}
963+
962964 def __delitem__ (self , key : str ):
963965 df = self .drop (columns = [key ])
964966 self ._set_block (df ._get_block ())
0 commit comments