-
Notifications
You must be signed in to change notification settings - Fork 63
feat: Display custom single index column in anywidget mode #2311
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
Changes from 5 commits
28c1645
ef97cc2
2e41e54
f88e263
bd19bf3
a5bd541
0591d7a
5a3bf9a
3b42978
e654974
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -245,7 +245,7 @@ def _cached_data(self) -> pd.DataFrame: | |||
| """Combine all cached batches into a single DataFrame.""" | ||||
| if not self._cached_batches: | ||||
| return pd.DataFrame(columns=self._dataframe.columns) | ||||
| return pd.concat(self._cached_batches, ignore_index=True) | ||||
| return pd.concat(self._cached_batches) | ||||
|
|
||||
| def _reset_batch_cache(self) -> None: | ||||
| """Resets batch caching attributes.""" | ||||
|
|
@@ -294,7 +294,15 @@ def _set_table_html(self) -> None: | |||
| break | ||||
|
|
||||
| # Get the data for the current page | ||||
| page_data = cached_data.iloc[start:end] | ||||
| page_data = cached_data.iloc[start:end].copy() | ||||
|
|
||||
| # Handle index display | ||||
| if page_data.index.name is not None: | ||||
|
||||
| @validations.requires_index |
I'll try to figure out the correct alternative and report back.
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.
df._block.has_indexThere 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.
Thanks again for the excellent feedback, @tswast. Your suggestion to use df._block.has_index was precisely what was needed to avoid the expensive index materialization on the full BigFrames DataFrame.
I've implemented the change to use self._dataframe._block.has_index. However, I found that an additional check was needed to fully resolve the issue and pass test_widget_with_default_index_should_display_row_column.
The full condition I've used is:
if self._dataframe._block.has_index and page_data.index.name is not None:
To clarify the inclusion of page_data.index.name is not None: this part of the check is performed on the small, local pandas page_data slice. It's a cheap operation because page_data is already in memory. Its purpose is to correctly handle the display formatting in all scenarios.
Specifically, while self._dataframe._block.has_index correctly tells us if a custom index exists on the BigFrames DataFrame, that index might still be an unnamed default (like a RangeIndex). In such cases, page_data.index.name would be None.
The combined check ensures that we only display a named custom index when both conditions are met:
- A custom index has been defined on the BigFrames DataFrame (self._dataframe._block.has_index).
- That index actually has a name (page_data.index.name is not None) to use as a header.
Otherwise, it correctly falls back to displaying the generic "Row" column. This makes the overall index display logic robust and accurate, reflecting the user's intent without triggering expensive BigQuery operations.
Let me know if this approach looks good to you.
Uh oh!
There was an error while loading. Please reload this page.