shapiq.utils.safe_isinstance¶

shapiq.utils.safe_isinstance(obj, class_path_str)[source]¶

Safely checks if an object is an instance of a class.

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:
  • obj (object) – Some object you want to test against

  • class_path_str (str | list[str] | tuple[str]) – A string or list of strings specifying full class paths Example: sklearn.ensemble.RandomForestRegressor

Return type:

bool

Returns:

True if isinstance is true and the package exists, False otherwise