-
Notifications
You must be signed in to change notification settings - Fork 63
feat: Refactor TableWidget and to_pandas_batches #2250
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
15993a3
feat: Refactor DataFrame.to_pandas_batches and update TableWidget
shuoweil 928f1db
test: fix failed testcase
shuoweil 0c12888
Merge branch 'main' into shuowei-anywidget-index-testcase
shuoweil eff882d
Merge branch 'main' into shuowei-anywidget-index-testcase
shuoweil 4222027
feat: remove unsafe while loop
shuoweil e3f5816
Merge branch 'main' into shuowei-anywidget-index-testcase
shuoweil 3233db4
chore: document why RLock is needed in TableWidget
shuoweil 387246a
fix(display): prevent deadlock in TableWidget page update
shuoweil 7e77932
fix: make TableWidget import-safe when traitlets is missing
shuoweil b303072
fix: refactor test_anywidget imports to avoid NameError when dependen…
shuoweil 5c5616f
test(unit): refine TableWidget deadlock test style
shuoweil e389782
Merge branch 'main' into shuowei-anywidget-index-testcase
shuoweil c312169
test: skip windows test
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -20,7 +20,8 @@ | |||||
| from importlib import resources | ||||||
| import functools | ||||||
| import math | ||||||
| from typing import Any, Dict, Iterator, List, Optional, Type | ||||||
| import threading | ||||||
| from typing import Any, Iterator, Optional | ||||||
| import uuid | ||||||
|
|
||||||
| import pandas as pd | ||||||
|
|
@@ -39,15 +40,15 @@ | |||||
| import anywidget | ||||||
| import traitlets | ||||||
|
|
||||||
| ANYWIDGET_INSTALLED = True | ||||||
| _ANYWIDGET_INSTALLED = True | ||||||
| except Exception: | ||||||
| ANYWIDGET_INSTALLED = False | ||||||
| _ANYWIDGET_INSTALLED = False | ||||||
|
|
||||||
| WIDGET_BASE: Type[Any] | ||||||
| if ANYWIDGET_INSTALLED: | ||||||
| WIDGET_BASE = anywidget.AnyWidget | ||||||
| _WIDGET_BASE: type[Any] | ||||||
| if _ANYWIDGET_INSTALLED: | ||||||
| _WIDGET_BASE = anywidget.AnyWidget | ||||||
| else: | ||||||
| WIDGET_BASE = object | ||||||
| _WIDGET_BASE = object | ||||||
|
|
||||||
|
|
||||||
| @dataclasses.dataclass(frozen=True) | ||||||
|
|
@@ -56,7 +57,7 @@ class _SortState: | |||||
| ascending: bool | ||||||
|
|
||||||
|
|
||||||
| class TableWidget(WIDGET_BASE): | ||||||
| class TableWidget(_WIDGET_BASE): | ||||||
| """An interactive, paginated table widget for BigFrames DataFrames. | ||||||
|
|
||||||
| This widget provides a user-friendly way to display and navigate through | ||||||
|
|
@@ -65,12 +66,8 @@ class TableWidget(WIDGET_BASE): | |||||
|
|
||||||
| page = traitlets.Int(0).tag(sync=True) | ||||||
| page_size = traitlets.Int(0).tag(sync=True) | ||||||
| row_count = traitlets.Union( | ||||||
| [traitlets.Int(), traitlets.Instance(type(None))], | ||||||
| default_value=None, | ||||||
| allow_none=True, | ||||||
| ).tag(sync=True) | ||||||
| table_html = traitlets.Unicode().tag(sync=True) | ||||||
| row_count = traitlets.Int(allow_none=True, default_value=None).tag(sync=True) | ||||||
| table_html = traitlets.Unicode("").tag(sync=True) | ||||||
| sort_column = traitlets.Unicode("").tag(sync=True) | ||||||
| sort_ascending = traitlets.Bool(True).tag(sync=True) | ||||||
| orderable_columns = traitlets.List(traitlets.Unicode(), []).tag(sync=True) | ||||||
|
|
@@ -86,9 +83,10 @@ def __init__(self, dataframe: bigframes.dataframe.DataFrame): | |||||
| Args: | ||||||
| dataframe: The Bigframes Dataframe to display in the widget. | ||||||
| """ | ||||||
| if not ANYWIDGET_INSTALLED: | ||||||
| if not _ANYWIDGET_INSTALLED: | ||||||
| raise ImportError( | ||||||
| "Please `pip install anywidget traitlets` or `pip install 'bigframes[anywidget]'` to use TableWidget." | ||||||
| "Please `pip install anywidget traitlets` or " | ||||||
| "`pip install 'bigframes[anywidget]'` to use TableWidget." | ||||||
| ) | ||||||
|
|
||||||
| self._dataframe = dataframe | ||||||
|
|
@@ -99,15 +97,19 @@ def __init__(self, dataframe: bigframes.dataframe.DataFrame): | |||||
| self._table_id = str(uuid.uuid4()) | ||||||
| self._all_data_loaded = False | ||||||
| self._batch_iter: Optional[Iterator[pd.DataFrame]] = None | ||||||
| self._cached_batches: List[pd.DataFrame] = [] | ||||||
| self._cached_batches: list[pd.DataFrame] = [] | ||||||
| self._last_sort_state: Optional[_SortState] = None | ||||||
| # RLock is needed because _set_table_html can be re-entrant when | ||||||
| # self.page is updated within the method, triggering the observer. | ||||||
| self._setting_html_lock = threading.RLock() | ||||||
|
||||||
| self._setting_html_lock = threading.RLock() | |
| self._setting_html_lock = threading.Lock() |
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
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.
Uh oh!
There was an error while loading. Please reload this page.