Skip to content

Fix CategoricalImputer when fill_value is already a category - #1114

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

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.

@solegalli

Copy link
Copy Markdown
Collaborator

Hi @gopain185, thanks for the contribution.

This PR looks like it was generated end to end by an AI coding agent, without a person reviewing the change. We prefer contributions with a human in the loop: someone who understands the problem, has checked that it is real, and can discuss the design and respond to review comments. AI assistance is fine, but the contributor needs to own the change.

I'm closing this PR.

@solegalli solegalli closed this Nov 18, 2026
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

2 participants