Repository: numpy/numpy
File: numpy/_core/src/multiarray/compiled_base.c (C)

Code before:
                                  "error. (Deprecated NumPy 2.1)") < 0) {
                        goto fail;
                    }
                }
                else {
                    /* Failure was not a TypeError. */
                    goto fail;
                }
            }
        }
        else {
            /* Got an empty list. */
            Py_DECREF(tmp1);
        }
    }

    if (lst == NULL) {
        PyArray_Descr* local_dtype = PyArray_DescrFromType(NPY_INTP);
        list = PyArray_FromAny(list, local_dtype, 0, 0, NPY_ARRAY_FORCECAST, NULL);
        if (list == NULL) {
            goto fail;
        }
        lst = (PyArrayObject *)PyArray_ContiguousFromAny(list, NPY_INTP, 1, 1);
        if (lst == NULL) {
            goto fail;
        }
    }
    len = PyArray_SIZE(lst);

    /*
     * This if/else if can be removed by changing the argspec above,
     */
    if (mlength == Py_None) {
        PyErr_SetString(PyExc_TypeError,
             "use 0 instead of None for minlength");
        goto fail;
    }
    else if (mlength != NULL) {
        minlength = PyArray_PyIntAsIntp(mlength);
        if (error_converting(minlength)) {
            goto fail;
        }
    }

    if (minlength < 0) {
        PyErr_SetString(PyExc_ValueError,
                        "'minlength' must not be negative");
        goto fail;
    }

    /* handle empty list */

Review comment (bug):
Neither of the two CI failures look related and I checked that the new regression test indeed fails before/passes after the patch.

I suspect Nathan or Sebastian will have to babysit me on the reference counting/setting for `local_dtype` and/or `list` above perhaps. Anyway, happy to make whatever revisions are requested.

For coercing to `NPY_INTP` we also have `coerce_index` in `iterators.c`, but dropping that in seemed to potentially require a bit more work.

Code after:
                    PyErr_Clear();
                    /* Deprecated 2024-08-02, NumPy 2.1 */
                    if (DEPRECATE("Non-integer input passed to bincount. In a "
                                  "future version of NumPy, this will be an "
                                  "error. (Deprecated NumPy 2.1)") < 0) {
                        goto fail;
                    }
                }
                else {
                    /* Failure was not a TypeError. */
                    goto fail;
                }
            }
        }
        else {
            /* Got an empty list. */
            Py_DECREF(tmp1);
        }
    }

    if (lst == NULL) {
        int flags = NPY_ARRAY_WRITEABLE | NPY_ARRAY_ALIGNED | NPY_ARRAY_C_CONTIGUOUS;
        if (PyArray_Check((PyObject *)list) &&
            PyArray_ISINTEGER((PyArrayObject *)list)) {
            flags = flags | NPY_ARRAY_FORCECAST;
        }
        PyArray_Descr* local_dtype = PyArray_DescrFromType(NPY_INTP);
        lst = (PyArrayObject *)PyArray_FromAny(list, local_dtype, 1, 1, flags, NULL);
        if (lst == NULL) {
            goto fail;
        }
    }
    len = PyArray_SIZE(lst);

    /*
     * This if/else if can be removed by changing the argspec above,
     */
    if (mlength == Py_None) {
        PyErr_SetString(PyExc_TypeError,
             "use 0 instead of None for minlength");
        goto fail;
    }
    else if (mlength != NULL) {
        minlength = PyArray_PyIntAsIntp(mlength);
        if (error_converting(minlength)) {
            goto fail;
        }
    }

    if (minlength < 0) {
        PyErr_SetString(PyExc_ValueError,