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.

`numpy.histogram` is returning an array of `int64`, which is breaking compatibility with bindings/C wrapper code

See original GitHub issue

Due to this change:

https://github.com/numpy/numpy/commit/34b582aadae8272e7b7209f7a05594e9258ba217#diff-9d44603693b9544b900e135a203b3ae2R180

    # Histogram is an integer or a float array depending on the weights.
    if weights is None:
        ntype = np.dtype(np.intp)  # <---
    else:
        ntype = weights.dtype

numpy.histogram is choosing intp as the return type for the histogram values. This is breaking compatibility with wrapper code that expects simple ints (int32 are fine, as are python long, but usually C wrapper code can’t handle numpy.int64). What is worse is that the behaviour is platform-dependent (i.e., it keeps working on 32-bit platforms).

Could it be changed to simply use int as dtype (i.e., would use numpy.int32)?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rkerncommented, May 13, 2016

You generally want to use PyNumber API instead of the PyLong API if you want to be able to use numpy scalar objects. You don’t need to use the numpy API.

1reaction
jaimefriocommented, May 12, 2016

In a 64 bit system you could have an input to histogram having more than 2**31 - 1 identical values, which would result in an int32 overflowing. So I think it is pretty much uncontroversial that the right thing to do is to go with np.intp.

It’s hard to tell without knowing more details, but the issue here seems to be that your wrapper code is not ready to work on 64 bit systems, and you will need to adapt it to fix that, not expect NumPy to sacrifice correctness for your convenience.

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
How to make a numpy histogram contain the right bin edge ...
By default the bins in numpy.histogram work by including the left bin edge and not the right bin edge. For example: array =...
Read more >
NumPy.histogram() Method in Python - GeeksforGeeks
A histogram is the best way to visualize the frequency distribution of a dataset by splitting it into small equal-sized intervals called ...
Read more >
Python Histogram Plotting: NumPy, Matplotlib, Pandas ...
Large array of data, and you want to compute the “mathematical” histogram that represents bins and the corresponding frequencies. NumPy's np. histogram() and ......
Read more >
NumPy compatibility — boost-histogram docs
Accessing the storage array#. You can access the storage of any Histogram using .view() , see Histogram. NumPy tuple ...
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