Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Display custom multi-index in anywidget mode#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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
shuoweil wants to merge52 commits intomain
base:main
Choose a base branch
Loading
fromshuowei-anywidget-index-testcase

Conversation

@shuoweil
Copy link
Contributor

@shuoweilshuoweil commentedNov 10, 2025
edited
Loading

This branch introduces significant enhancements to the interactive table widget, particularly for displaying complex data structures like nested STRUCTs and ARRAYs, which implicitly improves the visual handling of multi-index DataFrames.

  • Improved Nested Data Display (html.py)
  • Refined Multi-Index and Row Grouping (anywidget.py,table_widget.js,table_widget.css)
  • General UI/UX Improvements

TODO(b/469861913): Nested columns from structs (e.g., 'struct_col.name') are not currently sortable

See an example here: screen/48TZkxRbmuWNYBB

Fixes #<459515995> 🦕

@shuoweilshuoweil self-assigned thisNov 10, 2025
@shuoweilshuoweil requested review froma team ascode ownersNovember 10, 2025 22:11
@review-notebook-app
Copy link

Check out this pull request on ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered byReviewNB

@product-auto-labelproduct-auto-labelbot added size: lPull request size is large. api: bigqueryIssues related to the googleapis/python-bigquery-dataframes API. labelsNov 10, 2025
@shuoweilshuoweil changed the titlefeat: Enhance anywidget notebook with Index and MultiIndex example and improve test robustnessfeat: Display index and mutiindex in anywidget modeNov 10, 2025
@shuoweilshuoweil marked this pull request as draftNovember 11, 2025 19:13
@shuoweilshuoweil removed the request for review fromtswastNovember 11, 2025 19:13
@shuoweilshuoweilforce-pushed theshuowei-anywidget-index-testcase branch from441bb94 to33fd6e3CompareNovember 11, 2025 20:30
@shuoweilshuoweil marked this pull request as ready for reviewNovember 11, 2025 21:42
@shuoweilshuoweil changed the titlefeat: Display index and mutiindex in anywidget modefeat: Display index and multi-index in anywidget modeNov 12, 2025
Comment on lines 32 to 80
def_calculate_rowspans(dataframe:pd.DataFrame)->list[list[int]]:
"""Calculates the rowspan for each cell in a MultiIndex DataFrame.
Args:
dataframe (pd.DataFrame):
The DataFrame for which to calculate index rowspans.
Returns:
list[list[int]]:
A list of lists, where each inner list corresponds to an index level
and contains the rowspan for each row at that level. A value of 0
indicates that the cell should not be rendered (it's covered by a
previous rowspan).
"""
ifnotisinstance(dataframe.index,pd.MultiIndex):
# If not a MultiIndex, no rowspans are needed for the index itself.
# Return a structure that indicates each index cell should be rendered once.
return [[1]*len(dataframe.index)]ifdataframe.index.nlevels>0else []

rowspans:list[list[int]]= []
forlevel_idxinrange(dataframe.index.nlevels):
current_level_spans:list[int]= []
current_value=None
current_span=0

foriinrange(len(dataframe.index)):
value=dataframe.index.get_level_values(level_idx)[i]

ifvalue==current_value:
current_span+=1
current_level_spans.append(0)# Mark as covered by previous rowspan
else:
# If new value, finalize previous span and start a new one
ifcurrent_span>0:
# Update the rowspan for the start of the previous span
current_level_spans[i-current_span]=current_span
current_value=value
current_span=1
current_level_spans.append(0)# Placeholder, will be updated later

# Finalize the last span
ifcurrent_span>0:
current_level_spans[len(dataframe.index)-current_span]=current_span

rowspans.append(current_level_spans)

returnrowspans


Copy link
Collaborator

Choose a reason for hiding this comment

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

While this makes for a somewhat cleaner view, I think we'd be better off not implementing rowpans. For example sorting by the various index columns is less intuitive if the index isn't rendered the same as other columns.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

A new implementation is used without rowspans.

table_html.append(' <tr style="text-align: left;">')

# Add index headers
fornameindataframe.index.names:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's try to actually refer to the original BigFrames DataFrame when deciding which index columns to render or not. In particular, we should not render the index if the BigFrame DataFrame has a NULL index.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

My new version correctly refers to the original BigFrames DataFrame's _block.has_index property. If has_index is False (indicating a "NULL index"), the _prepare_dataframe_for_display method ensures that a default "Row" column is inserted for display instead of attempting to render a non-existent index. My recent refactoring preserved this established logic.

@shuoweilshuoweil marked this pull request as draftDecember 5, 2025 18:53
…mode.ipynb"This reverts commit 5919552aa4158bdf4c3de12b12270f75314b8418.
@product-auto-labelproduct-auto-labelbot added size: xlPull request size is extra large. and removed size: lPull request size is large. labelsDec 17, 2025
@shuoweilshuoweil changed the titlefeat: Display index and multi-index in anywidget modefeat: Display custom multi-index in anywidget modeDec 17, 2025
@shuoweilshuoweil marked this pull request as ready for reviewDecember 19, 2025 02:40
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@tswasttswastAwaiting requested review from tswast

At least 1 approving review is required to merge this pull request.

Assignees

@shuoweilshuoweil

Labels

api: bigqueryIssues related to the googleapis/python-bigquery-dataframes API.size: xlPull request size is extra large.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@shuoweil@tswast

[8]ページ先頭

©2009-2025 Movatter.jp