<commit_before>"""HistogramBase - base for all histogram classes."""
from __future__ import absolute_import, division
import numpy as np
from .binnings import as_binning


class HistogramBase(object):
    """Histogram base class.

    Behaviour shared by all histogram classes.

    The most important daughter classes are:
    - Histogram1D
    - HistogramND

    There are also special histogram types that are modifications of these classes.

    The methods you should override:
    - fill
    - fill_n (optional)
    - copy
    - _update_dict (optional)

    Underlying data type is int64 / float  or an explicitly specified
    other type (dtype).

    Attributes
    ----------
    _binnings : Iterable[BinningBase]
        Schema for binning(s)
    _frequencies : array_like
        Bin contents
    _errors2 : array_like
        Square errors associated with the bin contents
    _meta_data : dict
        All meta-data (names, user-custom values, ...). Anything can be put in.
        When exported, all information is kept.
    _dtype : np.dtype
        Type of the frequencies and also errors (int64, float64 or user-overridden)
    _missed : array_like
        Various storage for missed values in different histogram types
        (1 value for multi-dimensional, 3 values for one-dimensional)

    Invariants
    ----------
    - Frequencies in the histogram should always be non-negative.
    Many operations rely on that, but it is not always enforced.
    (TODO: Fix this?)

    See Also
    --------
    histogram1d
    histogram_nd
    special

    """

    def __init__(self, binnings, frequencies=None, errors2=None, **kwargs):
        """Constructor

        All keyword arguments not listed below become items in the _meta_data
        dictionary.

        Parameters
        ----------
        binnings : Iterable[BinningBase or array_like]
        frequencies : Optional[array_like]
        errors2 : Optional[array_like]
        dtype : np.dtype
        keep_missed : bool

        """
        self._binnings = [as_binning(binning) for binning in binnings]

        # Frequencies + appropriate dtypes
        if frequencies is None:
            dtype = kwargs.pop("dtype", np.int64)
            self._frequencies = np.zeros(self.shape, dtype=dtype)
        else:
            dtype = kwargs.pop("dtype", None)
            if dtype is not None:
                frequencies = np.asarray(frequencies, dtype=dtype)
            else:
                frequencies = np.asarray(frequencies)
                if np.issubdtype(frequencies.dtype, np.integer):
                    frequencies = frequencies.astype(np.int64)
                elif np.issubdtype(frequencies.dtype, np.floating):
                    frequencies = frequencies.astype(np.float64)
                else:
                    raise RuntimeError("Frequencies of type {0} not understood"
                                       .format(frequencies.dtype))
            dtype = frequencies.dtype
            if frequencies.shape != self.shape:
                raise RuntimeError("Values must have same dimension as bins.")
            if np.any(frequencies < 0):
                raise RuntimeError("Cannot have negative frequencies.")
            self._frequencies = frequencies
        self._dtype = dtype

        # Errors
        if errors2 is None:
            self._errors2 = self._frequencies.copy()
        else:
            self._errors2 = np.asarray(errors2, dtype=self.dtype)
        if np.any(self._errors2 < 0):
            raise RuntimeError("Cannot have negative squared errors.")
        if self._errors2.shape != self._frequencies.shape:
            raise RuntimeError("Errors must have same dimension as frequencies.")

        self.keep_missed = kwargs.pop("keep_missed", True)
        # Note: missed are dealt differently in 1D/ND cases

        if "axis_names" not in kwargs:
            kwargs["axis_names"] = ["axis{0}".format(i) for i in range(self.ndim)]

        # Meta data
        self._meta_data = kwargs.copy()

    @property
    def meta_data(self):
        """A dictionary of non-numerical information about the histogram.

        It contains several pre-defined ones, but you can add any other.
        These are preserved when saving and also in operations.

        Returns
        -------
        dict
        """
        return self._meta_data

    @property
    def name(self):
        """Name of the histogram (stored in meta-data).

        Returns
        -------
        str
        """
        return self._meta_data.get("name", None)

    @name.setter
    def name(self, value):
        """Name of the histogram.

        In plotting, this will be used as label.
        """
        self._meta_data["name"] = str(value)

    @property
    def title(self):
        """Title of the histogram to be displayed when plotted (stored in meta-data).
        
        If not specified, defaults to `name`.

        Returns
        -------
        str
        """
        return self._meta_data.get("title", self.name)

    @title.setter
    def title(self, value):
        """Title of the histogram.

        In plotting, this will be used as plot title.
        """
        self._meta_data["title"] = str(value)

    @property
    def axis_names(self):
        """Names of axes (stored in meta-data).

        Returns
        -------
        tuple[str]
        """
        default = ["axis{0}".format(i) for i in range(self.ndim)]
        return tuple(self._meta_data.get("axis_names", default))<commit_msg>Fix: HistogramBase.axis_names<commit_after>"""HistogramBase - base for all histogram classes."""
from __future__ import absolute_import, division
import numpy as np
from .binnings import as_binning


