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

Skip to content

Conversation

@BigBird404
Copy link
Contributor

Describe your changes

The issue was that after styling a streamlit dataframe with pandas styler when retrieving the "display_value" of an enum object, the result returned was the object's name rather than its actual value. This has now been corrected, and the proper value of the enum object is returned as expected.

To achieve this, a simple check was added to determine whether the object is of this specific type, and if so, its actual value is correctly returned.

GitHub Issue Link (if applicable)

Fixes #10637

Testing Plan

I added a new unit test that reflects the behavior described in the issue, although in a simplified form.
This test was failing prior to the fix.


Contribution License Agreement

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

@snyk-io
Copy link
Contributor

snyk-io bot commented Apr 7, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@BigBird404
Copy link
Contributor Author

Pushed a fix for the test failures.

Fixed min_dep_tests by replacing map with applymap in the test I had written. This change ensures compatibility with the version of pandas used in these tests.

@kmcgrady kmcgrady self-assigned this Apr 28, 2025
@lukasmasuch lukasmasuch added change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels May 1, 2025
@BigBird404
Copy link
Contributor Author

hi @kmcgrady ,
Would it be possible for you to take a look?
thanks!

@kmcgrady
Copy link
Collaborator

Hey @BigBird404 Sorry for the delay. I am on vacation, and I will review this next week. Thank you for your patience!

@kmcgrady kmcgrady added the security-assessment-completed Security assessment has been completed for PR label Jun 2, 2025
@kmcgrady
Copy link
Collaborator

kmcgrady commented Jun 2, 2025

Hey @BigBird404 Appreciate your patience. Everything looks good. Can you just rebase off the latest develop and resolve the conflict? Happy to help if needed.

…rame

After styling a streamlit dataframe with pandas styler the expected
output was as enum value but it was outputting an enum object.

To solve the problem we had to ensure that for Enum objects the
program will retrieve the enum value.

A test has also been added to ensure this issue doesn't reoccur.
…rame

Fixed min_dep_test by replacing map with applymap.
Which is compatible with the version of pandas used in these tests.
@BigBird404
Copy link
Contributor Author

BigBird404 commented Jun 2, 2025

Hey @kmcgrady ,
Just finished the rebase as requested, let me know if you need anything else!

r, c = map(int, match.groups())
new_df.iloc[r, c] = str(cell["display_value"])
if "id" in cell:
if match := cell_selector_regex.match(cell["id"]):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is triggering our linters. I think it should be back to the original with the and (on line 266). Any reason this needed to be separated?

@lukasmasuch lukasmasuch requested a review from Copilot June 4, 2025 19:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue with enum formatting in styled Streamlit dataframes by ensuring that the actual enum value is displayed instead of its member name. Key changes include adding a unit test to verify the correct display value, updating the pandas styler utility to handle enum objects, and importing the necessary enum dependency.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/tests/streamlit/elements/arrow_dataframe_test.py Added a new unit test to assert that enum display values are correctly rendered.
lib/streamlit/elements/lib/pandas_styler_utils.py Modified the _use_display_values function to check for enum types and display their actual value.

…rame

Combined the two if statements into one and added comments.
@BigBird404
Copy link
Contributor Author

BigBird404 commented Jun 5, 2025

Hey @kmcgrady,
I've combined the two if statements into one and added the suggested comments.
I looked through some old commits to understand why I had separated them, it turns out they were split when I first started working on this, not sure why. Let me know if you need anything else!

Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Thanks for the contribution!

@sfc-gh-lmasuch sfc-gh-lmasuch merged commit 361c0c1 into streamlit:develop Jun 9, 2025
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix 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.

Enum formatting in TextColumn does not work with a styled data frame

4 participants