validation#
Utilities for checking the inputs to components.
Functions#
Raises error if groupby domains are invalid. |
|
Raises a |
- validate_groupby_domains(groupby_domains, input_domain)#
Raises error if groupby domains are invalid.
In particular, this passes only if:
each column has a non-empty domain AND
for each column, all values in its domain are valid values w.r.t the input domain AND
for each column, each value in its domain is distinct.
- Parameters
groupby_domains (Mapping[str, Union[List[str], List[Optional[str]], List[int], List[Optional[int]], List[datetime.date], List[Optional[datetime.date]]]]) –
input_domain (tmlt.core.domains.spark_domains.SparkDataFrameDomain) –
- Return type
None
- validate_exact_number(value, allow_nonintegral=True, minimum=None, minimum_is_inclusive=True, maximum=None, maximum_is_inclusive=True)#
Raises a
ValueError
if value fails the specified conditions.Examples
Verify that a number is integral
>>> validate_exact_number( ... value=1, ... allow_nonintegral=False, ... ) >>> validate_exact_number( ... value=Fraction(1, 2), ... allow_nonintegral=False, ... ) Traceback (most recent call last): ValueError: 1/2 is not an integer
Verify that a number is between 0 and 1 (inclusive)
>>> validate_exact_number( ... value=1, ... minimum=0, ... maximum=1, ... ) >>> validate_exact_number( ... value=-1, ... minimum=0, ... maximum=1, ... ) Traceback (most recent call last): ValueError: -1 is not greater than or equal to 0 >>> validate_exact_number( ... value=2, ... minimum=0, ... maximum=1, ... ) Traceback (most recent call last): ValueError: 2 is not less than or equal to 1
Verify that a number is a finite integer
>>> validate_exact_number( ... value=-123, ... allow_nonintegral=False, ... minimum=-float("inf"), ... minimum_is_inclusive=False, ... maximum=float("inf"), ... maximum_is_inclusive=False, ... ) >>> validate_exact_number( ... value="0.5", ... allow_nonintegral=False, ... minimum=-float("inf"), ... minimum_is_inclusive=False, ... maximum=float("inf"), ... maximum_is_inclusive=False, ... ) Traceback (most recent call last): ValueError: 0.5 is not an integer >>> validate_exact_number( ... value=sp.oo, ... allow_nonintegral=False, ... minimum=-float("inf"), ... minimum_is_inclusive=False, ... maximum=float("inf"), ... maximum_is_inclusive=False, ... ) Traceback (most recent call last): ValueError: oo is not strictly less than inf >>> validate_exact_number( ... value=-sp.oo, ... allow_nonintegral=False, ... minimum=-float("inf"), ... minimum_is_inclusive=False, ... maximum=float("inf"), ... maximum_is_inclusive=False, ... ) Traceback (most recent call last): ValueError: -oo is not strictly greater than -inf
- Parameters
value (tmlt.core.utils.exact_number.ExactNumberInput) – A
sympy.Expr
to validate.allow_nonintegral (bool) – If False, raises an error if value is not integral, unless it is infinity.
minimum (Optional[tmlt.core.utils.exact_number.ExactNumberInput]) – An optional lower bound.
minimum_is_inclusive (bool) – If False, value is not allowed to be equal to minimum. Defaults to True.
maximum (Optional[tmlt.core.utils.exact_number.ExactNumberInput]) – An optional upper bound.
maximum_is_inclusive (bool) – If False, value being equal to maximum is not allowed. Defaults to True.
- Return type
None