diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-12-22 15:31:38 -0800 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-12-24 09:48:03 +0000 |
commit | 99f605c4545597e9a3bdf66f97b98da30f78ae33 (patch) | |
tree | 5372261f51d84b6a26dffc76b4812a874152bede /numpy/lib | |
parent | aecee019491defc79c7a881a2418803164887d74 (diff) | |
download | numpy-99f605c4545597e9a3bdf66f97b98da30f78ae33.tar.gz |
BUG: Fix misleading error when coercing to array
Closes gh-7864
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/histograms.py | 2 | ||||
-rw-r--r-- | numpy/lib/tests/test_histograms.py | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/numpy/lib/histograms.py b/numpy/lib/histograms.py index 2dc2df31b..21a7ab8be 100644 --- a/numpy/lib/histograms.py +++ b/numpy/lib/histograms.py @@ -228,7 +228,7 @@ def _get_outer_edges(a, range): if first_edge > last_edge: raise ValueError( 'max must be larger than min in range parameter.') - if not np.all(np.isfinite([first_edge, last_edge])): + if not (np.isfinite(first_edge) and np.isfinite(last_edge)): raise ValueError( 'range parameter must be finite.') if first_edge == last_edge: diff --git a/numpy/lib/tests/test_histograms.py b/numpy/lib/tests/test_histograms.py index 59baf91fe..8319041b8 100644 --- a/numpy/lib/tests/test_histograms.py +++ b/numpy/lib/tests/test_histograms.py @@ -238,6 +238,17 @@ class TestHistogram(object): with assert_raises(ValueError): hist, edges = np.histogram(arr, bins=bins) + def test_object_array_of_0d(self): + # gh-7864 + assert_raises(ValueError, + histogram, [np.array([0.4]) for i in range(10)] + [-np.inf]) + assert_raises(ValueError, + histogram, [np.array([0.4]) for i in range(10)] + [np.inf]) + + # these should not crash + np.histogram([np.array([0.5]) for i in range(10)] + [.500000000000001]) + np.histogram([np.array([0.5]) for i in range(10)] + [.5]) + class TestHistogramOptimBinNums(object): """ |