Skip to content

perf: Replace expensive len() call with PandasBatches.total_rows in anywidget TableWidget #1937

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

shuoweil
Copy link
Contributor

perf: Replace expensive len() call with PandasBatches.total_rows in anywidget TableWidget

@shuoweil shuoweil self-assigned this Jul 24, 2025
@shuoweil shuoweil requested review from a team as code owners July 24, 2025 23:22
@shuoweil shuoweil requested a review from GarrettWu July 24, 2025 23:22
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. api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. labels Jul 24, 2025
@shuoweil shuoweil requested review from tswast and removed request for GarrettWu July 24, 2025 23:23
@shuoweil shuoweil force-pushed the shuowei-anywidget-remove-len-call branch from aee37a7 to 303c4af Compare July 24, 2025 23:23
Comment on lines +79 to +86
# Access total_rows through type casting (internal use only)
from bigframes.core.blocks import PandasBatches

if isinstance(self._batches, PandasBatches):
self.row_count = self._batches.total_rows or 0
else:
# Fallback for compatibility
self.row_count = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need this? to_pandas_batches is implemented in this package. We shouldn't have to protect against that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I recommend using the cast method, if this is just for the type checker.

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