<commit_before>
def formatUnits(value, units, precision=1, useUnits=True):
    """
    Formats the value with appropriate units to the given number of digits of precision.
    The use_units parameter exists as a convenience, to make this easier to use with
    argparse boolean flags for friendly formatting.

    :param value: int or float value to format
    :param units: list of tuples of unit names with their multipliers
    :param precision: number of digits of precision to use after the decimal
    :param useUnits: bool indicating if this function should display units
    """
    scaledValue = value
    unit = ''
    if useUnits:
        for name, multiplier in units:
            if value < multiplier:
                break

            scaledValue = float(value) / multiplier
            unit = name

    formatString = '%%.%df%%s' % precision
    return formatString % (scaledValue, unit)

def parseUnits(value, units):
    """
    Parses a value with a unit and returns it in the base unit.

    :param value: str The value to parse
    :param units: list of tuples of unit names and multipliers
    :return: int
    """
    n = len(value)
    for i, c in enumerate(value):
        if value[i].isalpha():
            n = i
            break

    numberStr = value[:n]
    number = float(numberStr)

    unitStr = value[n:]
    for unit, multiplier in units:
        if unitStr == unit:
            return int(multiplier * number)

    raise ValueError('Uknknown unit "%s"' % unitStr)

#### Standard Units #####

UNITS_1000 = [<commit_msg>Fix None handling in unit utility<commit_after>
def formatUnits(value, units, precision=1, useUnits=True):
    """
    Formats the value with appropriate units to the given number of digits of precision.
    The use_units parameter exists as a convenience, to make this easier to use with
    argparse boolean flags for friendly formatting.

    :param value: int or float value to format
    :param units: list of tuples of unit names with their multipliers
    :param precision: number of digits of precision to use after the decimal
    :param useUnits: bool indicating if this function should display units
    """
    if value is None:
        return None

    scaledValue = value
    unit = ''
    if useUnits:
        for name, multiplier in units:
            if value < multiplier:
                break

            scaledValue = float(value) / multiplier
            unit = name

    formatString = '%%.%df%%s' % precision
    return formatString % (float(scaledValue), unit)

def parseUnits(value, units):
    """
    Parses a value with a unit and returns it in the base unit.

    :param value: str The value to parse
    :param units: list of tuples of unit names and multipliers
    :return: int
    """
    n = len(value)
    for i, c in enumerate(value):
        if value[i].isalpha():
            n = i
            break

    numberStr = value[:n]
    number = float(numberStr)

    unitStr = value[n:]
    for unit, multiplier in units:
        if unitStr == unit:
            return int(multiplier * number)

    raise ValueError('Uknknown unit "%s"' % unitStr)

#### Standard Units #####

UNITS_1000 = [
{'fraction_non_alphanumeric': 0.07955974842767295, 'fraction_numerical': 0.0031446540880503146, 'mean_word_length': 2.5149171270718234, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1041661', 'n_tokens_mistral': 880, 'n_tokens_neox': 847, 'n_words': 369}