<commit_before>#! /usr/bin/env python
"""Store collections of data fields."""

from .scalar_data_fields import ScalarDataFields


class Error(Exception):

    """Base class for errors in this module."""

    pass


class GroupError(Error, KeyError):

    """Raise this error for a missing group name."""

    def __init__(self, group):
        self._group = group

    def __str__(self):
        return self._group


class ModelDataFields(object):

    """Collection of grouped data-fields.

    The ModelDataFields class holds a set of ScalarDataFields that are
    separated into *groups*. A typical use for this class would be to define
    the groups as being locations on a grid where the values are defined.
    For instance, the groups could be *node*, *cell*, *link*, and *face*.

    Most of the method functions for ModelDataFields are the same as those for
    the ScalarDataFields class but with the first argument being a string that
    defines the group name.

    Attributes
    ----------
    groups

    See Also
    --------
    landlab.field.ScalarDataFields : Data fields within a *group* are
        stored as :class:`landlab.field.ScalarDataFields`.
    landlab.grid.ModelGrid : Inherits from ModelDataFields.

    Examples
    --------
<commit_msg>Added GroupSizeError.<commit_after>#! /usr/bin/env python
"""Store collections of data fields."""

from .scalar_data_fields import ScalarDataFields


class Error(Exception):

    """Base class for errors in this module."""

    pass


class GroupError(Error, KeyError):

    """Raise this error for a missing group name."""

    def __init__(self, group):
        self._group = group

    def __str__(self):
        return self._group


class GroupSizeError(Error, KeyError):

    """Raise this error if a group has changed sizes."""

    def __init__(self, group, old_size, new_size):
        self._group = group
        self._old_size = old_size
        self._new_size = new_size

    def __str__(self):
        return ("number of {group} elements has changed. "
                "(was = {was}, now={now})".format(group=self._group,
                                                  was=self._old_size,
                                                  now=self._new_size))


class ModelDataFields(object):

    """Collection of grouped data-fields.

    The ModelDataFields class holds a set of ScalarDataFields that are
    separated into *groups*. A typical use for this class would be to define
    the groups as being locations on a grid where the values are defined.
    For instance, the groups could be *node*, *cell*, *link*, and *face*.

    Most of the method functions for ModelDataFields are the same as those for
    the ScalarDataFields class but with the first argument being a string that
    defines the group name.

    Attributes
    ----------
    groups

    See Also
    --------
    landlab.field.ScalarDataFields : Data fields within a *group* are
        stored as :class:`landlab.field.ScalarDataFields`.
    landlab.grid.ModelGrid : Inherits from ModelDataFields.

    Examples
    --------

{'fraction_non_alphanumeric': 0.09249676584734799, 'fraction_numerical': 0.0, 'mean_word_length': 2.5348571428571427, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1517696', 'n_tokens_mistral': 821, 'n_tokens_neox': 787, 'n_words': 324}