diff options
author | MatteoRaso <33975162+MatteoRaso@users.noreply.github.com> | 2020-05-07 07:49:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-07 14:49:14 +0300 |
commit | 2f3b82638a24204a13c9b16a3a36a59f199df41d (patch) | |
tree | 89ee2e14e06744a7ea05034a0d9f75424de9ed78 | |
parent | 666b17976e1ee7bb2079259831ccba41d37cf078 (diff) | |
download | numpy-2f3b82638a24204a13c9b16a3a36a59f199df41d.tar.gz |
ENH: Better error message when ``bins`` has float value in ``histogramdd``. (#16129)
* Improved one of the error messages for histogramdd.py as outlined in issue #15984
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
-rw-r--r-- | numpy/lib/histograms.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/numpy/lib/histograms.py b/numpy/lib/histograms.py index f080cc392..1a9b41ced 100644 --- a/numpy/lib/histograms.py +++ b/numpy/lib/histograms.py @@ -1047,7 +1047,15 @@ def histogramdd(sample, bins=10, range=None, normed=None, weights=None, raise ValueError( '`bins[{}]` must be positive, when an integer'.format(i)) smin, smax = _get_outer_edges(sample[:,i], range[i]) - edges[i] = np.linspace(smin, smax, bins[i] + 1) + try: + n = operator.index(bins[i]) + + except TypeError as e: + raise TypeError( + "`bins[{}]` must be an integer, when a scalar".format(i) + ) from e + + edges[i] = np.linspace(smin, smax, n + 1) elif np.ndim(bins[i]) == 1: edges[i] = np.asarray(bins[i]) if np.any(edges[i][:-1] > edges[i][1:]): |