Skip to content

Commit 4ec4af8

Browse files
committed
Defer DataFrame HTML repr to Anywidget in display mode
1 parent 8325904 commit 4ec4af8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

bigframes/dataframe.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import pyarrow
5656
import tabulate
5757

58+
import bigframes
5859
import bigframes._config.display_options as display_options
5960
import bigframes.constants
6061
import bigframes.core
@@ -951,6 +952,10 @@ def _repr_html_(self):
951952
Renders the DataFrame as HTML.
952953
This method is used by IPython to display the DataFrame.
953954
"""
955+
# If in anywidget mode, return None to defer to _repr_mimebundle_
956+
# which will provide the richer anywidget representation.
957+
if bigframes.options.display.repr_mode == "anywidget":
958+
return None
954959
return self._repr_mimebundle_()["text/html"]
955960

956961
def _create_html_representation(

tests/system/small/test_anywidget.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,12 @@ def test_repr_in_anywidget_mode_should_not_be_deferred(
930930
assert "page_1_row_1" in representation
931931

932932

933+
def test_dataframe_repr_html_anywidget_mode(paginated_bf_df: bf.dataframe.DataFrame):
934+
with bf.option_context("display.repr_mode", "anywidget"):
935+
result = paginated_bf_df._repr_html_()
936+
assert result is None
937+
938+
933939
# TODO(b/332316283): Add tests for custom index and multiindex
934940
# This may not be necessary for the SQL Cell use case but should be
935941
# considered for completeness.

0 commit comments

Comments
 (0)