summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_function_base.py
diff options
context:
space:
mode:
authorRalf Gommers <ralf.gommers@googlemail.com>2011-03-31 12:52:13 +0200
committerRalf Gommers <ralf.gommers@googlemail.com>2011-04-01 22:42:45 +0200
commitfdf84d9d08b8001276e7cf4dead49e1efa91906b (patch)
tree719f7c5d6378543432f17ebda67959b665cf50c2 /numpy/lib/tests/test_function_base.py
parent689b68c3b194019700c4de7591043fcfdab1cec6 (diff)
downloadnumpy-fdf84d9d08b8001276e7cf4dead49e1efa91906b.tar.gz
BUG: make histogramdd work with infinite size bins. Closes #1788.
Also add more informative error messages for wrongly specified bins, for both histogram and histogram2d/dd.
Diffstat (limited to 'numpy/lib/tests/test_function_base.py')
-rw-r--r--numpy/lib/tests/test_function_base.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index ea3ca4000..353bf23e9 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -556,6 +556,10 @@ class TestHistogram(TestCase):
hist, edges = histogram([1, 2, 3, 4], [1, 2])
assert_array_equal(hist, [2, ])
assert_array_equal(edges, [1, 2])
+ assert_raises(ValueError, histogram, [1, 2], bins=0)
+ h, e = histogram([1,2], bins=1)
+ assert_equal(h, array([2]))
+ assert_allclose(e, array([1., 2.]))
def test_normed(self):
# Check that the integral of the density equals 1.
@@ -747,6 +751,27 @@ class TestHistogramdd(TestCase):
a, b = histogramdd([[], []], bins=([0,1], [0,1]))
assert_array_max_ulp(a, array([ 0., 0.]))
+ def test_bins_errors(self):
+ """There are two ways to specify bins. Check for the right errors when
+ mixing those."""
+ x = np.arange(8).reshape(2, 4)
+ assert_raises(ValueError, np.histogramdd, x, bins=[-1, 2, 4, 5])
+ assert_raises(ValueError, np.histogramdd, x, bins=[1, 0.99, 1, 1])
+ assert_raises(ValueError, np.histogramdd, x, bins=[1, 1, 1, [1, 2, 2, 3]])
+ assert_raises(ValueError, np.histogramdd, x, bins=[1, 1, 1, [1, 2, 3, -3]])
+ assert_(np.histogramdd(x, bins=[1, 1, 1, [1, 2, 3, 4]]))
+
+ def test_inf_edges(self):
+ """Test using +/-inf bin edges works. See #1788."""
+ x = np.arange(6).reshape(3, 2)
+ expected = np.array([[1, 0], [0, 1], [0, 1]])
+ h, e = np.histogramdd(x, bins=[3, [-np.inf, 2, 10]])
+ assert_allclose(h, expected)
+ h, e = np.histogramdd(x, bins=[3, np.array([-1, 2, np.inf])])
+ assert_allclose(h, expected)
+ h, e = np.histogramdd(x, bins=[3, [-np.inf, 3, np.inf]])
+ assert_allclose(h, expected)
+
class TestUnique(TestCase):
def test_simple(self):