|
23 | 23 | import re |
24 | 24 | import sys |
25 | 25 | import textwrap |
26 | | -import traceback |
27 | 26 | import typing |
28 | 27 | from typing import ( |
29 | 28 | Any, |
@@ -788,18 +787,6 @@ def __repr__(self) -> str: |
788 | 787 | if opts.repr_mode in ("deferred"): |
789 | 788 | return formatter.repr_query_job(self._compute_dry_run()) |
790 | 789 |
|
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 | | - |
803 | 790 | # TODO(swast): pass max_columns and get the true column count back. Maybe |
804 | 791 | # get 1 more column than we have requested so that pandas can add the |
805 | 792 | # ... for us? |
@@ -863,27 +850,27 @@ def _repr_html_(self) -> str: |
863 | 850 |
|
864 | 851 | if opts.repr_mode == "anywidget": |
865 | 852 | try: |
| 853 | + import anywidget # noqa: F401 |
866 | 854 | from IPython.display import display as ipython_display |
| 855 | + import traitlets # noqa: F401 |
867 | 856 |
|
868 | 857 | 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: |
880 | 859 | warnings.warn( |
881 | | - "Anywidget mode is not available. " |
| 860 | + "anywidget or its dependencies are not installed. " |
882 | 861 | "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." |
884 | 863 | ) |
885 | 864 | return formatter.repr_query_job(self._compute_dry_run()) |
886 | 865 |
|
| 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 | + |
887 | 874 | # Continue with regular HTML rendering for non-anywidget modes |
888 | 875 | # TODO(swast): pass max_columns and get the true column count back. Maybe |
889 | 876 | # get 1 more column than we have requested so that pandas can add the |
|
0 commit comments