-
Notifications
You must be signed in to change notification settings - Fork 4k
[Fix] Enum formatting not working with styled dataframes #11049
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
Conversation
🎉 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) |
|
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. |
|
hi @kmcgrady , |
|
Hey @BigBird404 Sorry for the delay. I am on vacation, and I will review this next week. Thank you for your patience! |
|
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.
|
Hey @kmcgrady , |
| 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"]): |
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.
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?
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.
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.
|
Hey @kmcgrady, |
lukasmasuch
left a comment
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.
LGTM 👍 Thanks for the contribution!
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.