Skip to content

validations

validations

Module for validation actions inside of Blueprints.

Classes:

validations.EqualToZeroError

EqualToZeroError(value_name: str, value: float)

Bases: Exception

Raised when a value is equal to zero.

Source code in blueprints/validations.py
17
18
19
def __init__(self, value_name: str, value: float) -> None:
    message = f"Invalid value for '{value_name}': {value}. Values for '{value_name}' cannot be equal to zero."
    super().__init__(message)

validations.GreaterThan90Error

GreaterThan90Error(value_name: str, value: float)

Bases: Exception

Raised when a value is greater than 90.

Source code in blueprints/validations.py
41
42
43
def __init__(self, value_name: str, value: float) -> None:
    message = f"Invalid value for '{value_name}': {value}. Values for '{value_name}' cannot be greater than 90."
    super().__init__(message)

validations.LessOrEqualToZeroError

LessOrEqualToZeroError(value_name: str, value: float)

Bases: Exception

Raised when a value is less than or equal to zero.

Source code in blueprints/validations.py
 9
10
11
def __init__(self, value_name: str, value: float) -> None:
    message = f"Invalid value for '{value_name}': {value}. Values for '{value_name}' must be greater than zero."
    super().__init__(message)

validations.ListsNotSameLengthError

ListsNotSameLengthError(
    list_name_1: str, list_name_2: str, length_1: int, length_2: int
)

Bases: Exception

Raised when two lists are not of the same length.

Source code in blueprints/validations.py
49
50
51
52
53
54
def __init__(self, list_name_1: str, list_name_2: str, length_1: int, length_2: int) -> None:
    message = (
        f"The lists '{list_name_1}' and '{list_name_2}' are not of the same length. "
        f"'{list_name_1}' length: {length_1}, '{list_name_2}' length: {length_2}."
    )
    super().__init__(message)

validations.MismatchSignError

MismatchSignError(value_names: list[str])

Bases: Exception

Raised when not all the keyword values have the same sign.

Source code in blueprints/validations.py
33
34
35
def __init__(self, value_names: list[str]) -> None:
    message = f"Sign of values {', '.join(value_names)} should be the same."
    super().__init__(message)

validations.NegativeValueError

NegativeValueError(value_name: str, value: float)

Bases: Exception

Raised when a value is negative.

Source code in blueprints/validations.py
25
26
27
def __init__(self, value_name: str, value: float) -> None:
    message = f"Invalid value for '{value_name}': {value}. Values for '{value_name}' cannot be negative."
    super().__init__(message)

validations.raise_if_greater_than_90

raise_if_greater_than_90(**kwargs: float) -> None

Raise a GreaterThan90Error if any of the given keyword arguments are greater than 90.

Parameters:

  • **kwargs (dict[str, float], default: {} ) –

    A dictionary of keyword arguments where keys are parameter names, and values are the values to validate.

Raises:

Source code in blueprints/validations.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
def raise_if_greater_than_90(**kwargs: float) -> None:
    """Raise a GreaterThan90Error if any of the given keyword arguments are greater than 90.

    Parameters
    ----------
    **kwargs : dict[str, float]
        A dictionary of keyword arguments where keys are parameter names, and values are the values to validate.

    Raises
    ------
    GreaterThan90Error
        If any value is greater than 90.

    """
    for key, value in kwargs.items():
        if value > 90:
            raise GreaterThan90Error(value_name=key, value=value)

validations.raise_if_less_or_equal_to_zero

raise_if_less_or_equal_to_zero(**kwargs: float) -> None

Raise a LessOrEqualToZeroError if any of the given keyword arguments are less than or equal to zero.

Parameters:

  • **kwargs (dict[str, float], default: {} ) –

    A dictionary of keyword arguments where keys are parameter names, and values are the values to validate.

Raises:

Source code in blueprints/validations.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def raise_if_less_or_equal_to_zero(**kwargs: float) -> None:
    """Raise a LessOrEqualToZeroError if any of the given keyword arguments are less than or equal to zero.

    Parameters
    ----------
    **kwargs : dict[str, float]
        A dictionary of keyword arguments where keys are parameter names, and values are the values to validate.

    Raises
    ------
    LessOrEqualToZeroError
        If any value is less than or equal to zero.

    """
    for key, value in kwargs.items():
        if value <= 0:
            raise LessOrEqualToZeroError(value_name=key, value=value)

validations.raise_if_lists_differ_in_length

raise_if_lists_differ_in_length(**kwargs: Sequence) -> None

Check if all provided Sequences are of the same length.

Parameters:

  • **kwargs (dict[str, Sequence], default: {} ) –

    A dictionary of keyword arguments where keys are list names and values are the Sequences to check.

Raises:

Source code in blueprints/validations.py
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
def raise_if_lists_differ_in_length(**kwargs: Sequence) -> None:
    """Check if all provided Sequences are of the same length.

    Parameters
    ----------
    **kwargs : dict[str, Sequence]
        A dictionary of keyword arguments where keys are list names and values are the Sequences to check.

    Raises
    ------
    ListsNotSameLengthError
        If any two Sequences are not of the same length.
    """
    # Convert the kwargs items to a list of (name, list) tuples
    lists = list(kwargs.items())

    # Compare each list with the first list
    first_list_name, first_list = lists[0]
    first_length = len(first_list)

    for list_name, lst in lists[1:]:
        if len(lst) != first_length:
            raise ListsNotSameLengthError(first_list_name, list_name, first_length, len(lst))

validations.raise_if_mismatch_sign

raise_if_mismatch_sign(**kwargs: float) -> None

Raise a MismatchSignError if any of the given keyword arguments have different signs.

Parameters:

  • **kwargs (dict[str, float], default: {} ) –

    A dictionary of keyword arguments where keys are parameter names, and values are the values to validate.

Raises:

Source code in blueprints/validations.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
def raise_if_mismatch_sign(**kwargs: float) -> None:
    """Raise a MismatchSignError if any of the given keyword arguments have different signs.

    Parameters
    ----------
    **kwargs : dict[str, float]
        A dictionary of keyword arguments where keys are parameter names, and values are the values to validate.

    Raises
    ------
    MismatchSignError
        If any values have different signs.
    """
    if kwargs and not (all(v >= 0 for v in kwargs.values()) or all(v <= 0 for v in kwargs.values())):
        raise MismatchSignError(value_names=list(kwargs.keys()))

validations.raise_if_negative

raise_if_negative(**kwargs: float) -> None

Raise a NegativeValueError if any of the given keyword arguments are negative.

Parameters:

  • **kwargs (dict[str, float], default: {} ) –

    A dictionary of keyword arguments where keys are parameter names, and values are the values to validate.

Raises:

Source code in blueprints/validations.py
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def raise_if_negative(**kwargs: float) -> None:
    """Raise a NegativeValueError if any of the given keyword arguments are negative.

    Parameters
    ----------
    **kwargs : dict[str, float]
        A dictionary of keyword arguments where keys are parameter names, and values are the values to validate.

    Raises
    ------
    NegativeValueError
        If any value is negative.

    """
    for key, value in kwargs.items():
        if value < 0:
            raise NegativeValueError(value_name=key, value=value)