Skip to content

Commit

Permalink
Sunburst parent copy (#2640)
Browse files Browse the repository at this point in the history
* wip: remove part of the bug

* added test

* handle more cases

* black

* add tests

* debug

* added tests and solved name conflict

* fine-tuning

* Revert "added test"

This reverts commit 79ac151.

* empty commit

* debug
  • Loading branch information
emmanuelle authored Jul 15, 2020
1 parent 2e99103 commit 4fd8736
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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 @@ -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:
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

0 comments on commit 4fd8736

Please sign in to comment.