Skip to content

fix: Setting category_orders was leading to missing data #4877

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 6 commits into from
Nov 14, 2024

Conversation

MarcoGorelli
Copy link
Contributor

@MarcoGorelli MarcoGorelli commented Nov 14, 2024

closes #4875

The bug in https://github.com/plotly/plotly.py/pull/4790/files was the change

- required_grouper = [g for g in grouper if g != one_group]
+ required_grouper = list(orders.keys())

and in the linked issue #4875, the group 'day' appears in orders but not in required_grouper

I've added a test - here's a visual demo too:

image

Output is also unchanged (compared with the latest PyPI release) when multiple groups point to the same column:

image

@MarcoGorelli MarcoGorelli marked this pull request as ready for review November 14, 2024 12:10
if len(single_group_name) == len(grouper):
# we have a single group, so we can skip all group-by operations!
groups = {tuple(single_group_name): df}
else:
required_grouper = list(orders.keys())
required_grouper = [
key for key in orders if key in grouper and key != one_group
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe one_group will never be in orders so this can be simplified to

Suggested change
key for key in orders if key in grouper and key != one_group
key for key in orders if key in grouper

Copy link
Contributor

@emilykl emilykl left a comment

Choose a reason for hiding this comment

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

Looks good to me @MarcoGorelli , thanks for the quick fix. 🙌 🚀

@LiamConnors Can you confirm this change fixes the issue for you?

@MarcoGorelli
Copy link
Contributor Author

thanks for your review!

sorry for the repeated pushes, kept noticing minor improvements

@FBruzzesi
Copy link
Contributor

Thanks Marco! Apologies for messing this one up 🥲

@LiamConnors
Copy link
Member

Looks good to me too. Thanks @MarcoGorelli !

@emilykl
Copy link
Contributor

emilykl commented Nov 14, 2024

No worries @FBruzzesi , you've just discovered we didn't have a test for this case!

@emilykl emilykl merged commit 2bc6a0f into plotly:master Nov 14, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting category_orders leads to missing data (master branch)
4 participants