diff options
-rw-r--r-- | numpy/core/src/multiarray/compiled_base.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/numpy/core/src/multiarray/compiled_base.c b/numpy/core/src/multiarray/compiled_base.c index f254022c9..f18ce155e 100644 --- a/numpy/core/src/multiarray/compiled_base.c +++ b/numpy/core/src/multiarray/compiled_base.c @@ -98,7 +98,8 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds) { PyObject *list = NULL, *weight = Py_None, *mlength = NULL; PyArrayObject *lst = NULL, *ans = NULL, *wts = NULL; - npy_intp *numbers, *ians, len, mx, mn, ans_size, minlength; + npy_intp *numbers, *ians, len, mx, mn, ans_size; + npy_intp minlength = 0; npy_intp i; double *weights , *dans; static char *kwlist[] = {"list", "weights", "minlength", NULL}; @@ -114,28 +115,30 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds) } len = PyArray_SIZE(lst); - if (mlength == NULL) { - minlength = 0; - } - else if (mlength == Py_None) { + /* + * This if/else if can be removed by changing the argspec to O|On above, + * once we retire the deprecation + */ + if (mlength == Py_None) { /* NumPy 1.14, 2017-06-01 */ if (DEPRECATE("0 should be passed as minlength instead of None; " "this will error in future.") < 0) { goto fail; } - minlength = 0; } - else { + else if (mlength != NULL) { minlength = PyArray_PyIntAsIntp(mlength); - if (minlength < 0) { - if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_ValueError, - "minlength must be non-negative"); - } + if (error_converting(minlength)) { goto fail; } } + if (minlength < 0) { + PyErr_SetString(PyExc_ValueError, + "minlength must be non-negative"); + goto fail; + } + /* handle empty list */ if (len == 0) { ans = (PyArrayObject *)PyArray_ZEROS(1, &minlength, NPY_INTP, 0); |