From da0a4f443847558d7675b14ca0af3265ceb87956 Mon Sep 17 00:00:00 2001 From: Maximilien Colange Date: Wed, 2 Oct 2024 13:37:07 +0200 Subject: [PATCH] remove check for non-leaf node fixes #4774 and #3589 --- packages/python/plotly/plotly/express/_core.py | 9 --------- .../test_optional/test_px/test_px_functions.py | 18 +++++++++++++++--- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 9a79810506d..a7312f550ca 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1633,15 +1633,6 @@ def _check_dataframe_all_leaves(df): "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.", - ) def process_dataframe_hierarchy(args): diff --git a/packages/python/plotly/plotly/tests/test_optional/test_px/test_px_functions.py b/packages/python/plotly/plotly/tests/test_optional/test_px/test_px_functions.py index ec27441d6c1..55f58cc5ce1 100644 --- a/packages/python/plotly/plotly/tests/test_optional/test_px/test_px_functions.py +++ b/packages/python/plotly/plotly/tests/test_optional/test_px/test_px_functions.py @@ -320,13 +320,25 @@ def test_sunburst_treemap_with_path_non_rectangular(): ) ) path = ["total", "regions", "sectors", "vendors"] - msg = "Non-leaves rows are not permitted in the dataframe" - with pytest.raises(ValueError, match=msg): - fig = px.sunburst(df, path=path, values="values") + fig = px.sunburst(df, path=path, values="values") + assert fig.data[0].values[-1] == np.sum(values) df.loc[df["vendors"].isnull(), "sectors"] = "Other" fig = px.sunburst(df, path=path, values="values") assert fig.data[0].values[-1] == np.sum(values) + df = pd.DataFrame( + { + "status": ["NOT_YET_COMPLETED", "COMPLETED"], + "next_step": ["Wrapup", None], + "count": [1, 2], + } + ) + fig = px.sunburst(df, path=["status", "next_step"], values="count") + assert fig.data[0].values[-1] == 3 + df.loc[0, "status"] = "ACTIVE_NOT_YET_COMPLETED" + fig = px.sunburst(df, path=["status", "next_step"], values="count") + assert fig.data[0].values[-1] == 3 + def test_pie_funnelarea_colorscale(): labels = ["A", "B", "C", "D"]