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.

np.histogram gives confusing error message when NaN is encountered

See original GitHub issue

If 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
eric-wiesercommented, Feb 16, 2018

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

1reaction
whtowbincommented, Aug 10, 2019

Could this be improved by giving the option to use np.nanmin and np.nanmax? Or make this the default?

Read more comments on GitHub >

github_iconTop 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 >

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