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

Code before:
            NULL, NULL, NULL) < 0) {
        return NULL;
    }

    if (sortkind == -1) {
        // kind default is the same as the flag default
        stable = (stable > 0)? NPY_SORT_STABLE: 0;
        descending = (descending > 0)? NPY_SORT_DESCENDING: 0;
        nanfirst = (nanfirst > 0)? NPY_SORT_NANFIRST: 0;
        flags = stable | descending | nanfirst;
    }
    else {
        // Check that no keywords are used
        int keywords_used = (stable != -1) | (descending != -1) | (nanfirst != -1);
        if (keywords_used) {
            PyErr_SetString(PyExc_ValueError,
                    "`kind` and keyword parameters can't be provided at "
                    "the same time. Use only one of them.");
            return NULL;
        }
        // remap sortkind to flags, NPY_HEAPSORT is effectively mapped to NPY_QUICKSORT.
        switch (sortkind) {
            default:
            case NPY_HEAPSORT:
            case NPY_QUICKSORT:
                flags = 0;
            case NPY_STABLESORT:
                flags = NPY_SORT_STABLE;
                break;
        }
    }

    order = (order != Py_None)? order: NULL;
    // Reorder field names if required.
    if (order != NULL) {
        PyObject *new_name;
        PyObject *_numpy_internal;
        saved = PyArray_DESCR(self);
        if (!PyDataType_HASFIELDS(saved)) {
            PyErr_SetString(PyExc_ValueError,
                            "Cannot specify "
                            "order when the array has no fields.");
            return NULL;
        }
        _numpy_internal = PyImport_ImportModule("numpy._core._internal");
        if (_numpy_internal == NULL) {
            return NULL;
        }
        new_name = PyObject_CallMethod(_numpy_internal, "_newnames",
                                       "OO", saved, order);
        Py_DECREF(_numpy_internal);

Review comment (suggestion):
Needs a `break` after, no? 

I'd also swap the order, so default is part of the end (also above, in `item_selection.c`, and below), but no big deal.

Code after:

    if (sortkind == _NPY_SORT_UNDEFINED) {
        // keywords only if sortkind not passed
        sortkind = 0;
        sortkind |= (stable > 0)? NPY_SORT_STABLE: 0;
        sortkind |= (descending > 0)? NPY_SORT_DESCENDING: 0;
    }
    else {
        // Check that no keywords are used
        int keywords_used = 0;
        keywords_used |= (stable != -1);
        keywords_used |= (descending != -1);
        if (keywords_used) {
            PyErr_SetString(PyExc_ValueError,
                    "`kind` and keyword parameters can't be provided at "
                    "the same time. Use only one of them.");
            return NULL;
        }
    }

    order = (order != Py_None)? order: NULL;
    // Reorder field names if required.
    if (order != NULL) {
        PyObject *new_name;
        PyObject *_numpy_internal;
        saved = PyArray_DESCR(self);
        if (!PyDataType_HASFIELDS(saved)) {
            PyErr_SetString(PyExc_ValueError,
                            "Cannot specify "
                            "order when the array has no fields.");
            return NULL;
        }
        _numpy_internal = PyImport_ImportModule("numpy._core._internal");
        if (_numpy_internal == NULL) {
            return NULL;
        }
        new_name = PyObject_CallMethod(_numpy_internal, "_newnames",
                                       "OO", saved, order);
        Py_DECREF(_numpy_internal);
        if (new_name == NULL) {
            return NULL;
        }
        newd = PyArray_DescrNew(saved);
        if (newd == NULL) {
            Py_DECREF(new_name);
            return NULL;
        }
        Py_DECREF(((_PyArray_LegacyDescr *)newd)->names);
        ((_PyArray_LegacyDescr *)newd)->names = new_name;
        ((PyArrayObject_fields *)self)->descr = newd;
    }