Skip to content
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

Fix ZeroDivisionError in pointplot when dodge=True and a single hue level exists #3831

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

notval98
Copy link

This PR fixes a ZeroDivisionError in sns.pointplot that occurs when dodge=True and the dataset contains only a single hue level. The issue arises because step_size is calculated using (n_hue_levels - 1), which results in a division by zero when n_hue_levels == 1.

Changes Made:
Updated categorical.py to prevent division by zero in the dodge calculation by adding a conditional check:
if n_hue_levels > 1:
step_size = dodge / (n_hue_levels - 1)
else:
step_size = 0 # Prevents division by zero when only one hue level exists

This ensures that when there is only one hue level, the dodge offset remains 0, preventing unnecessary adjustments.

Issue Reference:
Fixes #3825

Testing:
Verified that pointplot no longer raises an error when dodge=True with a single hue level.

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.

sns.pointplot breaks when dodge=True and dataset has a single hue level
1 participant