diff options
author | Ralf Gommers <ralf.gommers@googlemail.com> | 2011-03-29 21:56:25 +0200 |
---|---|---|
committer | Ralf Gommers <ralf.gommers@googlemail.com> | 2011-03-30 19:07:21 +0200 |
commit | 3ebc34878f3fd1200305f06ed0d6ba1a3529b457 (patch) | |
tree | d05a8d473256758b4e21856b58521c8b7a61ca2d /numpy/lib/tests/test_function_base.py | |
parent | d8b1b5a3a0e6a80256e1be3e652ed84a73432b24 (diff) | |
download | numpy-3ebc34878f3fd1200305f06ed0d6ba1a3529b457.tar.gz |
DEP: deprecate normed kw in histogram and restore its old behavior. Introduce
density kw.
This reverts part of the following commits:
3743430e
400a2a67
3743430e
Behavior for normed keyword is again the same as it was in Numpy 1.5. The
desired behavior (probability density) is implemented by the new density
keyword, which reflects the functionality better than "normed".
For a discussion on this issue, see the Numpy mailing list thread started on
Aug 6th, 2010.
Diffstat (limited to 'numpy/lib/tests/test_function_base.py')
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 6e80b0438..ea3ca4000 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -565,10 +565,25 @@ class TestHistogram(TestCase): area = sum(a * diff(b)) assert_almost_equal(area, 1) + # Check with non-constant bin widths (buggy but backwards compatible) + v = np.arange(10) + bins = [0, 1, 5, 9, 10] + a, b = histogram(v, bins, normed=True) + area = sum(a * diff(b)) + assert_almost_equal(area, 1) + + def test_density(self): + # Check that the integral of the density equals 1. + n = 100 + v = rand(n) + a, b = histogram(v, density=True) + area = sum(a * diff(b)) + assert_almost_equal(area, 1) + # Check with non-constant bin widths v = np.arange(10) bins = [0,1,3,6,10] - a, b = histogram(v, bins, normed=True) + a, b = histogram(v, bins, density=True) assert_array_equal(a, .1) assert_equal(sum(a*diff(b)), 1) @@ -576,14 +591,13 @@ class TestHistogram(TestCase): # infinities. v = np.arange(10) bins = [0,1,3,6,np.inf] - a, b = histogram(v, bins, normed=True) + a, b = histogram(v, bins, density=True) assert_array_equal(a, [.1,.1,.1,0.]) # Taken from a bug report from N. Becker on the numpy-discussion # mailing list Aug. 6, 2010. - counts, dmy = np.histogram([1,2,3,4], [0.5,1.5,np.inf], normed=True) + counts, dmy = np.histogram([1,2,3,4], [0.5,1.5,np.inf], density=True) assert_equal(counts, [.25, 0]) - warnings.filters.pop(0) def test_outliers(self): # Check that outliers are not tallied @@ -646,13 +660,10 @@ class TestHistogram(TestCase): wa, wb = histogram([1, 2, 2, 4], bins=4, weights=[4, 3, 2, 1], normed=True) assert_array_almost_equal(wa, array([4, 5, 0, 1]) / 10. / 3. * 4) - warnings.filterwarnings('ignore', \ - message="\s*This release of NumPy fixes a normalization bug") # Check weights with non-uniform bin widths a,b = histogram(np.arange(9), [0,1,3,6,10], \ - weights=[2,1,1,1,1,1,1,1,1], normed=True) + weights=[2,1,1,1,1,1,1,1,1], density=True) assert_almost_equal(a, [.2, .1, .1, .075]) - warnings.filters.pop(0) def test_empty(self): a, b = histogram([], bins=([0,1])) |