Skip to content

Commit 52f10dc

Browse files
committed
change the fallback function name to better reflect the change
1 parent 9a1ee30 commit 52f10dc

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
@@ -821,7 +821,7 @@ def __repr__(self) -> str:
821821
lines.append(f"[{row_count} rows x {column_count} columns]")
822822
return "\n".join(lines)
823823

824-
def _repr_html_(self) -> str:
824+
def _repr_html_fallback_(self) -> str:
825825
"""
826826
Returns an html string primarily for use by notebooks for displaying
827827
a representation of the DataFrame. Displays 20 rows by default since
@@ -934,26 +934,36 @@ def _repr_mimebundle_(self, include=None, exclude=None):
934934

935935
# Create and display the widget
936936
widget = display.TableWidget(df)
937-
widget_repr = widget._repr_mimebundle_(include=include, exclude=exclude)
937+
widget_repr_result = widget._repr_mimebundle_(
938+
include=include, exclude=exclude
939+
)
940+
941+
# Handle both tuple (data, metadata) and dict returns
942+
if isinstance(widget_repr_result, tuple):
943+
widget_repr = dict(
944+
widget_repr_result[0]
945+
) # Extract data dict from tuple
946+
else:
947+
widget_repr = dict(widget_repr_result)
938948

939949
# Use deferred repr for text/plain of anywidget display.
940950
# This avoids kicking off a query when the user is just
941951
# printing the last expression in a cell.
942-
widget_repr["text/plain"] = repr(self)
943-
widget_repr["text/html"] = self._repr_html_()
952+
widget_repr["text/plain"] = repr(df)
953+
widget_repr["text/html"] = self._repr_html_fallback_()
944954
return widget_repr
945955

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

956-
return {"text/html": self._repr_html_(), "text/plain": repr(self)}
966+
return {"text/html": self._repr_html_fallback_(), "text/plain": repr(self)}
957967

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

0 commit comments

Comments
 (0)