np.histogram gives confusing error message when NaN is encountered
See original GitHub issueIf one tries to do np.histogram([1,2,3,4,np.nan])
, then an error message is thrown:
ValueError: range parameter must be finite.
This message is somewhat confusing, because I had to open up the source code of histogram
to see that mn
and mx
, which were determined from a.min()
and a.max()
, were NaN because of NaN’s in the input data.
Is it possible to change it to something like “input data contains NaN, which is not supported”?
Python version: 3.6 numpy version: 1.13.3
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
python - pylab histogram get rid of nan - Stack Overflow
I can get rid of the error by using nan_to_num from numpy, but than i get a lot of zero values which mess...
Read more >Release Notes — NumPy v1.15 Manual
Since the range is ignored anyway when the bins are given explicitly, this error was needless. Note that calling histogram on NaN values ......
Read more >Release Notes — NumPy v1.17 Manual
NumPy 1.16.2 is a quick release fixing several problems encountered on Windows ... Chain exceptions to give better error messages for invalid PEP3118...
Read more >Removing NaN Values in Python Quantopian
1 Answer 1 · You should use numpy to check for NaN s, not use the equals operator. np. · You shouldn't use...
Read more >numpy.lib.function_base — epygram 1.2.15 documentation
return x.ptp() / np.sqrt(x.size) def _hist_bin_sturges(x): """ Sturges histogram bin estimator. A very simplistic estimator based on the assumption of ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Same message in 1.15
Note that input containing NaN is supported, but only if a range parameter is specified. The same behavior can be seen for infinities too - so perhaps
"autodetected range of [{min}, {max}] is not finite"
A patch should be fairly straightforward
Could this be improved by giving the option to use np.nanmin and np.nanmax? Or make this the default?