Skip to content

FIX SimpleImputer.inverse_transform column shift with empty features … - #34949

Open
abhisekkundu-DS wants to merge 5 commits into
scikit-learn:mainfrom
abhisekkundu-DS:fix/simpleimputer-inverse-transform-27012
Open

abhisekkundu-DS wants to merge 5 commits into
scikit-learn:mainfrom
abhisekkundu-DS:fix/simpleimputer-inverse-transform-27012

Conversation

@abhisekkundu-DS

@abhisekkundu-DS abhisekkundu-DS commented Sep 13, 2026 •

Copy link
Copy Markdown

Reference Issues/PRs

Fixes #27012.

What does this implement/fix? Explain your changes.

This PR fixes a column-shifting issue in SimpleImputer.inverse_transform when the transformed data contains features that were empty during fitting.

The existing implementation could incorrectly identify valid features during inverse_transform, causing the reconstructed output columns to be shifted when empty features were present.

This PR:

  • Correctly detects valid features in SimpleImputer.inverse_transform.
  • Fixes the column-shifting behavior when empty features are present.
  • Adds regression tests covering inverse_transform with empty features.
  • Adds test coverage for non-NaN missing_values.
  • Adds the corresponding changelog entry.
  • Fixes a Ruff formatting issue in the tests.

Introduce yourself

Hi, I'm Abhisek Kundu. I currently work as an AI Engineer and have experience working with Python, machine learning, deep learning, and computer vision.

I use Python and machine learning libraries such as scikit-learn in my development and experimentation work. I wanted to contribute to scikit-learn because it is an important open-source project in the machine-learning ecosystem, and I wanted to gain experience contributing to a large production-quality codebase.

This is my first contribution to the scikit-learn community, and I'm looking forward to learning from the maintainers and improving the implementation based on their feedback.

AI usage disclosure

I used AI assistance for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

I reviewed the generated suggestions, adapted them to the scikit-learn codebase, and tested the resulting changes.

Any other comments?

Thank you for reviewing this contribution. I am happy to make any changes or improvements requested during the review process.

@github-actions

Copy link
Copy Markdown

Thank you for opening your first pull request to scikit-learn! 🎉

To help get your contribution reviewed, please make sure that:

  • You have filled out the pull request template.

  • The pull request addresses an existing issue that is ready for contribution (e.g. not tagged as 'Needs Triage', 'Needs Decision', ...). If you are proposing a new feature, please open an issue to discuss it first.

  • There are no other open pull requests already targeting the same issue.

  • You have followed the pull request checklist. In particular, linting and tests should pass.

@github-actions github-actions Bot added the CI:Linter failure The linter CI is failing on this PR label Sep 13, 2026
@github-actions github-actions Bot removed the CI:Linter failure The linter CI is failing on this PR label Sep 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

inverse_transform of SimpleImputer with empty features changes order of columns

1 participant