shapiq.utils.modules#
Functions
|
Acts as a safe version of isinstance without having to explicitly import packages which may not exist in the user's environment. |
|
Try to import a module and return None if it fails. |
- shapiq.utils.modules.safe_isinstance(obj, class_path_str)[source]#
Acts as a safe version of isinstance without having to explicitly import packages which may not exist in the user’s environment. Checks if obj is an instance of type specified by class_path_str.
Note
This function was directly taken from the shap repository.
- Parameters:
- Return type:
- Returns:
True if isinstance is true and the package exists, False otherwise
- shapiq.utils.modules.try_import(name, package=None)[source]#
Try to import a module and return None if it fails.
Note
Solution adapted from [stack overflow](https://stackoverflow.com/a/53241197).
- Parameters:
- Return type:
- Returns:
The imported module or None if the import fails.