hvl_ccb.utils.validation
- validate_and_resolve_host(host: str | IPv4Address | IPv6Address | None, logger: Logger | None = None) str[source]
- validate_bool(x_name: str, x: object, logger: Logger | None = None) None[source]
Validate if given input x is a bool.
- Parameters:
x_name – string name of the validate input, use for the error message
x – an input object to validate as boolean
logger – logger of the calling submodule
- Raises:
TypeError – when the validated input does not have boolean type
- validate_number(x_name: str, x: object, limits: tuple[int | float | None, int | float | None] | list[int | float | None] | None = (None, None), number_type: type[int | float] | tuple[type[int | float], ...] = (<class 'int'>, <class 'float'>), *, closed_interval: bool | tuple[bool, bool] | list[bool] = True, logger: ~logging.Logger | None = None) None[source]
Validate if given input x is a number of given number_type type, with value between given limits[0] and limits[1], if not None.
For array-like objects (npt.NDArray, list, tuple, dict) it is checked if all elements are within the limits and have the correct type.
- Parameters:
x_name – string name of the validate input, use for the error message
x – an input object to validate as number of given type within given range
limits – two-item list/tuple with lower and upper limit. Use None for an unbounded side. -np.inf is accepted as unbounded lower limit, and np.inf is accepted as unbounded upper limit.
number_type – expected type or tuple of types of a number, by default (int, float)
closed_interval – if True, both limits are inclusive; if False, both are exclusive; alternatively, provide (lower_closed, upper_closed) to define half-open intervals
logger – logger of the calling submodule
- Raises:
TypeError – when the validated input does not have expected type
ValueError – when the validated input has correct number type but is not within given range or has wrong input limits