<commit_before>"""
    pyexcel.utils
    ~~~~~~~~~~~~~~~~~~~

    Utility functions for pyexcel

    :copyright: (c) 2014 by <NAME>.
    :license: GPL v3
"""
from .sheets import NominableSheet, Sheet
from ._compact import OrderedDict, PY2


def to_array(o):
    """convert a reader iterator to an array"""
    array = []
    for i in o:
        array.append(i)
    return array


def to_dict(o):
    """convert a reader iterator to a dictionary"""
    the_dict = OrderedDict()
    series = "Series_%d"
    count = 1
    for c in o:
        if type(c) == dict:
            the_dict.update(c)
        elif isinstance(c, Sheet):
            the_dict.update({c.name: to_array(c)})
        else:
            key = series % count
            the_dict.update({key: c})
            count += 1
    return the_dict


def to_records(reader, custom_headers=None):
    """
    Make an array of dictionaries

    It takes the first row as keys and the rest of
    the rows as values. Then zips keys and row values
    per each row. This is particularly helpful for
    database operations.
    """
    ret = []
    if isinstance(reader, NominableSheet) is False:
        raise NotImplementedError
    if len(reader.rownames) > 0:
        if custom_headers:
            headers = custom_headers
        else:
            headers = reader.rownames
        for column in reader.columns():
            the_dict = dict(zip(headers, column))
            ret.append(the_dict)
    elif len(reader.colnames) > 0:
        if custom_headers:
            headers = custom_headers
        else:
            headers = reader.colnames
        for row in reader.rows():
            the_dict = dict(zip(headers, row))
            ret.append(the_dict)
    else:
        raise ValueError("No series found")
    return ret


def from_records(records):
    """Reverse function of to_records
    """
    if len(records) < 1:
        return None

    keys = records[0].keys()
    data = []
    data.append(list(keys))
    for r in records:
        row = []<commit_msg>sort to_records's keys<commit_after>"""
    pyexcel.utils
    ~~~~~~~~~~~~~~~~~~~

    Utility functions for pyexcel

    :copyright: (c) 2014 by <NAME>.
    :license: GPL v3
"""
from .sheets import NominableSheet, Sheet
from ._compact import OrderedDict, PY2


def to_array(o):
    """convert a reader iterator to an array"""
    array = []
    for i in o:
        array.append(i)
    return array


def to_dict(o):
    """convert a reader iterator to a dictionary"""
    the_dict = OrderedDict()
    series = "Series_%d"
    count = 1
    for c in o:
        if type(c) == dict:
            the_dict.update(c)
        elif isinstance(c, Sheet):
            the_dict.update({c.name: to_array(c)})
        else:
            key = series % count
            the_dict.update({key: c})
            count += 1
    return the_dict


def to_records(reader, custom_headers=None):
    """
    Make an array of dictionaries

    It takes the first row as keys and the rest of
    the rows as values. Then zips keys and row values
    per each row. This is particularly helpful for
    database operations.
    """
    ret = []
    if isinstance(reader, NominableSheet) is False:
        raise NotImplementedError
    if len(reader.rownames) > 0:
        if custom_headers:
            headers = custom_headers
        else:
            headers = reader.rownames
        for column in reader.columns():
            the_dict = dict(zip(headers, column))
            ret.append(the_dict)
    elif len(reader.colnames) > 0:
        if custom_headers:
            headers = custom_headers
        else:
            headers = reader.colnames
        for row in reader.rows():
            the_dict = dict(zip(headers, row))
            ret.append(the_dict)
    else:
        raise ValueError("No series found")
    return ret


def from_records(records):
    """Reverse function of to_records
    """
    if len(records) < 1:
        return None

    keys = sorted(records[0].keys())
    data = []
    data.append(list(keys))
    for r in records:
        row = []
{'fraction_non_alphanumeric': 0.10419220397156166, 'fraction_numerical': 0.005883795047805835, 'mean_word_length': 2.0839002267573696, 'pattern_counts': {'":': 0, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1825754', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1183, 'n_words': 380}