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

Code before:
NPY_NO_EXPORT int
PyArray_SortEx(PyArrayObject *op, int axis, NPY_SORTFLAGS flags)
{
    PyArray_SortFunc **sort_table = NULL;
    PyArray_SortFunc *sort = NULL;

    if (check_and_adjust_axis(&axis, PyArray_NDIM(op)) < 0) {
        return -1;
    }

    if (PyArray_FailUnlessWriteable(op, "sort array") < 0) {
        return -1;
    }

    sort_table = PyDataType_GetArrFuncs(PyArray_DESCR(op))->sort;
    switch (flags) {
        case NPY_SORT_STABLE:
            sort = sort_table[NPY_STABLESORT];
            break;
        default:
            sort = sort_table[NPY_QUICKSORT];
    }

    // Look for appropriate generic function if no type specific version
    if (sort == NULL) {
        if (!PyDataType_GetArrFuncs(PyArray_DESCR(op))->compare) {
            PyErr_SetString(PyExc_TypeError,
                            "type does not have compare function");
            return -1;
        }
        switch (flags) {
            case NPY_SORT_STABLE:
                sort = generic_sort_table[NPY_STABLESORT];
                break;
            default:
                sort = generic_sort_table[NPY_QUICKSORT];
        }
    }

    if (sort == NULL) {
        PyErr_SetString(PyExc_TypeError,
                        "no current sort function meets the requirements");
        return -1;
    }
    return _new_sortlike(op, axis, sort, NULL, NULL, 0);
}

/* Table of generic argsort function for use by PyArray_ArgSortEx */
static PyArray_ArgSortFunc* const generic_argsort_table[] = {npy_aquicksort,
                                                             npy_aheapsort,
                                                             npy_atimsort};

Review comment (suggestion):
I guess this really should be `case 0:` and the default should just fall through.

Code after:
NPY_NO_EXPORT int
PyArray_Sort(PyArrayObject *op, int axis, NPY_SORTKIND flags)
{
    PyArray_SortFunc **sort_table = NULL;
    PyArray_SortFunc *sort = NULL;

    if (check_and_adjust_axis(&axis, PyArray_NDIM(op)) < 0) {
        return -1;
    }

    if (PyArray_FailUnlessWriteable(op, "sort array") < 0) {
        return -1;
    }

    // Zero the NPY_HEAPSORT bit, maps NPY_HEAPSORT to NPY_QUICKSORT
    flags &= ~_NPY_SORT_HEAPSORT;

    sort_table = PyDataType_GetArrFuncs(PyArray_DESCR(op))->sort;
    switch (flags) {
        case NPY_SORT_DEFAULT:
            sort = sort_table[NPY_QUICKSORT];
            break;
        case NPY_SORT_STABLE:
            sort = sort_table[NPY_STABLESORT];
            break;
        default:
            break;
    }

    // Look for appropriate generic function if no type specific version
    if (sort == NULL) {
        if (!PyDataType_GetArrFuncs(PyArray_DESCR(op))->compare) {
            PyErr_SetString(PyExc_TypeError,
                            "type does not have compare function");
            return -1;
        }
        switch (flags) {
            case NPY_SORT_DEFAULT:
                sort = generic_sort_table[NPY_QUICKSORT];
                break;
            case NPY_SORT_STABLE:
                sort = generic_sort_table[NPY_STABLESORT];
                break;
            default:
                break;
        }
    }

    if (sort == NULL) {
        PyErr_SetString(PyExc_TypeError,
                        "no current sort function meets the requirements");