Skip to content

ENH Improves error message when experimental flag is not imported #23194

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

Conversation

thomasjpfan
Copy link
Member

Reference Issues/PRs

Fixes #13964

What does this implement/fix? Explain your changes.

This PR uses PEP 562 to display a better error message when IterativeImputer , HalvingRandomSearchCV, or HalvingGridSearchCV is imported without the experimental import flag

@thomasjpfan thomasjpfan added the Quick Review For PRs that are quick to review label Apr 22, 2022
@thomasjpfan thomasjpfan marked this pull request as draft April 23, 2022 21:09
@thomasjpfan thomasjpfan marked this pull request as ready for review April 23, 2022 21:17
@thomasjpfan thomasjpfan changed the title ENH Imporves error message for experimental import flags ENH Imporves error message when experimental flag is not imported Apr 24, 2022
@lesteve lesteve changed the title ENH Imporves error message when experimental flag is not imported ENH Improves error message when experimental flag is not imported Apr 25, 2022
Copy link
Member

@lesteve lesteve left a comment

Choose a reason for hiding this comment

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

LGTM.

Just wondering, in principle we could put all the logic in __getattr__ (checking if sklearn.experimental.enable_bla is in sys.modules) and remove the code from sklearn.experimental.enable_bla, right?

The advantage would be that the experimental enabling logic in in a single place.

Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

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

Lgtm. Loic has a point if it's worth tackling

@thomasjpfan
Copy link
Member Author

Just wondering, in principle we could put all the logic in getattr (checking if sklearn.experimental.enable_bla is in sys.modules) and remove the code from sklearn.experimental.enable_bla, right?

Yes, this is a good idea. I included your suggestion in: b952e7a (#23194)

setattr(model_selection, "HalvingRandomSearchCV", HalvingRandomSearchCV)
setattr(model_selection, "HalvingGridSearchCV", HalvingGridSearchCV)

model_selection.__all__ += ["HalvingRandomSearchCV", "HalvingGridSearchCV"]
Copy link
Member

Choose a reason for hiding this comment

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

The __all__ functionality has not been replicated in __getattr__, is that on purpose?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have not consider __all__. I do not think there is a way to replicate it in __getattr__. PEP562 allows us to adjust dir, but that does not influence __all__ or the import * mechanism.

With that in mind, I reverted the commit that moves everything into __getattr__.

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

LGTM. I let @lesteve having a final look.

@lesteve
Copy link
Member

lesteve commented Apr 27, 2022

Merging, thanks!

@lesteve lesteve merged commit 1d6a237 into scikit-learn:main Apr 27, 2022
jjerphan pushed a commit to jjerphan/scikit-learn that referenced this pull request Apr 29, 2022
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Experimental error message
4 participants