Skip to content

BUG: lib: Fix histogram problem with signed integer arrays. #14864

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 1 commit into from
Nov 8, 2019

Conversation

charris
Copy link
Member

@charris charris commented Nov 8, 2019

Backport of #14381.

An input such as

np.histogram(np.array([-2, 0, 127], dtype=np.int8), bins="auto")

would raise the exception

ValueError: Number of samples, -1, must be non-negative.

The problem was that the peak-to-peak value for the input array was
computed with the ptp method, which returned negative values for
signed integer arrays when the actual value was more than the
maximum signed value of the array's data type.

The fix is to use a peak-to-peak function that returns an
unsigned value for signed integer arrays.

Closes gh-14379.

An input such as

    np.histogram(np.array([-2, 0, 127], dtype=np.int8), bins="auto")

would raise the exception

    ValueError: Number of samples, -1, must be non-negative.

The problem was that the peak-to-peak value for the input array was
computed with the `ptp` method, which returned negative values for
signed integer arrays when the actual value was more than the
maximum signed value of the array's data type.

The fix is to use a peak-to-peak function that returns an
unsigned value for signed integer arrays.

Closes numpygh-14379.
@charris charris added this to the 1.16.6 milestone Nov 8, 2019
@charris charris closed this Nov 8, 2019
@charris charris reopened this Nov 8, 2019
@charris charris merged commit 08614de into numpy:maintenance/1.16.x Nov 8, 2019
@charris charris deleted the backport-14381 branch November 8, 2019 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants