This repository was archived by the owner on Apr 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
feat: display series in anywidget mode #2346
Merged
Merged
Changes from 10 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
218b7c2
feat: Enhance Series and DataFrame display with anywidget
shuoweil 9e3163f
test: add more npm tests
shuoweil 3227b23
test: add this file for faster and reliable npm tests
shuoweil c1a8f83
docs: notebook update
shuoweil c39293a
test: update old testcase due to new feature implementation
shuoweil 9dff0f4
Revert "test: update old testcase due to new feature implementation"
shuoweil f67e30f
feat: only display row count when series is large than the number can…
shuoweil 81d1dbe
refactor: Handle special float values and None consistently in sqlglo…
chelsea-lin 057f54d
Merge branch 'main' into shuowei-anywidget-series-display
shuoweil f70d5c1
Merge branch 'main' into shuowei-anywidget-series-display
shuoweil 58e357a
Merge branch 'main' into shuowei-anywidget-series-display
shuoweil fd04e6a
refactor: code refactor
shuoweil 4825aeb
fix: fix mypy
shuoweil 8845464
Merge branch 'main' into shuowei-anywidget-series-display
shuoweil d36fc0f
refactor: move code to plaintext file and add checks
shuoweil 593f9ae
refactor: move code to plaintext file and add checks
shuoweil 400ea07
Revert "refactor: move code to plaintext file and add checks"
shuoweil 945616c
Merge branch 'main' into shuowei-anywidget-series-display
shuoweil a474606
refactor: move create_text_representation to plaintext.py
shuoweil bd56992
refactor: move display logic to display/plaintext.py and display/html.py
shuoweil 971ee33
refactor: restore original order of max_results in __repr__
shuoweil 1a73628
docs: add todo back
shuoweil 1b7952b
refactor: split repr_mimebundle logic, handle deferred mode in html, …
shuoweil 15b2ac6
refactor: rename repr_mimebundle helpers and improve fallback comments
shuoweil f8914c8
style: fix repr_mimebundle docstring formatting
shuoweil 9fea10e
docs: update anywidget demo notebook with series display showcase
shuoweil a20a5ee
docs: update notebook
shuoweil 9e92c2a
Merge branch 'main' into shuowei-anywidget-series-display
shuoweil c0f4b4e
refactor: decouple plaintext representation from core objects
shuoweil 38899b7
refactor: consolidate object metadata extraction for display
shuoweil 64230d1
fix: refactor html display to address review comments
shuoweil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |||||||||||||||||||||||||||
| import itertools | ||||||||||||||||||||||||||||
| import numbers | ||||||||||||||||||||||||||||
| import textwrap | ||||||||||||||||||||||||||||
| import traceback | ||||||||||||||||||||||||||||
| import typing | ||||||||||||||||||||||||||||
| from typing import ( | ||||||||||||||||||||||||||||
| Any, | ||||||||||||||||||||||||||||
|
|
@@ -48,6 +49,7 @@ | |||||||||||||||||||||||||||
| import pyarrow as pa | ||||||||||||||||||||||||||||
| import typing_extensions | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import bigframes._config.display_options as display_options | ||||||||||||||||||||||||||||
| import bigframes.core | ||||||||||||||||||||||||||||
| from bigframes.core import agg_expressions, groupby, log_adapter | ||||||||||||||||||||||||||||
| import bigframes.core.block_transforms as block_ops | ||||||||||||||||||||||||||||
|
|
@@ -568,6 +570,105 @@ def reset_index( | |||||||||||||||||||||||||||
| block = block.assign_label(self._value_column, name) | ||||||||||||||||||||||||||||
| return bigframes.dataframe.DataFrame(block) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def _get_anywidget_bundle( | ||||||||||||||||||||||||||||
| self, include=None, exclude=None | ||||||||||||||||||||||||||||
| ) -> tuple[dict[str, Any], dict[str, Any]]: | ||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||
| Helper method to create and return the anywidget mimebundle for Series. | ||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||
| from bigframes import display | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Convert Series to DataFrame for TableWidget | ||||||||||||||||||||||||||||
| series_df = self.to_frame() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Create and display the widget | ||||||||||||||||||||||||||||
| widget = display.TableWidget(series_df) | ||||||||||||||||||||||||||||
| widget_repr_result = widget._repr_mimebundle_(include=include, exclude=exclude) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Handle both tuple (data, metadata) and dict returns | ||||||||||||||||||||||||||||
| if isinstance(widget_repr_result, tuple): | ||||||||||||||||||||||||||||
| widget_repr, widget_metadata = widget_repr_result | ||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||
| widget_repr = widget_repr_result | ||||||||||||||||||||||||||||
| widget_metadata = {} | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| widget_repr = dict(widget_repr) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Add text representation | ||||||||||||||||||||||||||||
| widget_repr["text/plain"] = self._create_text_representation( | ||||||||||||||||||||||||||||
| widget._cached_data, widget.row_count | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| # At this point, we have already executed the query as part of the | |
| # widget construction. Let's use the information available to render | |
| # the HTML and plain text versions. | |
| widget_repr["text/html"] = self._create_html_representation( | |
| widget._cached_data, | |
| widget.row_count, | |
| len(self.columns), | |
| blob_cols, | |
| ) | |
| widget_repr["text/plain"] = self._create_text_representation( | |
| widget._cached_data, widget.row_count | |
| ) |
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we'd refactor so that the code is shared. One way to do this would be to call the respective Series._create_html_representation or DataFrame._create_html_representation from the helper function.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of this code is nearly identical to the logic in https://github.com/googleapis/python-bigquery-dataframes/blob/main/bigframes/dataframe.py with the following differences:
self.to_frame()before rendering the TableWidget.text/htmlandtext/plain.Could you please refactor
dataframe.pyand this file to use shared helper functions to reduce duplication? https://github.com/googleapis/python-bigquery-dataframes/blob/main/bigframes/display/html.py seems like it'd be and appropriate place for such helpers.