Skip to content

Conversation

@ddri
Copy link

@ddri ddri commented Jan 4, 2026

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_histogram incorrectly 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

Test plan

  • All existing test_plot_histogram.py tests pass
  • New tests verify:
    • Distributions with leading/trailing int zeros are detected correctly
    • Mixed int 0 and float 0.0 values are handled
    • Pure integer counts are still detected as counts mode

Note: 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.

When a probability distribution dictionary has integer zeros before
float values (e.g., {0: 0, 1: 0, 2: 0.5, 3: 0.5}), plot_histogram
incorrectly detected it as "counts" mode because it only checked the
type of the first value.

Changed the detection logic to check if any value is a float, rather
than only the first value. This fixes cases where distributions with
leading/trailing integer zeros were coerced to integers, resulting in
empty or incorrect plots.

Fixes Qiskit#11949
@ddri ddri requested a review from a team as a code owner January 4, 2026 06:07
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jan 4, 2026
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the following people are relevant to this code:

@CLAassistant
Copy link

CLAassistant commented Jan 4, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community PR PRs from contributors that are not 'members' of the Qiskit repo

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

plot_histogram fails to operate correctly when numerous starting and ending values are zero

3 participants