Skip to content
3 changes: 2 additions & 1 deletion packages/python/plotly/plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1546,8 +1546,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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down