Skip to content

Fix histogram binwidth edge case#3961

Open
ShiroKSH wants to merge 1 commit into
mwaskom:masterfrom
ShiroKSH:fix/histogram-binwidth-edge-case
Open

Fix histogram binwidth edge case#3961
ShiroKSH wants to merge 1 commit into
mwaskom:masterfrom
ShiroKSH:fix/histogram-binwidth-edge-case

Conversation

@ShiroKSH

Copy link
Copy Markdown

Fixes #3646.

Hist._define_bin_edges currently rounds a valid positive binwidth to zero bins whenever the data range is less than half the requested width. Both histplot and objects.Hist then pass zero to NumPy and raise a ValueError.

Keep the existing approximate-width behavior, but use one bin when a finite positive width would round to zero. For constant data, provide a one-width range so singleton histograms preserve the requested width, matching the earlier #2813 behavior. Invalid negative widths remain rejected.

Tests:

  • uv run pytest -q tests/_stats/test_counting.py tests/test_distributions.py tests/test_objects.py (292 passed, 1 skipped)
  • uv run ruff check seaborn/_stats/counting.py tests/_stats/test_counting.py
  • uv run ty check

@ShiroKSH

Copy link
Copy Markdown
Author

@mwaskom We'd appreciate it if you could take a look at this pull request when you have a chance.

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.

Value error in histplot with binwidth smaller than half the data range

1 participant