Skip to content

Fix CategoricalImputer when fill_value is already a category - #1114

Open
gopain185 wants to merge 1 commit into
feature-engine:mainfrom
gopain185:categorical-imputer-existing-fill-value
Open

gopain185 wants to merge 1 commit into
feature-engine:mainfrom
gopain185:categorical-imputer-existing-fill-value

Conversation

@gopain185

Copy link
Copy Markdown

Closes #1113.

CategoricalImputer(fill_value=...) always called cat.add_categories(fill_value) on categorical columns before
filling, so it raised ValueError: new categories must not include old categories when the value was already one
of the categories, for example when the categories were declared up front or when an already imputed frame was
transformed again. The category is now added only when it is missing.

The new test covers unordered and ordered categoricals and checks that a second transform leaves the result
unchanged. It fails without the change. pytest tests/test_imputation: 104 passed on both pandas 2.3.3 and 3.1.0.

The same pattern in RareLabelEncoder is handled separately in #1096.

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.

CategoricalImputer fails when fill_value is already a category

1 participant