<commit_before>"""Utility functions."""

import base64
import io

try:
    import numpy as np
except ImportError:
    np = None


def json_encoder_default(obj):
    """Handle more data types than the default JSON encoder.

    Specifically, it treats a `set` and a numpy array like a `list`.

    Example: `json.dumps(obj, default=json_encoder_default)`
    """
    if np is not None:
        if isinstance(obj, np.integer):
            return int(obj)
        elif isinstance(obj, np.float):
            return float(obj)

    if isinstance(obj, set):
        return list(obj)
    elif hasattr(obj, 'tolist') and hasattr(obj, '__iter__'):
        # for np.array
        return obj.tolist()

    return obj


def fig_to_src(figure, image_format='png', dpi=80):<commit_msg>docstring formatting<commit_after>"""Utility functions."""

import base64
import io

try:
    import numpy as np
except ImportError:
    np = None


def json_encoder_default(obj):
    """Handle more data types than the default JSON encoder.

    Specifically, it treats a ``set`` and a numpy array like a ``list``.

    Example usage: ``json.dumps(obj, default=json_encoder_default)``
    """
    if np is not None:
        if isinstance(obj, np.integer):
            return int(obj)
        elif isinstance(obj, np.float):
            return float(obj)

    if isinstance(obj, set):
        return list(obj)
    elif hasattr(obj, 'tolist') and hasattr(obj, '__iter__'):
        # for np.array
        return obj.tolist()

    return obj


def fig_to_src(figure, image_format='png', dpi=80):
{'fraction_non_alphanumeric': 0.11004478566858605, 'fraction_numerical': 0.005118362124120281, 'mean_word_length': 2.8617283950617285, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2439320', 'n_tokens_mistral': 488, 'n_tokens_neox': 470, 'n_words': 155}