class HistogramBase(object):
    """Histogram base class.

    Behaviour shared by all histogram classes.

    The most important daughter classes are:
    - Histogram1D
    - HistogramND

    There are also special histogram types that are modifications of these classes.

    The methods you should override:
    - fill
    - fill_n (optional)
    - copy
    - _update_dict (optional)

    Underlying data type is int64 / float  or an explicitly specified
    other type (dtype).

    Attributes
    ----------
    _binnings : Iterable[BinningBase]
        Schema for binning(s)
    _frequencies : array_like
        Bin contents
    _errors2 : array_like
        Square errors associated with the bin contents
    _meta_data : dict
        All meta-data (names, user-custom values, ...). Anything can be put in.
        When exported, all information is kept.
    _dtype : np.dtype
        Type of the frequencies and also errors (int64, float64 or user-overridden)
    _missed : array_like
        Various storage for missed values in different histogram types
        (1 value for multi-dimensional, 3 values for one-dimensional)

    Invariants
    ----------
    - Frequencies in the histogram should always be non-negative.
    Many operations rely on that, but it is not always enforced.
    (TODO: Fix this?)

    See Also
    --------
    histogram1d
    histogram_nd
    special

    """

    def __init__(self, binnings, frequencies=None, errors2=None, **kwargs):
        """Constructor

        All keyword arguments not listed below become items in the _meta_data
        dictionary.

        Parameters
        ----------
        binnings : Iterable[BinningBase or array_like]
        frequencies : Optional[array_like]
        errors2 : Optional[array_like]
        dtype : np.dtype
        keep_missed : bool

        """
        self._binnings = [as_binning(binning) for binning in binnings]

        # Frequencies + appropriate dtypes
        if frequencies is None:
            dtype = kwargs.pop("dtype", np.int64)
            self._frequencies = np.zeros(self.shape, dtype=dtype)
        else:
            dtype = kwargs.pop("dtype", None)
            if dtype is not None:
                frequencies = np.asarray(frequencies, dtype=dtype)
            else:
                frequencies = np.asarray(frequencies)
                if np.issubdtype(frequencies.dtype, np.integer):
                    frequencies = frequencies.astype(np.int64)
                elif np.issubdtype(frequencies.dtype, np.floating):
                    frequencies = frequencies.astype(np.float64)
                else:
                    raise RuntimeError("Frequencies of type {0} not understood"
                                       .format(frequencies.dtype))
            dtype = frequencies.dtype
            if frequencies.shape != self.shape:
                raise RuntimeError("Values must have same dimension as bins.")
            if np.any(frequencies < 0):
                raise RuntimeError("Cannot have negative frequencies.")
            self._frequencies = frequencies
        self._dtype = dtype

        # Errors
        if errors2 is None:
            self._errors2 = self._frequencies.copy()
        else:
            self._errors2 = np.asarray(errors2, dtype=self.dtype)
        if np.any(self._errors2 < 0):
            raise RuntimeError("Cannot have negative squared errors.")
        if self._errors2.shape != self._frequencies.shape:
            raise RuntimeError("Errors must have same dimension as frequencies.")

        self.keep_missed = kwargs.pop("keep_missed", True)
        # Note: missed are dealt differently in 1D/ND cases

        if "axis_names" not in kwargs:
            kwargs["axis_names"] = ["axis{0}".format(i) for i in range(self.ndim)]

        # Meta data
        self._meta_data = kwargs.copy()

    @property
    def meta_data(self):
        """A dictionary of non-numerical information about the histogram.

        It contains several pre-defined ones, but you can add any other.
        These are preserved when saving and also in operations.

        Returns
        -------
        dict
        """
        return self._meta_data

    @property
    def name(self):
        """Name of the histogram (stored in meta-data).

        Returns
        -------
        str
        """
        return self._meta_data.get("name", None)

    @name.setter
    def name(self, value):
        """Name of the histogram.

        In plotting, this will be used as label.
        """
        self._meta_data["name"] = str(value)

    @property
    def title(self):
        """Title of the histogram to be displayed when plotted (stored in meta-data).
        
        If not specified, defaults to `name`.

        Returns
        -------
        str
        """
        return self._meta_data.get("title", self.name)

    @title.setter
    def title(self, value):
        """Title of the histogram.

        In plotting, this will be used as plot title.
        """
        self._meta_data["title"] = str(value)

    @property
    def axis_names(self):
        """Names of axes (stored in meta-data).

        Returns
        -------
        tuple[str]
        """
        default = ["axis{0}".format(i) for i in range(self.ndim)]
        return tuple(self._meta_data.get("axis_names", None) or default)
{'fraction_non_alphanumeric': 0.09232158988256549, 'fraction_numerical': 0.005600722673893405, 'mean_word_length': 1.948335552596538, 'pattern_counts': {'":': 0, '<': 7, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4476612', 'n_tokens_mistral': 3006, 'n_tokens_neox': 2927, 'n_words': 944}