diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index a97d52c21f..f283cb3cde 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1550,8 +1550,9 @@ def aggfunc_continuous(x): for col in cols: # for hover_data, custom_data etc. if col not in agg_f: agg_f[col] = aggfunc_discrete + # Avoid collisions with reserved names - columns in the path have been copied already + cols = list(set(cols) - set(["labels", "parent", "id"])) # ---------------------------------------------------------------------------- - df_all_trees = pd.DataFrame(columns=["labels", "parent", "id"] + cols) # Set column type here (useful for continuous vs discrete colorscale) for col in cols: diff --git a/packages/python/plotly/plotly/tests/test_core/test_px/test_px_functions.py b/packages/python/plotly/plotly/tests/test_core/test_px/test_px_functions.py index 00245db3ab..e8c95860ce 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_px/test_px_functions.py +++ b/packages/python/plotly/plotly/tests/test_core/test_px/test_px_functions.py @@ -250,6 +250,26 @@ def test_sunburst_treemap_with_path_color(): assert np.all(np.array(colors[:8]) == np.array(calls)) +def test_sunburst_treemap_column_parent(): + vendors = ["A", "B", "C", "D", "E", "F", "G", "H"] + sectors = [ + "Tech", + "Tech", + "Finance", + "Finance", + "Tech", + "Tech", + "Finance", + "Finance", + ] + regions = ["North", "North", "North", "North", "South", "South", "South", "South"] + values = [1, 3, 2, 4, 2, 2, 1, 4] + df = pd.DataFrame(dict(id=vendors, sectors=sectors, parent=regions, values=values,)) + path = ["parent", "sectors", "id"] + # One column of the path is a reserved name - this is ok and should not raise + fig = px.sunburst(df, path=path, values="values") + + def test_sunburst_treemap_with_path_non_rectangular(): vendors = ["A", "B", "C", "D", None, "E", "F", "G", "H", None] sectors = [