-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEA add link for HTML representation #1051
Draft
glemaitre
wants to merge
6
commits into
skrub-data:main
Choose a base branch
from
glemaitre:html_repr_link
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
37cdcb5
FEA add link for HTML representation
glemaitre c473d92
fix import
glemaitre ce62f69
Add GapEncoder
glemaitre 4887823
remove docstring to pass the test and add TODO for future removal
glemaitre b2284b8
reduce diff using inheritance
glemaitre 5309352
[doc build]
glemaitre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,11 @@ | |
|
||
sklearn_version = parse_version(sklearn.__version__) | ||
|
||
# TODO: remove when scikit-learn 1.6 is the minimum supported version | ||
# TODO: subsequently, we should remove the inheritance from _HTMLDocumentationLinkMixin | ||
# for each estimator then. | ||
# TODO: remove when scikit-learn 1.6 is the minimum supported version and only import | ||
# We have this fix due to the following bug: | ||
# https://github.com/scikit-learn/scikit-learn/pull/29774 | ||
if sklearn_version > parse_version("1.6"): | ||
from sklearn.utils._estimator_html_repr import _HTMLDocumentationLinkMixin | ||
else: | ||
|
||
class _HTMLDocumentationLinkMixin: | ||
|
@@ -20,12 +20,12 @@ | |
|
||
@property | ||
def _doc_link_template(self): | ||
sklearn_version = parse_version(sklearn.__version__) | ||
if sklearn_version.dev is None: | ||
version_url = f"{sklearn_version.major}.{sklearn_version.minor}" | ||
else: | ||
version_url = "dev" | ||
return getattr( | ||
self, | ||
"__doc_link_template", | ||
( | ||
|
@@ -36,7 +36,7 @@ | |
|
||
@_doc_link_template.setter | ||
def _doc_link_template(self, value): | ||
setattr(self, "__doc_link_template", value) | ||
|
||
def _get_doc_link(self): | ||
"""Generates a link to the API documentation for a given estimator. | ||
|
@@ -52,10 +52,10 @@ | |
`""`) is returned. | ||
""" | ||
if self.__class__.__module__.split(".")[0] != self._doc_link_module: | ||
return "" | ||
|
||
if self._doc_link_url_param_generator is None: | ||
estimator_name = self.__class__.__name__ | ||
# Construct the estimator's module name, up to the first private | ||
# submodule. This works because in scikit-learn all public estimators | ||
# are exposed at that level, even if they actually live in a private | ||
|
@@ -66,10 +66,10 @@ | |
self.__class__.__module__.split("."), | ||
) | ||
) | ||
return self._doc_link_template.format( | ||
estimator_module=estimator_module, estimator_name=estimator_name | ||
) | ||
return self._doc_link_template.format( | ||
**self._doc_link_url_param_generator() | ||
) | ||
|
||
|
@@ -82,22 +82,28 @@ | |
|
||
|
||
def doc_link_url_param_generator(estimator): | ||
from skrub import __version__ | ||
|
||
skrub_version = parse_version(__version__) | ||
if skrub_version.dev is None: | ||
version_url = f"{skrub_version.major}.{skrub_version.minor}" | ||
else: | ||
version_url = "dev" | ||
estimator_name = estimator.__class__.__name__ | ||
estimator_module = ".".join( | ||
itertools.takewhile( | ||
lambda part: not part.startswith("_"), | ||
estimator.__class__.__module__.split("."), | ||
) | ||
) | ||
return { | ||
"version": version_url, | ||
"estimator_module": estimator_module, | ||
"estimator_name": estimator_name, | ||
} | ||
|
||
|
||
class _SkrubHTMLDocumentationLinkMixin(_HTMLDocumentationLinkMixin): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. even when the scikit-learn fix is released, we will most likely want this mixin to avoid repeating these 3 attributes everywhere. so in the end all we will have to remove is the so after all I am +1 for this PR |
||
_doc_link_template = doc_link_template | ||
_doc_link_module = doc_link_module | ||
_doc_link_url_param_generator = doc_link_url_param_generator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC we will now have 2 of those in every skrub estimator's parents, one directly and one through the BaseEstimator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. The one on the left in the inheritance will be the one used.