<commit_before>/******************************************************************************
 * Licensed under Apache License Version 2.0 - see LICENSE
 *****************************************************************************/

static PyObject *
PyIU_MinMax(PyObject *Py_UNUSED(m),
            PyObject *args,
            PyObject *kwargs)
{
    static char *kwlist[] = {"key", "default", NULL};

    PyObject *sequence, *iterator=NULL, *defaultitem = NULL, *keyfunc = NULL;
    PyObject *item1 = NULL, *item2 = NULL, *val1 = NULL, *val2 = NULL;
    PyObject *maxitem = NULL, *maxval = NULL, *minitem = NULL, *minval = NULL;
    PyObject *temp = NULL, *resulttuple = NULL;
    PyObject *funcargs=NULL;
    int cmp;
    const int positional = PyTuple_GET_SIZE(args) > 1;

    if (positional) {
        sequence = args;
    } else if (!PyArg_UnpackTuple(args, "minmax", 1, 1, &sequence)) {
        return NULL;
    }

    if (!PyArg_ParseTupleAndKeywords(PyIU_global_0tuple, kwargs,
                                     "|OO:minmax", kwlist,
                                     &keyfunc, &defaultitem)) {
        return NULL;
    }

    PYIU_NULL_IF_NONE(keyfunc);
    Py_XINCREF(keyfunc);

    if (positional && defaultitem != NULL) {
        PyErr_SetString(PyExc_TypeError,
                        "Cannot specify a default for `minmax` with multiple "
                        "positional arguments");
        goto Fail;
    }

    if (keyfunc != NULL) {
        funcargs = PyTuple_New(0);
        if (funcargs == NULL) {
            goto Fail;
        }
    }

    iterator = PyObject_GetIter(sequence);
    if (iterator == NULL) {
        goto Fail;
    }

    while ( (item1=Py_TYPE(iterator)->tp_iternext(iterator)) ) {
        item2 = Py_TYPE(iterator)->tp_iternext(iterator);
        /* item2 could be NULL (end of sequence) clear a StopIteration but
           immediatly fail if it's another exception. It will check for
           exceptions in the end (again) but make sure it does not process
           an iterable when the iterator threw an exception! */
        if (item2 == NULL) {
            if (PyErr_Occurred()) {
                if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
                    PyErr_Clear();
                } else {
                    goto Fail;
                }
            }
        }

        /* get the value from the key function. */<commit_msg>Create a size-1 tuple for the function arguments in minmax.<commit_after>/******************************************************************************
 * Licensed under Apache License Version 2.0 - see LICENSE
 *****************************************************************************/

static PyObject *
PyIU_MinMax(PyObject *Py_UNUSED(m),
            PyObject *args,
            PyObject *kwargs)
{
    static char *kwlist[] = {"key", "default", NULL};

    PyObject *sequence, *iterator=NULL, *defaultitem = NULL, *keyfunc = NULL;
    PyObject *item1 = NULL, *item2 = NULL, *val1 = NULL, *val2 = NULL;
    PyObject *maxitem = NULL, *maxval = NULL, *minitem = NULL, *minval = NULL;
    PyObject *temp = NULL, *resulttuple = NULL;
    PyObject *funcargs=NULL;
    int cmp;
    const int positional = PyTuple_GET_SIZE(args) > 1;

    if (positional) {
        sequence = args;
    } else if (!PyArg_UnpackTuple(args, "minmax", 1, 1, &sequence)) {
        return NULL;
    }

    if (!PyArg_ParseTupleAndKeywords(PyIU_global_0tuple, kwargs,
                                     "|OO:minmax", kwlist,
                                     &keyfunc, &defaultitem)) {
        return NULL;
    }

    PYIU_NULL_IF_NONE(keyfunc);
    Py_XINCREF(keyfunc);

    if (positional && defaultitem != NULL) {
        PyErr_SetString(PyExc_TypeError,
                        "Cannot specify a default for `minmax` with multiple "
                        "positional arguments");
        goto Fail;
    }

    if (keyfunc != NULL) {
        funcargs = PyTuple_New(1);
        if (funcargs == NULL) {
            goto Fail;
        }
    }

    iterator = PyObject_GetIter(sequence);
    if (iterator == NULL) {
        goto Fail;
    }

    while ( (item1=Py_TYPE(iterator)->tp_iternext(iterator)) ) {
        item2 = Py_TYPE(iterator)->tp_iternext(iterator);
        /* item2 could be NULL (end of sequence) clear a StopIteration but
           immediatly fail if it's another exception. It will check for
           exceptions in the end (again) but make sure it does not process
           an iterable when the iterator threw an exception! */
        if (item2 == NULL) {
            if (PyErr_Occurred()) {
                if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
                    PyErr_Clear();
                } else {
                    goto Fail;
                }
            }
        }

        /* get the value from the key function. */
{'fraction_non_alphanumeric': 0.16103789126853377, 'fraction_numerical': 0.006383855024711697, 'mean_word_length': 2.1174582798459562, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6108078', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1338, 'n_words': 377}