Skip to content
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

Avoid hard import of sklearn in base module. #5663

Merged
merged 2 commits into from
Nov 21, 2023

Conversation

csadorf
Copy link
Contributor

@csadorf csadorf commented Nov 17, 2023

Fixes #5662.

@csadorf csadorf requested a review from a team as a code owner November 17, 2023 20:37
@github-actions github-actions bot added the Cython / Python Cython or Python issue label Nov 17, 2023
@csadorf csadorf added bug Something isn't working non-breaking Non-breaking change and removed Cython / Python Cython or Python issue labels Nov 17, 2023
@@ -447,9 +451,10 @@ class Base(TagsMixin,

def _repr_mimebundle_(self, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you verify if IPython handles this _repr_mimebundle_ function returning None in the same way as it handles this function not existing? In other words, is the notebook output without sklearn worse than the output before #5630?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know the answer, but I think you could return {"text/plain": repr(self)} in the case of scikit-learn not being installed and that would lead to the same thing being displayed as now. The way the mimebundles work is that you can return several (text, html, png, video, ...) and the UI then chooses the one it things is best. So if we only provide the text based on, it should always choose that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the documentation on this and it interpreted the phrase "[i]f this returns something, other _repr_*_ methods are ignored" to mean that if we return None on this function we are not returning "something" so other functions should be used. I also ran some tests in a Jupyter notebook which seemed to confirm that. However, could confirm that. I don't think that returning {"text/plain": repr(self)} is a good idea, because it seems that this function would take precedence over other potentially applicable functions. Which could lead to surprising behavior, especially when child classes try to specialize the representation in a meaningful way.

@betatim Was there a specific reason that you chose to use _repr_mimebundle_ as opposed to overriding _repr_html_?

Copy link
Contributor Author

@csadorf csadorf Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm slightly revising my comment. I think returning {"text/plain": repr(self)} is a good idea as long as we use the _repr_mimebundle_ function, however, I'm wondering whether it wouldn't be be better to use _repr_html_ in the first place.

Copy link
Contributor

@bdice bdice Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it’s better to use _repr_html_ for supporting only one special repr format.

Copy link
Contributor

@bdice bdice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks fine, just one question about testing IPython behavior when the magic repr is None.

@github-actions github-actions bot added the Cython / Python Cython or Python issue label Nov 20, 2023
@bdice
Copy link
Contributor

bdice commented Nov 20, 2023

I merged in branch-23.12 so that the clang-tidy job would pass.

@dantegd
Copy link
Member

dantegd commented Nov 21, 2023

/merge

@rapids-bot rapids-bot bot merged commit f79d40f into rapidsai:branch-23.12 Nov 21, 2023
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Cython / Python Cython or Python issue non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] sklearn is a hard dependency after #5630
4 participants