[Numpy-svn] r8674 - in trunk/numpy/lib: . tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Mon Aug 30 13:24:58 EDT 2010
Author: dhuard
Date: 2010-08-30 12:24:57 -0500 (Mon, 30 Aug 2010)
New Revision: 8674
Modified:
trunk/numpy/lib/function_base.py
trunk/numpy/lib/tests/test_function_base.py
Log:
added a warning concerning the buggy normalization in histogram with non-uniform bin widths
Modified: trunk/numpy/lib/function_base.py
===================================================================
--- trunk/numpy/lib/function_base.py 2010-08-30 10:56:17 UTC (rev 8673)
+++ trunk/numpy/lib/function_base.py 2010-08-30 17:24:57 UTC (rev 8674)
@@ -155,8 +155,10 @@
mn -= 0.5
mx += 0.5
bins = linspace(mn, mx, bins+1, endpoint=True)
+ uniform = True
else:
bins = asarray(bins)
+ uniform = False
if (np.diff(bins) < 0).any():
raise AttributeError(
'bins must increase monotonically.')
@@ -191,7 +193,16 @@
if normed:
db = array(np.diff(bins), float)
+ if not uniform:
+ warnings.warn("""
+ This release of NumPy fixes a normalization bug in histogram
+ function occuring with non-uniform bin widths. The returned
+ value is now a density: n / (N * bin width), where n is the
+ bin count and N the total number of points.
+ """)
return n/db/n.sum(), bins
+
+
else:
return n, bins
Modified: trunk/numpy/lib/tests/test_function_base.py
===================================================================
--- trunk/numpy/lib/tests/test_function_base.py 2010-08-30 10:56:17 UTC (rev 8673)
+++ trunk/numpy/lib/tests/test_function_base.py 2010-08-30 17:24:57 UTC (rev 8674)
@@ -565,6 +565,7 @@
area = sum(a * diff(b))
assert_almost_equal(area, 1)
+ warnings.simplefilter('ignore', Warning)
# Check with non-constant bin widths
v = np.arange(10)
bins = [0,1,3,6,10]
@@ -583,6 +584,7 @@
# mailing list Aug. 6, 2010.
counts, dmy = np.histogram([1,2,3,4], [0.5,1.5,np.inf], normed=True)
assert_equal(counts, [.25, 0])
+ warnings.resetwarnings()
def test_outliers(self):
# Check that outliers are not tallied
@@ -645,12 +647,13 @@
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.simplefilter('ignore', Warning)
# 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)
assert_almost_equal(a, [.2, .1, .1, .075])
+ warnings.resetwarnings()
-
class TestHistogramdd(TestCase):
def test_simple(self):
x = array([[-.5, .5, 1.5], [-.5, 1.5, 2.5], [-.5, 2.5, .5], \
More information about the Numpy-svn
mailing list