plotly / plotly/plotly.py

add "Non-leaves rows are not permitted in the dataframe" with sunburst diagrams

Offen
#3,589 2 Kommentare 7 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature P3
Vorherrschende Sprache
Python
Sterne
18.8k
Forks
2.8k
Ø Merge
16 Std. 26 Min.
Gemergte PRs (30 T.)
21

Beschreibung

It is sometimes useful to have non-leaf data in a Sunburst diagram. However, there is no way to tell Plotly Express to ignore or accept non-leaves.

Minimum viable example:

import pandas as pd
import plotly.express as px
lst = [['Alice', "Bob"], ['Alice', "Bob", "Carrie"], ["Alice", "Bob", "Chuck"]]
df = pd.DataFrame(lst)
fig = px.sunburst(df, path=df.columns)

Gives the error:

ValueError: ('Non-leaves rows are not permitted in the dataframe \n', 0 Alice
1 Bob
2
Name: 0, dtype: object, 'is not a leaf.')

This can be fixed by commenting out part of plotly/express/_core.py

def _check_dataframe_all_leaves(df):
    df_sorted = df.sort_values(by=list(df.columns))
    null_mask = df_sorted.isnull()
    df_sorted = df_sorted.astype(str)
    null_indices = np.nonzero(null_mask.any(axis=1).values)[0]
    for null_row_index in null_indices:
        row = null_mask.iloc[null_row_index]
        i = np.nonzero(row.values)[0][0]
        if not row[i:].all():
            raise ValueError(
                "None entries cannot have not-None children",
                df_sorted.iloc[null_row_index],
            )
    df_sorted[null_mask] = ""
    row_strings = list(df_sorted.apply(lambda x: "".join(x), axis=1))
    #for i, row in enumerate(row_strings[:-1]):
        #if row_strings[i + 1] in row and (i + 1) in null_indices:
            #raise ValueError(
            #    "Non-leaves rows are not permitted in the dataframe \n",
            #    df_sorted.iloc[i + 1],
            #    "is not a leaf.",
            #)

It would be great if px.sunburst could have an option to disable these checks, or to skip over any row which is not a leaf.

How can I propose this as an option?

Thanks!

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne in plotly/express/_core.py bei _check_dataframe_all_leaves und reproduziere das Problem mit dem bereitgestellten pandas- und px.sunburst-Beispiel. Untersuche, wie px.sunburst eine Option anbieten könnte, um Nicht-Blatt-Zeilen zu akzeptieren oder zu überspringen, und definiere die Aufgabe als abgeschlossen, wenn das Beispiel bei aktivierter Option nicht mehr den aktuellen Fehler für Nicht-Blatt-Zeilen auslöst.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
data-visualization
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.