Skip to content

Conversation

@shuoweil
Copy link
Contributor

@shuoweil shuoweil commented Dec 9, 2025

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> 🦕

@shuoweil shuoweil requested review from a team as code owners December 9, 2025 23:48
@shuoweil shuoweil requested a review from tswast December 9, 2025 23:48
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@shuoweil shuoweil assigned shuoweil and unassigned chelsea-lin Dec 9, 2025
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. labels Dec 9, 2025
@shuoweil shuoweil marked this pull request as draft December 9, 2025 23:48
@shuoweil shuoweil marked this pull request as ready for review December 10, 2025 00:08

# Handle both tuple (data, metadata) and dict returns
if isinstance(widget_repr_result, tuple):
widget_repr, widget_metadata = widget_repr_result
Copy link
Contributor Author

@shuoweil shuoweil Dec 10, 2025

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                         

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. size: xl Pull request size is extra large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants