Utils¶
-
sklearn_instrumentation.utils.
compose_decorators
(decorators: List[collections.abc.Callable]) → collections.abc.Callable[source]¶ Compose multiple decorators into one.
Helper function for combining multiple instrumentation decorators into one.
- Parameters
decorators (list(Callable)) – A list of instrumentation decorators to be combined into a single decorator.
-
sklearn_instrumentation.utils.
get_arg_by_key
(func: collections.abc.Callable, args: tuple, key: str)[source]¶ Get the value of a corresponding arg name as found in a function’s signature.
-
sklearn_instrumentation.utils.
get_descriptor
(func: collections.abc.Callable) → sklearn.utils.metaestimators._IffHasAttrDescriptor[source]¶ Get the corresponding
_IffHasAttrDescriptor
.
-
sklearn_instrumentation.utils.
get_estimators_in_package
(package_name: str = 'sklearn') → Set[Type[sklearn.base.BaseEstimator]][source]¶ Get all BaseEstimators from a package.
- Parameters
package_name (str) – a package name from which to get BaseEstimators
- Returns
A dictionary of fully qualified class names as keys and classes as values
-
sklearn_instrumentation.utils.
get_estimators_in_packages
(package_names: List[str]) → Set[Type[sklearn.base.BaseEstimator]][source]¶ Get all BaseEstimators from a list of packages.
- Parameters
package_names (list(str)) – a list of package names from which to get BaseEstimators
- Returns
A dictionary of fully qualified class names as keys and classes as values
-
sklearn_instrumentation.utils.
get_method_class
(estimator: Type[sklearn.base.BaseEstimator], method_name: str) → Type[source]¶ Get the class owner of the (possibly inherited) method.
-
sklearn_instrumentation.utils.
get_sklearn_estimator_from_method
(func: collections.abc.Callable) → sklearn.base.BaseEstimator[source]¶ Get the estimator of a method or delegate.
Raises TypeError is the instance is not a BaseEstimator.
- Parameters
func (Callable) – A bound method or delegator function of a BaseEstimator instance
- Returns
The BaseEstimator instance of the method or delegator.
-
sklearn_instrumentation.utils.
has_instrumentation
(estimator: Union[sklearn.base.BaseEstimator, Type[sklearn.base.BaseEstimator]], method_name: str) → bool[source]¶ Indicate if the estimator’s method is instrumented.
-
sklearn_instrumentation.utils.
is_class_method
(func: collections.abc.Callable) → bool[source]¶ Indicate if the method belongs to a class (opposed to an instance).
-
sklearn_instrumentation.utils.
is_delegator
(func: collections.abc.Callable) → bool[source]¶ Indicate if the method is delegated using
_IffHasAttrDescriptor
.
-
sklearn_instrumentation.utils.
is_instance_method
(func: collections.abc.Callable) → bool[source]¶ Indicate if the method belongs to an instance of a class (opposed to the class).