Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lukasmasuch
Copy link
Collaborator

@lukasmasuch lukasmasuch commented Feb 28, 2025

Describe your changes

Adds support for Pandas Styler tooltips to st.table:

Screen.Recording.2025-02-28.at.14.31.58.mov

GitHub Issue Link (if applicable)

Testing Plan

  • Added e2e test.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@lukasmasuch lukasmasuch marked this pull request as ready for review February 28, 2025 13:19
@lukasmasuch lukasmasuch added security-assessment-completed Security assessment has been completed for PR change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Feb 28, 2025
// we need to convert the specific HTML element (used for tooltips) from
// the display value into an actual span element.
formattedContent = formattedContent.replace(
`<span class="pd-t"></span>`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it would be best to use a regex to replace it only if it is at the end of formattedContent? I doubt it will ever make a difference, but it makes the code consistent with the check for formattedContent.endsWith(`<span class="pd-t"></span>`).

Suggested change
`<span class="pd-t"></span>`,
/<span class="pd-t"><\/span>$/,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that should work as well 👍 Changed it

Copy link
Contributor

@JosephMarinier JosephMarinier left a comment

Choose a reason for hiding this comment

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

Cool! Thank you very much!

formattedContent &&
formattedContent.endsWith(`<span class="pd-t"></span>`)
) {
// This is a bit hacky, but to support the Pandas Styler's tooltip feature,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a bit ugly, but it seems like the likelihood that we enter this block as a false positive is extremely low.

Copy link
Collaborator Author

@lukasmasuch lukasmasuch Mar 4, 2025

Choose a reason for hiding this comment

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

Yeah, unfortunately the ugly part already happens in the hacky way were are parsing pandas styler display values out of the html representation of the dataframe :(

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems more likely that one day we may no longer enter this block if Pandas makes changes, for example to the CSS class name. No catastrophic consequences, just no tooltips. I'll let you know if I catch that happening. 😜

Thanks for the review!

@lukasmasuch lukasmasuch merged commit 1a04951 into develop Mar 4, 2025
32 checks passed
@lukasmasuch lukasmasuch deleted the feature/add-styler-tooltip-support-to-table branch March 4, 2025 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

st.dataframe(styler) and st.table(styler) raise an AttributeError when using styler.set_tooltips()

4 participants