diff options
author | David Huard <david.huard@gmail.com> | 2011-07-20 14:36:35 -0400 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2012-04-29 19:13:55 -0600 |
commit | 6bb57ccac190182694c64987d80b7ca53d8f5c4d (patch) | |
tree | 014e62083cd0164c3cc17834ac929a9c8efcba85 | |
parent | b33e8b9724af621b7f7308650a29a00c1be79579 (diff) | |
download | numpy-6bb57ccac190182694c64987d80b7ca53d8f5c4d.tar.gz |
BUG: ticket #1899, fixed histogramdd bug with empty inputs.
-rw-r--r-- | numpy/lib/function_base.py | 6 | ||||
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 5 | ||||
-rw-r--r-- | numpy/lib/tests/test_twodim_base.py | 5 |
3 files changed, 11 insertions, 5 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index ca291f6bb..2f3d47c0a 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -335,11 +335,11 @@ def histogramdd(sample, bins=10, range=None, normed=False, weights=None): Found bin edge of size <= 0. Did you specify `bins` with non-monotonic sequence?""") + nbin = asarray(nbin) + # Handle empty input. if N == 0: - return np.zeros(D), edges - - nbin = asarray(nbin) + return np.zeros(nbin-2), edges # Compute the bin number each sample falls into. Ncount = {} diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index d1cf9d149..8f7d45060 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -749,7 +749,10 @@ class TestHistogramdd(TestCase): def test_empty(self): a, b = histogramdd([[], []], bins=([0,1], [0,1])) - assert_array_max_ulp(a, array([ 0., 0.])) + assert_array_max_ulp(a, array([[ 0.]])) + a, b = np.histogramdd([[], [], []], bins=2) + assert_array_max_ulp(a, np.zeros((2, 2, 2))) + def test_bins_errors(self): """There are two ways to specify bins. Check for the right errors when diff --git a/numpy/lib/tests/test_twodim_base.py b/numpy/lib/tests/test_twodim_base.py index 85e76a384..36addfac2 100644 --- a/numpy/lib/tests/test_twodim_base.py +++ b/numpy/lib/tests/test_twodim_base.py @@ -224,7 +224,10 @@ class TestHistogram2d(TestCase): def test_empty(self): a, edge1, edge2 = histogram2d([],[], bins=([0,1],[0,1])) - assert_array_max_ulp(a, array([ 0., 0.])) + assert_array_max_ulp(a, array([[ 0.]])) + + a, edge1, edge2 = histogram2d([], [], bins=4) + assert_array_max_ulp(a, np.zeros((4, 4))) class TestTri(TestCase): |