summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorDavid Cournapeau <cournape@gmail.com>2010-02-02 04:54:53 +0000
committerDavid Cournapeau <cournape@gmail.com>2010-02-02 04:54:53 +0000
commit1473800aeb30256517a11556fa1ad86c9127d641 (patch)
treec43be7784cb14fcb34b0baf1ba65fc8a4360b85e /numpy/lib
parent60e53321fbb0a5e3ae630100eff32aec939a4434 (diff)
downloadnumpy-1473800aeb30256517a11556fa1ad86c9127d641.tar.gz
BUG: fix #1387. Raise ValueError for empty input to bincount.
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/src/_compiled_base.c5
-rw-r--r--numpy/lib/tests/test_regression.py3
2 files changed, 8 insertions, 0 deletions
diff --git a/numpy/lib/src/_compiled_base.c b/numpy/lib/src/_compiled_base.c
index e272e835a..38a446c06 100644
--- a/numpy/lib/src/_compiled_base.c
+++ b/numpy/lib/src/_compiled_base.c
@@ -117,6 +117,11 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
goto fail;
}
len = PyArray_SIZE(lst);
+ if (len < 1) {
+ PyErr_SetString(PyExc_ValueError,
+ "The first argument cannot be empty.");
+ goto fail;
+ }
numbers = (intp *) PyArray_DATA(lst);
mxi = mxx(numbers, len);
mni = mnx(numbers, len);
diff --git a/numpy/lib/tests/test_regression.py b/numpy/lib/tests/test_regression.py
index 9821ba97e..16add3295 100644
--- a/numpy/lib/tests/test_regression.py
+++ b/numpy/lib/tests/test_regression.py
@@ -176,6 +176,9 @@ class TestRegression(TestCase):
sys.stdout = sys.__stdout__
raise AssertionError("ticket #1243")
+ def test_bincount_empty(self):
+ """Ticket #1387: empty array as input for bincount."""
+ assert_raises(ValueError, lambda : np.bincount(np.array([], dtype=np.intp)))
if __name__ == "__main__":
run_module_suite()