diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2018-03-26 00:28:49 -0700 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2018-03-26 00:52:37 -0700 |
commit | fd92d02152d50735b5ffafcce3a7a722e366b192 (patch) | |
tree | aa9de631c790d4e4d32fd07e6fea9d06c240aace /numpy/lib/histograms.py | |
parent | 52a739e2c1172876fb444a73dafd23247c826d6e (diff) | |
download | numpy-fd92d02152d50735b5ffafcce3a7a722e366b192.tar.gz |
MAINT: Give a more useful error messages for bins of an incorrect dimension
Previously gave `ValueError: object too deep for desired array` from an internal call
This also adds support for 0d array bincounts
Diffstat (limited to 'numpy/lib/histograms.py')
-rw-r--r-- | numpy/lib/histograms.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/numpy/lib/histograms.py b/numpy/lib/histograms.py index 097df2053..a8cd9acb8 100644 --- a/numpy/lib/histograms.py +++ b/numpy/lib/histograms.py @@ -881,18 +881,21 @@ def histogramdd(sample, bins=10, range=None, normed=False, weights=None): edge_dt = float # Create edge arrays for i in np.arange(D): - if np.isscalar(bins[i]): + if np.ndim(bins[i]) == 0: if bins[i] < 1: raise ValueError( '`bins[{}]` must be positive, when an integer'.format(i)) edges[i] = np.linspace(smin[i], smax[i], bins[i] + 1, dtype=edge_dt) - else: + elif np.ndim(bins[i]) == 1: edges[i] = np.asarray(bins[i], edge_dt) # not just monotonic, due to the use of mindiff below if np.any(edges[i][:-1] >= edges[i][1:]): raise ValueError( '`bins[{}]` must be strictly increasing, when an array' .format(i)) + else: + raise ValueError( + '`bins[{}]` must be a scalar or 1d array'.format(i)) nbin[i] = len(edges[i]) + 1 # includes an outlier on each end dedges[i] = np.diff(edges[i]) |