question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Histogramdd returns negative values after bins were not checked for monotonic increase

See original GitHub issue

A call to np.histogram(2, bins=[1, 3, 1]) will raise a ValueError: bins must increase monotonically. exception. However, arrays generated with a datatype of uint64 or np.uint64 will not be checked (correctly, at least) for monotonicity and will execute without a problem, generating a histogram with a negative value:

hist, edges = np.histogram(2, bins=np.array([1, 3, 1], dtype='uint64'))
# hist == np.array([1, -1]) 

The two problems here are obvious:

  1. numpy doesn’t check the monotonicity of the bins, or at least does so incorrectly.
  2. A histogram with a negative value is returned.

I’m using numpy version 1.12.1 with Python 3.6.1 on Windows 64 bit. Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
eric-wiesercommented, May 1, 2018

Hey look, a float-integer overflow bug:

def test_large_integers():
    big = 2**60  # Too large to represent with a full precision float

    x = np.array([0], np.int64)
    x_edges = np.array([-1, +1], np.int64)
    y = big + x
    y_edges = big + x_edges

    hist, edges = histogramdd((x, y), bins=(x_edges, y_edges))

gives, on 1.13.3:

ValueError: Found bin edge of size <= 0. Did you specify `bins` withnon-monotonic sequence?

This one is definitely strictly increasing

0reactions
mattipcommented, May 14, 2018

#11023 has been merged, this no longer raises on master

Read more comments on GitHub >

github_iconTop Results From Across the Web

bins must increase monotonically - Stack Overflow
The histogram is of course not sorted and therefore the "bins must increase monotonically"-error is thrown.
Read more >
numpy.histogram — NumPy v1.24 Manual
If bins is a sequence, it defines a monotonically increasing array of bin edges, including the rightmost edge, allowing for non-uniform bin widths....
Read more >
sklearn.ensemble.HistGradientBoostingRegressor
Monotonic constraint to enforce on each feature are specified using the following integer values: 1: monotonic increase. 0: no constraint.
Read more >
Metrics Types - Datadog Docs
This number of events can accumulate or decrease over time—it is not monotonically increasing. Note: A COUNT is different from the RATE metric...
Read more >
numpy.lib.function_base — epygram 1.2.15 documentation
If the IQR is 0, this function returns 1 for the number of bins. ... Do not modify the original value of range...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found