Skip to content

input4mips_validation.exceptions#

input4mips_validation.exceptions #

Exceptions

NonUniqueError #

Bases: ValueError

Raised when a collection of values are not unique, but they should be

Source code in src/input4mips_validation/exceptions.py
class NonUniqueError(ValueError):
    """
    Raised when a collection of values are not unique, but they should be
    """

    def __init__(
        self,
        description: str,
        values: Collection[Any],
    ) -> None:
        """
        Initialise the error

        Parameters
        ----------
        description
            Description of the collection and the error

            This is used to make a more helpful error message.

        values
            Collection of values that contains non-unique values
        """
        occurence_counts = collections.Counter(values).most_common()
        error_msg = f"{description}. {occurence_counts=}"

        super().__init__(error_msg)

__init__(description, values) #

Initialise the error

Parameters:

Name Type Description Default
description str

Description of the collection and the error

This is used to make a more helpful error message.

required
values Collection[Any]

Collection of values that contains non-unique values

required
Source code in src/input4mips_validation/exceptions.py
def __init__(
    self,
    description: str,
    values: Collection[Any],
) -> None:
    """
    Initialise the error

    Parameters
    ----------
    description
        Description of the collection and the error

        This is used to make a more helpful error message.

    values
        Collection of values that contains non-unique values
    """
    occurence_counts = collections.Counter(values).most_common()
    error_msg = f"{description}. {occurence_counts=}"

    super().__init__(error_msg)