You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
inverse_transform of SimpleImputer with empty features changes order of columns #27012
When one uses a SimpleImputer with keep_empty_features=False and add_indicator=True, then if a column has only missing values during fit, but has values during transform, then the inverse transform will shift all columns to the right of that column one to the left.
(Note that I found this while experimenting and is not something that we rely on being fixed)
The indicator column (the final column of zeros) ought to be removed after the inverse
The inverse transform knows what it removes, and so should be able to "put it back". Ideally, the inverse should behave as an actual inverse and fully undo the initial transformation.
Can I work on this issue ? I think I can solve this issue.
Sure, we'd appreciate the help! Just keep in mind that there are two bugs which ought to be handled in two, separate PRs. The first is probably easier.
@lorentzenchr@Micky774 I have a fix for the above issue but I feel in general the current architecture of simple imputer is such that if you fit on some data and transform other data then it is prone to many errors.
I can think of few additional test cases where things would fail if we fit and transform in this manner.
I feel when we are transforming, we should re-calculate the statistics [number of missing feature for example] again rather than using them from fit time. I am opening a sperate issue for the new failing test cases I can think of to highlight the bigger issue.
Hi,
I was still able to reproduce the issue on scikit-learn 1.8.0 (numoy 2.4.1).
I noticed that PR #28729 attempted a fix but was closed when the fork was deleted.
If that's ok, would be happy to work on it
Activity
Micky774 commentedon Aug 11, 2023
Two bugs highlighted here:
PRs are welcome for both.
Kaustbh commentedon Aug 17, 2023
Can I work on this issue ? I think I can solve this issue.
Micky774 commentedon Aug 17, 2023
Sure, we'd appreciate the help! Just keep in mind that there are two bugs which ought to be handled in two, separate PRs. The first is probably easier.
vjoshi253 commentedon Feb 11, 2024
Since the help wanted tag is here, I am assuming no one is working on this. I would take this up.
@lorentzenchr @Micky774
vjoshi253 commentedon Feb 17, 2024
@lorentzenchr @Micky774 I have a fix for the above issue but I feel in general the current architecture of simple imputer is such that if you fit on some data and transform other data then it is prone to many errors.
I can think of few additional test cases where things would fail if we fit and transform in this manner.
I feel when we are transforming, we should re-calculate the statistics [number of missing feature for example] again rather than using them from fit time. I am opening a sperate issue for the new failing test cases I can think of to highlight the bigger issue.
AlessandroCesaTs commentedon Jan 28, 2026
Hi,
I was still able to reproduce the issue on scikit-learn 1.8.0 (numoy 2.4.1).
I noticed that PR #28729 attempted a fix but was closed when the fork was deleted.
If that's ok, would be happy to work on it
Shreecharana24 commentedon Feb 3, 2026
Thanks for confirming this is still reproducible.
I can reproduce the issue on the current main branch.
I’m working on a fix with a regression test; will open a draft PR once ready.
FIX SimpleImputer inverse_transform with all-NaN features and add_ind…
FIX SimpleImputer inverse_transform with all-NaN features and add_ind…
FIX SimpleImputer.inverse_transform column shift with empty features (s…
TST Add regression tests for inverse_transform with empty features (s…
STY Fix ruff format lint issue in test_impute.py (scikit-learn#27012)
TST Add coverage for non-NaN missing_values and add changelog entry (s…
FIX Correctly detect valid features in SimpleImputer.inverse_transfor…
FIX SimpleImputer inverse_transform with empty features