diff options
author | Robert Franke <franke.rob@googlemail.fake> | 2014-02-12 15:20:38 +0100 |
---|---|---|
committer | Robert Franke <franke.rob@googlemail.fake> | 2014-02-12 15:20:38 +0100 |
commit | c4c139bba033c420a6edbe585b2846426e3e694c (patch) | |
tree | 77ab77d428f4985bff0c298d64d0ae7a7ac76de3 /numpy/lib | |
parent | f57c77b88a735d5f49a407881777ff2e9f3b1be2 (diff) | |
download | numpy-c4c139bba033c420a6edbe585b2846426e3e694c.tar.gz |
Fix histogramdd treatment of events at rightmost binedge
Fixes Github issue #4266
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/function_base.py | 6 | ||||
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 24 |
2 files changed, 27 insertions, 3 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 63b191b07..21a531211 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -373,10 +373,10 @@ def histogramdd(sample, bins=10, range=None, normed=False, weights=None): if not np.isinf(mindiff): decimal = int(-log10(mindiff)) + 6 # Find which points are on the rightmost edge. - on_edge = where(around(sample[:, i], decimal) == - around(edges[i][-1], decimal))[0] + not_smaller_than_edge = (sample[:, i] >= edges[i][-1]) + on_edge = (around(sample[:, i], decimal) == around(edges[i][-1], decimal)) # Shift these points one bin to the left. - Ncount[i][on_edge] -= 1 + Ncount[i][where(on_edge & not_smaller_than_edge)[0]] -= 1 # Flattened histogram matrix (1D) # Reshape is used so that overlarge arrays diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 003d3e541..82d90311e 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1155,6 +1155,30 @@ class TestHistogramdd(TestCase): h, e = np.histogramdd(x, bins=[3, [-np.inf, 3, np.inf]]) assert_allclose(h, expected) + def test_rightmost_binedge(self): + """Test event very close to rightmost binedge. + See Github issue #4266""" + x = [0.9999999995] + bins = [[0.,0.5,1.0]] + hist, _ = histogramdd(x, bins=bins) + assert_(hist[0] == 0.0) + assert_(hist[1] == 1.) + x = [1.0] + bins = [[0.,0.5,1.0]] + hist, _ = histogramdd(x, bins=bins) + assert_(hist[0] == 0.0) + assert_(hist[1] == 1.) + x = [1.0000000001] + bins = [[0.,0.5,1.0]] + hist, _ = histogramdd(x, bins=bins) + assert_(hist[0] == 0.0) + assert_(hist[1] == 1.) + x = [1.0001] + bins = [[0.,0.5,1.0]] + hist, _ = histogramdd(x, bins=bins) + assert_(hist[0] == 0.0) + assert_(hist[1] == 0.0) + class TestUnique(TestCase): def test_simple(self): |