BUG Adjusts html_repr based on configuration#17093
BUG Adjusts html_repr based on configuration#17093adrinjalali merged 6 commits intoscikit-learn:masterfrom
Conversation
|
@jnothman @amueller @NicolasHug @ogrisel This is most likely only used by sphinx gallery. Currently the I part of me think this PR is not needed, but I am open to other opinions. |
|
Is there an example were a block ends with an estimator? I don't think we have much of these I'm fine eitherway. We can always merge this and then decide to use |
sklearn/base.py
Outdated
| """ | ||
| if get_config()["display"] == 'diagram': | ||
| return estimator_html_repr(self) | ||
| return f"<code>{html.escape(repr(self))}</code>" |
There was a problem hiding this comment.
Can't we just raise an AttibuteError here, shouldn't it be handled by sphinx gallery etc?
|
We have some raw output in the gallery, for example on master. |
|
Can't we detect that we are running inside sphinx via some env variable and otherwise raise AttributeError. I'm just not sure the priority between repr_html and mimetypebundle is correctly implemented in all environements. |
rth
left a comment
There was a problem hiding this comment.
Nevermind, I think it should be fine. Thanks @thomasjpfan !
|
I wanted to return an The only way around this is to return |
|
Updated |
Cant we do the same hack as in SVC predict_proba of a property that either returns a function or raises AttributeError, that way |
Yes, we can do it here as well. PR updated with the hack. |
|
Looks like this is needed even in jupyter lab, because |
ogrisel
left a comment
There was a problem hiding this comment.
A few suggestions but other than that +1 on my side as well.
sklearn/base.py
Outdated
| """HTML representation of estimator. | ||
|
|
||
| Used to display the HTML representation in sphinx-gallery. | ||
| Jupyer kernels will use `_repr_mimebundle_`. |
There was a problem hiding this comment.
There is a typo:
| Jupyer kernels will use `_repr_mimebundle_`. | |
| Jupyter kernels will use `_repr_mimebundle_`. |
and apparently this is wrong based on your last comment. I am not sure if _repr_mimebundle_ will ever take the priority. Maybe we can just state:
This is redundant with the logic of _repr_mimebundle_. The latter should be favored in the long term, _repr_html_ is only implemented for consumers who do not interpret _repr_mimebundle_.
|
|
||
| return out | ||
|
|
||
| @property |
There was a problem hiding this comment.
Maybe add a comment to explain that @property is necessary to make hasattr(estimator, "_repr_html_") return True or False depending on get_config()["display"] .
sklearn/base.py
Outdated
| raise AttributeError("_repr_html_ is only defined when the " | ||
| "'display' configuration option is set to " | ||
| "'diagram'") | ||
| return self.__repr_html_ |
There was a problem hiding this comment.
Is the use of leading dunder intentional? I find the behavior of private name mangling potentially confusing. Maybe self._repr_html_inner would be more explicit?
|
Seems like all other comments are addressed as well, merging. |
* ENH Adjusts html_repr based on configuration * CLN Returns None instead * CLN Uses property hack * CLN Address comments
* ENH Adjusts html_repr based on configuration * CLN Returns None instead * CLN Uses property hack * CLN Address comments
* ENH Adjusts html_repr based on configuration * CLN Returns None instead * CLN Uses property hack * CLN Address comments
* ENH Adjusts html_repr based on configuration * CLN Returns None instead * CLN Uses property hack * CLN Address comments


_repr_html_was defined to work to make sphinx-gallery work properly. This PR makes sure the return is just therepr, if thedisplayoption is not set.In a jupyter notebook, the
_repr_mimebundle_will be used so this PR will not have take any effect.