-
Notifications
You must be signed in to change notification settings - Fork 62
fix: Correct DataFrame widget rendering in Colab #2319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
|
||
| # Handle both tuple (data, metadata) and dict returns | ||
| if isinstance(widget_repr_result, tuple): | ||
| widget_repr, widget_metadata = widget_repr_result |
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.
Even though this PR is a large one, the only difference from #2271 is this added metadata part. PR 2271 discards metadata, which causes the widget is not displayed at colab notebook. I modify the method to ensure metadata is preserved and returned. Verified at: screen/AjTEQC8SrSfMqhN
860
861 # Handle both tuple (data, metadata) and dict returns
862 if isinstance(widget_repr_result, tuple):
863 - widget_repr = dict(widget_repr_result[0]) # Extract data dict from tuple
863 + widget_repr, widget_metadata = widget_repr_result
864 else:
865 - widget_repr = dict(widget_repr_result)
865 + widget_repr = widget_repr_result
866 + widget_metadata = None
867
868 + widget_repr = dict(widget_repr)
869 +
870 # At this point, we have already executed the query as part of the
871 # widget construction. Let's use the information available to render
872 # the HTML and plain text versions.
876 widget._cached_data, widget.row_count
877 )
878
879 + if widget_metadata is not None:
880 + return widget_repr, widget_metadata
881 return widget_repr
882
This PR fix the _get_anywidget_bundle method. Previously, when the underlying widget's repr_mimebundle method returned a (data, metadata) tuple, the code was only extracting the data portion and discarding the metadata. This resulted in the widget not rendering correctly in environments like Colab, which rely on this metadata.
The change corrects this by properly unpacking the tuple into widget_repr and widget_metadata. The method now preserves the metadata and returns it along with the data, ensuring that the necessary information for widget rendering is passed on.
We also revert commit 4df3428 to reapply "refactor: Migrate DataFrame display to use IPython's repr_mimebundle() protocol for anywidget mode (#2271)"
A testcase is added to verify this new change. We also verified at colab: screen/AzGa5RMTJnMH5NH
Fixes #<466155761> 🦕