Repository navigation
Fix px hierarchy charts with a categorical color column - #5901
Open
Avalon2222 wants to merge 2 commits into
Open
Avalon2222 wants to merge 2 commits into
Avalon2222 wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to issue
No existing issue, the bug and a reproduction are below.
Description of change
px.sunburst,px.treemapandpx.iciclefail whenpathis used andcoloris a categorical column (pandascategory, PolarsEnum, PyArrow dictionary). This worked in plotly 5.24.1 and is broken in 7.1.0. Inprocess_dataframe_hierarchy, discrete colors are aggregated withmax()and mixed parents get"(?)".max()is not defined for an unordered categorical, and"(?)"is not one of the categories, so both steps fail. This PR casts a categorical or enum color column to string before thegroup_by, so the figure is the same as with a plain string column.Other backends failed with
Cannot setitem on a Categorical with a new category(ordered pandas categorical),conversion from str to enum failed ... ["(?)"](PolarsEnum) andFunction 'hash_min_max' has no kernel matching input types (dictionary<...>)(PyArrow).Testing strategy
Added
test_sunburst_treemap_with_path_categorical_color, which runs for every dataframe constructor and for sunburst, treemap and icicle, and checks that the ids and colors match the plain string column. Also addedtest_sunburst_treemap_with_path_enum_colorfor PolarsEnum. The new tests fail without the change.tests/test_optional/test_pxpasses locally (1251 passed, 13 skipped, 4 xfailed).Additional information (optional)
I used an AI coding assistant to help write and test this change, and I reviewed it myself.
Guidelines