Skip to content

Commit f18fd9e

Browse files
committed
change return type
1 parent d418799 commit f18fd9e

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

bigframes/dataframe.py

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import re
2424
import sys
2525
import textwrap
26-
import traceback
2726
import typing
2827
from typing import (
2928
Any,
@@ -788,18 +787,6 @@ def __repr__(self) -> str:
788787
if opts.repr_mode in ("deferred"):
789788
return formatter.repr_query_job(self._compute_dry_run())
790789

791-
# Anywidget mode uses interative display
792-
if opts.repr_mode == "anywidget":
793-
# Try to display with anywidget, fall back to deferred if not in IPython
794-
try:
795-
from bigframes import display
796-
797-
widget = display.TableWidget(self.copy())
798-
return widget._repr_html_() # Return widget's HTML representation
799-
except (AttributeError, ValueError, ImportError):
800-
# Not in IPython environment, fall back to deferred mode
801-
return formatter.repr_query_job(self._compute_dry_run())
802-
803790
# TODO(swast): pass max_columns and get the true column count back. Maybe
804791
# get 1 more column than we have requested so that pandas can add the
805792
# ... for us?
@@ -863,27 +850,27 @@ def _repr_html_(self) -> str:
863850

864851
if opts.repr_mode == "anywidget":
865852
try:
853+
import anywidget # noqa: F401
866854
from IPython.display import display as ipython_display
855+
import traitlets # noqa: F401
867856

868857
from bigframes import display
869-
870-
# Always create a new widget instance for each display call
871-
# This ensures that each cell gets its own widget and prevents
872-
# unintended sharing between cells
873-
widget = display.TableWidget(df.copy())
874-
875-
ipython_display(widget)
876-
return "" # Return empty string since we used display()
877-
878-
except (AttributeError, ValueError, ImportError):
879-
# Fallback if anywidget is not available
858+
except ImportError:
880859
warnings.warn(
881-
"Anywidget mode is not available. "
860+
"anywidget or its dependencies are not installed. "
882861
"Please `pip install anywidget traitlets` or `pip install 'bigframes[anywidget]'` to use interactive tables. "
883-
f"Falling back to deferred mode. Error: {traceback.format_exc()}"
862+
"Falling back to deferred mode."
884863
)
885864
return formatter.repr_query_job(self._compute_dry_run())
886865

866+
# Always create a new widget instance for each display call
867+
# This ensures that each cell gets its own widget and prevents
868+
# unintended sharing between cells
869+
widget = display.TableWidget(df.copy())
870+
871+
ipython_display(widget)
872+
return "" # Return empty string since we used display()
873+
887874
# Continue with regular HTML rendering for non-anywidget modes
888875
# TODO(swast): pass max_columns and get the true column count back. Maybe
889876
# get 1 more column than we have requested so that pandas can add the

0 commit comments

Comments
 (0)