<commit_before>from blaze.compatibility import _strtypes

def parse_index(ind):
    if isinstance(ind, (int, _strtypes)):
        return ind
    if isinstance(ind, list):
        return tuple(map(parse_index, ind))
    if isinstance(ind, dict):
        return slice(ind.get('start'), ind.get('stop'), ind.get('step'))
    raise ValueError('Do not know how to parse %s into an index' % str(ind))


def emit_index(ind):
    if isinstance(ind, (int, _strtypes)):
        return ind
    if isinstance(ind, tuple):
        return list(map(emit_index, ind))
    if isinstance(ind, slice):
        result = {'start': ind.start, 'stop': ind.stop, 'step': ind.step}
        if result['step'] is None:
            del result['step']
        return result<commit_msg>serve: docstrings for index functions<commit_after>from blaze.compatibility import _strtypes

def parse_index(ind):
    """ Parse structured index into Pythonic form

    >>> parse_index([1, {'start': 0, 'stop': 10}])
    (1, slice(0, 10, None))

    See also:
        emit_index
    """
    if isinstance(ind, (int, _strtypes)):
        return ind
    if isinstance(ind, list):
        return tuple(map(parse_index, ind))
    if isinstance(ind, dict):
        return slice(ind.get('start'), ind.get('stop'), ind.get('step'))
    raise ValueError('Do not know how to parse %s into an index' % str(ind))


def emit_index(ind):
    """ Emit Python index into structured form

    >>> emit_index((1, slice(0, 10, None)))
    [1, {'start': 0, 'stop': 10}]

    See also:
        parse_index
    """
    if isinstance(ind, (int, _strtypes)):
        return ind
    if isinstance(ind, tuple):
        return list(map(emit_index, ind))
    if isinstance(ind, slice):
        result = {'start': ind.start, 'stop': ind.stop, 'step': ind.step}
        if result['step'] is None:
            del result['step']
        return result
{'fraction_non_alphanumeric': 0.14331379861481086, 'fraction_numerical': 0.008524240809802876, 'mean_word_length': 2.953684210526316, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1029050', 'n_tokens_mistral': 584, 'n_tokens_neox': 570, 'n_words': 177}