summaryrefslogtreecommitdiff
path: root/numpy/lib/src
diff options
context:
space:
mode:
authorimmerrr <immerrr@gmail.com>2014-03-24 09:16:36 +0400
committerimmerrr <immerrr@gmail.com>2014-03-26 09:52:18 +0400
commite5cf3654e81573bf583cbf6a8688a5e44fafceea (patch)
treeb5a5bbba2b1c2114f728b060bb1bd6e7bf3fd556 /numpy/lib/src
parent60d434766b1a5a315674811e544d33dea5b2323d (diff)
downloadnumpy-e5cf3654e81573bf583cbf6a8688a5e44fafceea.tar.gz
BUG: fix incorrect minlength handling in np.bincount
Diffstat (limited to 'numpy/lib/src')
-rw-r--r--numpy/lib/src/_compiled_base.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/numpy/lib/src/_compiled_base.c b/numpy/lib/src/_compiled_base.c
index f70cd2bab..a461613e3 100644
--- a/numpy/lib/src/_compiled_base.c
+++ b/numpy/lib/src/_compiled_base.c
@@ -161,14 +161,22 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
len = PyArray_SIZE(lst);
type = PyArray_DescrFromType(NPY_INTP);
- /* handle empty list */
- if (len < 1) {
- if (mlength == Py_None) {
- minlength = 0;
- }
- else if (!(minlength = PyArray_PyIntAsIntp(mlength))) {
+ if (mlength == Py_None) {
+ minlength = 0;
+ }
+ else {
+ minlength = PyArray_PyIntAsIntp(mlength);
+ if (minlength <= 0) {
+ if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_ValueError,
+ "minlength must be positive");
+ }
goto fail;
}
+ }
+
+ /* handle empty list */
+ if (len == 0) {
if (!(ans = (PyArrayObject *)PyArray_Zeros(1, &minlength, type, 0))){
goto fail;
}
@@ -185,15 +193,6 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
}
ans_size = mx + 1;
if (mlength != Py_None) {
- if (!(minlength = PyArray_PyIntAsIntp(mlength))) {
- goto fail;
- }
- if (minlength <= 0) {
- /* superfluous, but may catch incorrect usage */
- PyErr_SetString(PyExc_ValueError,
- "minlength must be positive");
- goto fail;
- }
if (ans_size < minlength) {
ans_size = minlength;
}