Skip to content

Fix OneHotEncoder metadata dropping generated indicators (#1106) - #1107

Open
avinashtrivedix wants to merge 3 commits into
feature-engine:mainfrom
avinashtrivedix:fix/onehotencoder-name-collision
Open

avinashtrivedix wants to merge 3 commits into
feature-engine:mainfrom
avinashtrivedix:fix/onehotencoder-name-collision

Conversation

@avinashtrivedix

Copy link
Copy Markdown

Fixes #1106

Description

This PR resolves a metadata omission bug in OneHotEncoder where newly generated dummy columns were inadvertently dropped if their generated names collided with the original categorical input column names.

Changes Made

  • Modified _add_new_feature_names() in feature_engine/encoding/one_hot.py.
  • Reversed the order of operations in the list comprehension. The original categorical variables are now filtered out before the new dummy feature names are appended, entirely preventing the naming collision.
  • Left the transform() method untouched, respecting the architectural updates already pending in the narwhals-migration branch.

Testing

  • Verified the metadata fix locally against the minimal reproducible example provided in the original issue.
  • Executed the existing test suite (pytest tests/test_encoding/test_onehot_encoder.py); all 29 tests pass successfully against the current main branch.

@avinashtrivedix

Copy link
Copy Markdown
Author

I noticed the Python 3.9 pipeline is failing due to _SklearnCheckInputWrapper exceptions across unrelated modules (test_time_series, test_imputation, etc.). Since the style checks are green and the test_onehot_encoder.py suite passed successfully on the 3.10 and 3.11 runners, this appears to be a separate upstream environment issue on main. Let me know if you need any adjustments.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OneHotEncoder loses a dummy name when it matches an encoded input column

1 participant