<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
The base information profile.
"""

from abc import ABCMeta, abstractmethod

from ..math import close

profile_docstring = """
{name}

Static Attributes
-----------------
xlabel : str
    The label for the x-axis when plotting.
ylabel : str
    The label for the y-axis when plotting.
{static_attributes}

Attributes
----------
dist : Distribution
profile : dict
widths : [float]
{attributes}

Methods
-------
draw
    Plot the profile
{methods}

Private Methods
---------------
_compute
    Compute the profile
"""

class BaseProfile(object):
    """
    BaseProfile

    Static Attributes
    -----------------
    xlabel : str
        The label for the x-axis when plotting.
    ylabel : str
        The label for the y-axis when plotting.

    Attributes
    ----------
    dist : Distribution
    profile : dict
    widths : [float]

    Methods
    -------
    draw
        Plot the profile.

    Abstract Methods
    ----------------
    _compute
        Compute the profile.
    """
    __metaclass__ = ABCMeta

    xlabel = 'scale'
    ylabel = 'information [bits]'

    def __init__(self, dist):
        """
        Initialize the profile.

        Parameters
        ----------
        dist : Distribution
            The distribution to compute the profile for.
        """
        super(BaseProfile, self).__init__()
        self.dist = dist.copy(base='linear')
        self._compute()

    @abstractmethod
    def _compute(self): # pragma: no cover
        """
        Abstract method to compute the profile.
        """
        pass

    def draw(self, ax=None): # pragma: no cover
        """
        Draw the profile using matplotlib.

        Parameters
        ----------
        ax : axis
            The axis to draw the profile on. If None, a new axis is created.

        Returns
        -------
        ax : axis
            The axis with profile.
        """
        import matplotlib.pyplot as plt

        if ax is None:
            ax = plt.figure().gca()

         # pylint: disable=no-member
        left, height = zip(*self.profile.items())
        ax.bar(left, height, width=self.widths)

        ax.set_xticks([i+0.5 for i in self.profile])
        ax.set_xticklabels([str(i) for i in self.profile])

        ax.set_xlabel(self.xlabel)
        ax.set_ylabel(self.ylabel)

        low, high = ax.get_ylim()
        if close(low, 0, atol=1e-5):
            low = -0.1
        if close(high, 0, atol=1e-5):<commit_msg>fix spacing<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
The base information profile.
"""

from abc import ABCMeta, abstractmethod

from ..math import close

profile_docstring = """
{name}

Static Attributes
-----------------
xlabel : str
    The label for the x-axis when plotting.
ylabel : str
    The label for the y-axis when plotting.
{static_attributes}

Attributes
----------
dist : Distribution
profile : dict
widths : [float]
{attributes}

Methods
-------
draw
    Plot the profile
{methods}

Private Methods
---------------
_compute
    Compute the profile
"""

class BaseProfile(object):
    """
    BaseProfile

    Static Attributes
    -----------------
    xlabel : str
        The label for the x-axis when plotting.
    ylabel : str
        The label for the y-axis when plotting.

    Attributes
    ----------
    dist : Distribution
    profile : dict
    widths : [float]

    Methods
    -------
    draw
        Plot the profile.

    Abstract Methods
    ----------------
    _compute
        Compute the profile.
    """
    __metaclass__ = ABCMeta

    xlabel = 'scale'
    ylabel = 'information [bits]'

    def __init__(self, dist):
        """
        Initialize the profile.

        Parameters
        ----------
        dist : Distribution
            The distribution to compute the profile for.
        """
        super(BaseProfile, self).__init__()
        self.dist = dist.copy(base='linear')
        self._compute()

    @abstractmethod
    def _compute(self): # pragma: no cover
        """
        Abstract method to compute the profile.
        """
        pass

    def draw(self, ax=None): # pragma: no cover
        """
        Draw the profile using matplotlib.

        Parameters
        ----------
        ax : axis
            The axis to draw the profile on. If None, a new axis is created.

        Returns
        -------
        ax : axis
            The axis with profile.
        """
        import matplotlib.pyplot as plt

        if ax is None:
            ax = plt.figure().gca()

        # pylint: disable=no-member
        left, height = zip(*self.profile.items())
        ax.bar(left, height, width=self.widths)

        ax.set_xticks([i+0.5 for i in self.profile])
        ax.set_xticklabels([str(i) for i in self.profile])

        ax.set_xlabel(self.xlabel)
        ax.set_ylabel(self.ylabel)

        low, high = ax.get_ylim()
        if close(low, 0, atol=1e-5):
            low = -0.1
        if close(high, 0, atol=1e-5):
{'fraction_non_alphanumeric': 0.1385626119848696, 'fraction_numerical': 0.00437985267768266, 'mean_word_length': 1.6262415054887611, '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': '3716700', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1421, 'n_words': 440}