Skip to content

Commit 6b407d4

Browse files
committed
change the fallback function name to better reflect the change
1 parent 689fa74 commit 6b407d4

File tree

5 files changed

+408
-24
lines changed

5 files changed

+408
-24
lines changed

bigframes/dataframe.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ def __repr__(self) -> str:
827827
lines.append(f"[{row_count} rows x {column_count} columns]")
828828
return "\n".join(lines)
829829

830-
def _repr_html_(self) -> str:
830+
def _repr_html_fallback_(self) -> str:
831831
"""
832832
Returns an html string primarily for use by notebooks for displaying
833833
a representation of the DataFrame. Displays 20 rows by default since
@@ -940,26 +940,36 @@ def _repr_mimebundle_(self, include=None, exclude=None):
940940

941941
# Create and display the widget
942942
widget = display.TableWidget(df)
943-
widget_repr = widget._repr_mimebundle_(include=include, exclude=exclude)
943+
widget_repr_result = widget._repr_mimebundle_(
944+
include=include, exclude=exclude
945+
)
946+
947+
# Handle both tuple (data, metadata) and dict returns
948+
if isinstance(widget_repr_result, tuple):
949+
widget_repr = dict(
950+
widget_repr_result[0]
951+
) # Extract data dict from tuple
952+
else:
953+
widget_repr = dict(widget_repr_result)
944954

945955
# Use deferred repr for text/plain of anywidget display.
946956
# This avoids kicking off a query when the user is just
947957
# printing the last expression in a cell.
948-
widget_repr["text/plain"] = repr(self)
949-
widget_repr["text/html"] = self._repr_html_()
958+
widget_repr["text/plain"] = repr(df)
959+
widget_repr["text/html"] = self._repr_html_fallback_()
950960
return widget_repr
951961

952962
except (AttributeError, ValueError, ImportError):
953-
# Fallback: let IPython use _repr_html_() instead
963+
# Fallback: let IPython use _repr_html_fallback_() instead
954964
warnings.warn(
955965
"Anywidget mode is not available. "
956966
"Please `pip install anywidget traitlets` or `pip install 'bigframes[anywidget]'` to use interactive tables. "
957967
f"Falling back to static HTML. Error: {traceback.format_exc()}"
958968
)
959-
# Don't return anything - let IPython fall back to _repr_html_()
969+
# Don't return anything - let IPython fall back to _repr_html_fallback_()
960970
pass
961971

962-
return {"text/html": self._repr_html_(), "text/plain": repr(self)}
972+
return {"text/html": self._repr_html_fallback_(), "text/plain": repr(self)}
963973

964974
def __delitem__(self, key: str):
965975
df = self.drop(columns=[key])

0 commit comments

Comments
 (0)