diff options
author | Julian Taylor <jtaylor.debian@googlemail.com> | 2014-06-23 22:44:05 +0200 |
---|---|---|
committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2014-06-23 22:49:33 +0200 |
commit | e20d4b91d00cea1cf495d4cb85ee9bc2b7930a3d (patch) | |
tree | c4d8f06f3ce273ca93b6abd92cf52bde06477968 /numpy/lib/tests/test_function_base.py | |
parent | fe3410f7380c06adc81fb8e097c96dc51a42e0f3 (diff) | |
download | numpy-e20d4b91d00cea1cf495d4cb85ee9bc2b7930a3d.tar.gz |
BUG: handle rounding issue with histogram edges on float32 data
Following inequality causes wrong counting at the edges and can be avoided by
making the edge array of the same type as the input data.
In [1]: np.around(np.float64(6010.36962890625), 5)
Out[1]: 6010.3696300000001
In [2]: np.around(np.float32(6010.36962890625), 5)
Out[2]: 6010.3701
Closes gh-4799
Diffstat (limited to 'numpy/lib/tests/test_function_base.py')
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index ee38b3573..ac677a308 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1070,6 +1070,13 @@ class TestHistogram(TestCase): h, b = histogram(a, weights=np.ones(10, float)) assert_(issubdtype(h.dtype, float)) + def test_f32_rounding(self): + # gh-4799, check that the rounding of the edges works with float32 + x = np.array([276.318359 , -69.593948 , 21.329449], dtype=np.float32) + y = np.array([5005.689453, 4481.327637, 6010.369629], dtype=np.float32) + counts_hist, xedges, yedges = np.histogram2d(x, y, bins=100) + assert_equal(counts_hist.sum(), 3.) + def test_weights(self): v = rand(100) w = np.ones(100) * 5 |