Skip to content

Conversation

shuoweil
Copy link
Contributor

@shuoweil shuoweil commented Oct 4, 2025

Previously, SQL queries in anywidget mode would fall back to deferred execution, showing a dry run instead of an interactive table.

This change modifies the display logic to directly use the anywidget interactive display for SQL queries, providing a more consistent and responsive user experience. A test case has been added to verify this behavior.

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<448126500> 🦕

@shuoweil shuoweil self-assigned this Oct 4, 2025
@shuoweil shuoweil requested review from a team as code owners October 4, 2025 07:39
@product-auto-label product-auto-label bot added size: s Pull request size is small. api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. labels Oct 4, 2025
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Oct 4, 2025

widget = display.TableWidget(self.copy())
return widget._repr_html_() # Return widget's HTML representation
except (AttributeError, ValueError, ImportError):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we catching so many exceptions here?

Copy link
Contributor Author

@shuoweil shuoweil Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are catching those exceptions to handle cases where the interactive anywidget table can't be displayed.
anywidget is an optional install, so we have to catch the ImportError in case someone doesn't have it. It also only works in environments like a Jupyter notebook, so if you run the code in a regular script, it can throw an AttributeError or ValueError.

That try...except block is just a safety net. It lets us fall back to the basic table view instead of crashing the program if the setup isn't perfect for the fancier, interactive one.

Copy link
Collaborator

@tswast tswast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In b/448126500 I suggest investigating the errors that happen when visualizing STRUCT columns, but this PR doesn't test such cases.

@shuoweil shuoweil force-pushed the shuowei-anywidget-col branch from dfa9c03 to 43a938c Compare October 7, 2025 05:46
Previously, SQL queries in anywidget mode would fall back to deferred execution, showing a dry run instead of an interactive table.

This change modifies the display logic to directly use the anywidget interactive display for SQL queries, providing a more consistent and responsive user experience. A test case has been added to verify this behavior.
Adds a test case to verify that a DataFrame with a STRUCT column is
correctly displayed in anywidget mode.

This test confirms that displaying a STRUCT column does not raise an
exception that would trigger the fallback to the deferred representation.
It mocks `IPython.display.display` to capture the `TableWidget` instance
and asserts that the rendered HTML contains the expected string
representation of the STRUCT data.
@shuoweil shuoweil force-pushed the shuowei-anywidget-col branch from 43a938c to 4a33ccf Compare October 9, 2025 06:43
@shuoweil shuoweil requested a review from tswast October 9, 2025 06:45
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: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants