diff options
author | lzkelley <lkelley@cfa.harvard.edu> | 2015-11-15 17:25:45 -0500 |
---|---|---|
committer | lzkelley <lkelley@cfa.harvard.edu> | 2015-11-17 14:00:38 -0500 |
commit | 46d2e8356760e7549d0c80da9fe232177924183c (patch) | |
tree | 1fe484ba26adcc55b923ed3ac25defb73df26f7f /numpy/lib/function_base.py | |
parent | cf66c68c6a560c934f4a767934573c7f85dcb4ae (diff) | |
download | numpy-46d2e8356760e7549d0c80da9fe232177924183c.tar.gz |
BUG, MAINT: check that histogram range parameters are finite, add tests to assure this. Improved some error-types.
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index fef69dff3..9261dba22 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -336,8 +336,12 @@ def histogram(a, bins=10, range=None, normed=False, weights=None, if (range is not None): mn, mx = range if (mn > mx): - raise AttributeError( + raise ValueError( 'max must be larger than min in range parameter.') + if not np.all(np.isfinite([mn, mx])): + raise ValueError( + 'range parameter must be finite.') + if isinstance(bins, basestring): bins = _hist_optim_numbins_estimator(a, bins) @@ -422,7 +426,7 @@ def histogram(a, bins=10, range=None, normed=False, weights=None, else: bins = asarray(bins) if (np.diff(bins) < 0).any(): - raise AttributeError( + raise ValueError( 'bins must increase monotonically.') # Initialize empty histogram @@ -533,7 +537,7 @@ def histogramdd(sample, bins=10, range=None, normed=False, weights=None): try: M = len(bins) if M != D: - raise AttributeError( + raise ValueError( 'The dimension of bins must be equal to the dimension of the ' ' sample x.') except TypeError: @@ -551,6 +555,9 @@ def histogramdd(sample, bins=10, range=None, normed=False, weights=None): smin = atleast_1d(array(sample.min(0), float)) smax = atleast_1d(array(sample.max(0), float)) else: + if not np.all(np.isfinite(range)): + raise ValueError( + 'range parameter must be finite.') smin = zeros(D) smax = zeros(D) for i in arange(D): |