8000 fix: custom category order was hard-coded by MarcoGorelli · Pull Request #5000 · plotly/plotly.py · GitHub
[go: up one dir, main page]

Skip to content

fix: custom category order was hard-coded #5000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add go.Pie comparison
  • Loading branch information
MarcoGorelli committed Jan 30, 2025
commit 9043fff3a286e36d8599029b94335fa830821801
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,35 @@ def test_pie_like_px():

def test_pie_custom_category_order(constructor):
# https://github.com/plotly/plotly.py/issues/4999
df = constructor(
{
"status": ["On Route", "Pending", "Waiting Result", "Delivered"],
"count": [28, 10, 73, 8],
}
)
data = {
"status": ["On Route", "Pending", "Waiting Result", "Delivered"],
"count": [28, 10, 73, 8],
}
df = constructor(data)
custom_order = ["Pending", "Waiting Result", "On Route", "Delivered"]
result = px.pie(
data_frame=df,
values="count",
names="status",
category_orders={"status": custom_order},
).to_dict()
assert list(result["data"][0]["labels"]) == [
)
assert list(result.to_dict()["data"][0]["labels"]) == [
"Pending",
"Waiting Result",
"On Route",
"Delivered",
]
values_ = np.array(
[
x[0]
for x in sorted(
zip(data["count"], data["status"]),
key=lambda t: custom_order.index(t[1]),
)
]
)
trace = go.Pie(values=values_, labels=custom_order)
_compare_figures(trace, result)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was doing a similar fix 🙈

You could also add the comparison with go.Pie:

    values_ = np.array([
        x[0] for x in sorted(zip(data["count"], data["status"]), key=lambda t: custom_order.index(t[1]))
    ])
    trace = go.Pie(
        values=values_,
        labels=custom_order,
    )
    _compare_figures(trace, fig)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, thanks for reviewing!


def test_sunburst_treemap_colorscales():
Expand Down
0