Fix plot_histogram distribution detection with leading int zeros #15497
+64
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #11949
When a probability distribution dictionary has integer zeros before float values (e.g.,
{0: 0, 1: 0, 2: 0.5, 3: 0.5}),plot_histogramincorrectly detected it as "counts" mode because it only checked the type of the first value. This caused float probabilities to be coerced to integers, resulting in empty or incorrect plots.Changed the detection logic to check if any value is a float, rather than only the first value. This is the approach suggested by @jakelishman in the issue comments.
Changes
plot_histogram()_is_deprecated_data_format()(which the previous PR Fix to #11949: plot_histogram fails to operate correctly when numerous starting and ending values are zero #11979 missed)Test plan
test_plot_histogram.pytests passNote: This is a fresh implementation of the fix from stale PR #11979, with the additional fix for
_is_deprecated_data_format(), tests, and release note that were requested but never added.