Repository navigation
[MRG] Fix simple imputer with empty features doesn't put back removed columns - #28729
Closed
miguelcsilva wants to merge 7 commits into
scikit-learn:mainfrom
miguelcsilva:fix-simple-imputer-with-empty-features-doesnt-put-back-removed-columns
Closed
miguelcsilva wants to merge 7 commits intoscikit-learn:mainfrom miguelcsilva:fix-simple-imputer-with-empty-features-doesnt-put-back-removed-columns
miguelcsilva wants to merge 7 commits into
scikit-learn:mainfrom
miguelcsilva:fix-simple-imputer-with-empty-features-doesnt-put-back-removed-columns
Conversation
Member
|
@Micky774 ping for potential review. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Reference Issues/PRs
Fixes #27012
What does this implement/fix? Explain your changes.
Even though the discussion #27012 (comment) suggested two separate PRs I found it easier to make a single one since the two issues were tightly related.
The following changes were made:
SimpleImputer.fitsavesself._removals_maskandself._removalsifself.keep_empty_featuresisFalseto keep track of the indices where removals were made and of the arrays that were actually removed.SimpleImputer.inverse_transformwas refactored to replace thewhileloop with numpy vectorized operations.SimpleImputer.inverse_transformwas expanded to handle the case of empty features having been remove and now puts them back in the original positions.test_simple_imputation_inverse_transformwas refactored to usepytest.mark.parametrize. The original test cases were kept and 3 more test cases added to address the case where the entire columns have missing values.Any other comments?
To avoid the
transformandinverse_transformmethods diverging in the future, I would suggest that in a separate PR, thetransformfunction is changed to start using the newself._removals_maskandself._removalsattributes to decide on the features to remove. I'll be happy to work on a PR for that if this one is approved.I have not made any changes to the documentation since I considered very unlikely someone was actually relying on the bug. But I'm happy to make changes to the docs if you consider helpful.