nicetoolbox.utils.check_and_exception¶
Check and exception handling functions.
Functions
Check if an object is of a specific type and if it is within a given list of options. |
|
Check if a given token is present in a folder name. |
|
Check if an object's value falls within specified bounds. |
|
Check if any vectors in the last dimension of an array are zero vectors. |
|
This function logs an error message and then raises a specific error with a formatted message. |
|
Check if a file exists at the given path. |
- nicetoolbox.utils.check_and_exception.check_options(object, object_type, options) None[source]¶
Check if an object is of a specific type and if it is within a given list of options.
- Parameters:
object (any) – The object to be checked.
object_type (type) – The expected type of the object.
options (list) – A list of valid options for the object.
- Raises:
TypeError – If the object is not of the expected type.
ValueError – If the object is not within the list of valid options.
- Returns:
None
- nicetoolbox.utils.check_and_exception.check_token_in_filepath(folder_name: str, token: str, description: str) None[source]¶
Check if a given token is present in a folder name.
- Parameters:
folder_name (str) – The name of the folder to check.
token (str) – The token to search for in the folder name.
description (str) – A description of the folder for error messages.
- Raises:
ValueError – If the token is not found in the folder name.
- Returns:
None
- nicetoolbox.utils.check_and_exception.check_value_bounds(object, object_type=None, object_min=None, object_max=None) None[source]¶
Check if an object’s value falls within specified bounds.
- Parameters:
object (any) – The object to be checked.
object_type (type, optional) – The expected type of the object. Defaults to None.
object_min (any, optional) – The minimum value allowed for the object. Defaults to None.
object_max (any, optional) – The maximum value allowed for the object. Defaults to None.
- Raises:
TypeError – If the object is not of the expected type (if object_type is provided).
ValueError – If the object’s value is less than object_min (if object_min is provided). If the object’s value is greater than object_max (if object_max is provided).
- Returns:
None
- nicetoolbox.utils.check_and_exception.check_zeros(arr: ndarray) None[source]¶
Check if any vectors in the last dimension of an array are zero vectors.
- Args
arr (ndarray): The input array.
- Raises
AssertionError: If there are any zero vectors found in the last dimension of the array.
Examples >>> arr_3d_example = np.random.randint(0, 255, (10, 10, 3)) >>> check_zeros(arr_3d_example)
- nicetoolbox.utils.check_and_exception.error_log_and_raise(error, name, message)[source]¶
This function logs an error message and then raises a specific error with a formatted message.
- Parameters:
error (Exception) – The type of error to be raised.
name (str) – The name of the function or method where the error occurred.
message (str) – The detailed error message.
- Raises:
error – The specific error type raised with a formatted error message.