From 2f3b82638a24204a13c9b16a3a36a59f199df41d Mon Sep 17 00:00:00 2001 From: MatteoRaso <33975162+MatteoRaso@users.noreply.github.com> Date: Thu, 7 May 2020 07:49:14 -0400 Subject: 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 --- numpy/lib/histograms.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'numpy/lib/histograms.py') 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:]): -- cgit v1.2.1