1616
1717import logging
1818import os
19+ import re
1920import warnings
2021from abc import ABC
2122
23+ import sklearn
24+
2225from daal4py .sklearn ._utils import (
2326 PatchingConditionsChain as daal4py_PatchingConditionsChain ,
2427)
25- from daal4py .sklearn ._utils import daal_check_version
28+ from daal4py .sklearn ._utils import daal_check_version , sklearn_check_version
29+
30+ # Note: if inheriting from '_HTMLDocumentationLinkMixin' here, it then doesn't matter
31+ # the order of inheritance of classes for estimators when this is later subclassed,
32+ # whereas if inheriting from something else, the subclass that inherits from this needs
33+ # to be the first inherited class in estimators in order for it to take effect.
34+ if sklearn_check_version ("1.4" ):
35+ from sklearn .utils ._estimator_html_repr import _HTMLDocumentationLinkMixin
36+
37+ BaseForHTMLDocLink = _HTMLDocumentationLinkMixin
38+ else :
39+ BaseForHTMLDocLink = ABC
2640
2741
2842class PatchingConditionsChain (daal4py_PatchingConditionsChain ):
@@ -128,10 +142,8 @@ def get_hyperparameters(self, op):
128142
129143
130144# This abstract class is meant to generate a clickable doc link for classses
131- # in sklearnex that are not part of base scikit-learn. It should be inherited
132- # before inheriting from a scikit-learn estimator, otherwise will get overriden
133- # by the estimator's original.
134- class IntelEstimator (ABC ):
145+ # in sklearnex that are not part of base scikit-learn.
146+ class IntelEstimator (BaseForHTMLDocLink ):
135147 @property
136148 def _doc_link_module (self ) -> str :
137149 return "sklearnex"
@@ -141,3 +153,25 @@ def _doc_link_template(self) -> str:
141153 module_path , _ = self .__class__ .__module__ .rsplit ("." , 1 )
142154 class_name = self .__class__ .__name__
143155 return f"https://uxlfoundation.github.io/scikit-learn-intelex/latest/non-scikit-algorithms.html#{ module_path } .{ class_name } "
156+
157+
158+ # This abstract class is meant to generate a clickable doc link for classses
159+ # in sklearnex that have counterparts in scikit-learn.
160+ class PatchableEstimator (BaseForHTMLDocLink ):
161+ @property
162+ def _doc_link_module (self ) -> str :
163+ return "sklearnex"
164+
165+ @property
166+ def _doc_link_template (self ) -> str :
167+ if re .search (r"^\d\.\d\.\d$" , sklearn .__version__ ):
168+ sklearn_version_parts = sklearn .__version__ .split ("." )
169+ doc_version_url = sklearn_version_parts [0 ] + "." + sklearn_version_parts [1 ]
170+ else :
171+ doc_version_url = "stable"
172+ module_path , _ = self .__class__ .__module__ .rsplit ("." , 1 )
173+ module_path = re .sub ("sklearnex" , "sklearn" , module_path )
174+ class_name = self .__class__ .__name__
175+ # for TSNE, which re-uses daal4py
176+ module_path = re .sub (r"daal4py\." , "" , module_path )
177+ return f"https://scikit-learn.org/{ doc_version_url } /modules/generated/{ module_path } .{ class_name } .html"
0 commit comments