plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
16.09k stars 2.54k forks source link

sunburst errors with "Non-leaves are not permitted in the dataframe" #4774

Open EpigeneMax opened 5 days ago

EpigeneMax commented 5 days ago

The logic to check for non-leaves is dubious, e.g. a leaf whose name is a suffix of another leaf triggers an error. The check also depends on the alphabetical ordering on the leaves.

As suggested by #3589, I wonder whether this non-leaf detection is really meaningful. I'd be happy to write a PR to remove this check. Thoughts?

minimal working example

import pandas as pd
import plotly.express as px

df = pd.DataFrame(
    {
        "status": ["NOT_YET_COMPLETED", "COMPLETED"],
        "next_step": ["Wrapup", None],
        "count": [1, 2],
    }
)
# no error
px.sunburst(df, path=["status", "next_step"], values="count")

df.loc[0, "status"] = "ACTIVE_NOT_YET_COMPLETED"
# error (spurious)
px.sunburst(df, path=["status", "next_step"], values="count")
gvwilson commented 5 days ago

@archmoj does this belong here or in plotly.js?

archmoj commented 5 days ago

@LiamConnors would you please create a codepen and transfer it to plotly.js?

EpigeneMax commented 5 days ago

I think the dubious check in on the Python side, plotly/express/_core.py lines 1637 -- 1644.

LiamConnors commented 5 days ago

@LiamConnors would you please create a codepen and transfer it to plotly.js?

The logic is in plotly.express and prevents the figure from being generated so it's not possible to create a codepen for plotly.js