-
-
Notifications
You must be signed in to change notification settings - Fork 26.5k
API Rename OneHotEncoder option sparse to sparse_output #24412
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
glemaitre
left a comment
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.
You will also need an entry in the 1.2 changelog to acknowledge the deprecation.
| "will be removed in 1.4.", | ||
| FutureWarning, | ||
| ) | ||
| self.sparse_output = self.sparse |
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.
This is an annoying case here.
Supposedly, we should be raising an error if both sparse and sparse_output are set to non-default values. However, to detect it we need to add a None option to sparse_output that defaults to True by default. However, we don't want None and we also need to depreciate it at the inclusion such that we remove it. It means that in practice we will always be raising a warning and force users to set it to a bool.
@jeremiedbb I recall that we had a similar pattern somewhere else (DictionaryLearning of NMF). How did we do it?
@lorentzenchr @thomasjpfan do you see a better way?
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.
To keep it simple, I would raise in the following case
if self.sparse != "deprecated" and self.sparse != self.sparse_output:
raise ValueError("Some informative message")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.
This doesn't work because you don't want to raise when the user sets sparse to a value different than the default of sparse_output.
To me the appropriate way is to do as explained in our docs, i.e. if a user sets sparse we raise a warning saying that it's deprecated and that sparse_output should be used instead and is ignored, and then use the value of sparse.
We don't really need to raise when both are set, the future warning is enough
lorentzenchr
left a comment
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.
This is already looking quite good.
sklearn/ensemble/_hist_gradient_boosting/tests/test_gradient_boosting.py
Outdated
Show resolved
Hide resolved
| "will be removed in 1.4.", | ||
| FutureWarning, | ||
| ) | ||
| self.sparse_output = self.sparse |
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.
To keep it simple, I would raise in the following case
if self.sparse != "deprecated" and self.sparse != self.sparse_output:
raise ValueError("Some informative message")Co-authored-by: Christian Lorentzen <[email protected]>
jeremiedbb
left a comment
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.
Thanks for the PR @rusdes. Here are just a few comments. LGTM Otherwise
Co-authored-by: Jérémie du Boisberranger <[email protected]>
Co-authored-by: Jérémie du Boisberranger <[email protected]>
jeremiedbb
left a comment
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.
LGTM. Thanks @rusdes.
@glemaitre, are you ok with this handling of the param renaming (see #24412 (comment)) ?
|
True this is fine with me. Thanks @rusdes Good to be merged. |
|
@lorentzenchr @glemaitre @jeremiedbb I was going through some code and found that |
@rusdes I agree with you. Feel free to directly open a PR to make the deprecation. Thanks |
Reference Issues/PRs
Fixes #24265.
What does this implement/fix? Explain your changes.
This PR deprecates
sparseparameter inOneHotEncoderand introducessparse_output.Any other comments?
Launched:
and all tests pass with 0 warnings.