Skip to content

histogram crashes cryptically with single float bin #8072

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

Closed
guetg opened this issue Sep 20, 2016 · 3 comments
Closed

histogram crashes cryptically with single float bin #8072

guetg opened this issue Sep 20, 2016 · 3 comments

Comments

@guetg
Copy link

guetg commented Sep 20, 2016

This code:
np.histogram(np.random.random(1000), bins=100.1) # Crashes

works fine with python3.4 & numpy 1.9.2. However it crashes with 3.5.2 & numpy 1.11.1 with the following error msg:

 File "test.py", line 8, in <module>
     np.histogram(np.random.random(1000), bins=100.1)
 File "/home/bin/anaconda3/lib/python3.5/site-packages/numpy/lib/function_base.py", line 603, in histogram
      increment = (tmp_a_data >= bin_edges[indices + 1]) & (indices != bins - 1)
  IndexError: index 101 is out of bounds for axis 1 with size 101

I know that bins should be int, but I would suggest either better error message or floor/ceil to make it int like in 1.9.2

@charris
Copy link
Member

charris commented Sep 20, 2016

In master this raises an a somewhat better, but totally misleading, error

TypeError: 'float' object cannot be interpreted as an index

@seberg
Copy link
Member

seberg commented Sep 20, 2016

Just a side comment, I just noticed (after wondering about whether a change in python would make sense), that this is actually changed in python, so that it does say "integer" instead of the confusing "index in python 3.5 (probably earlier, thought not my python 2.7).

@eric-wieser
Copy link
Member

eric-wieser commented Oct 20, 2017

Now raises TypeError( '`bins` must be an integer, a string, or an array')

theodoregoetz pushed a commit to theodoregoetz/numpy that referenced this issue Oct 23, 2017
Split up the overloaded `bins` variable into separate names depending on its meaning

Helpful errors are now emitted for:
* non-integer bin counts (fixes numpygh-8072)
* non-1d bin edges

Removes another use of `np.isscalar`...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants