Skip to content

feat: add errors parameter to CategoricalImputer for multimodal variables#908

Open
direkkakkar319-ops wants to merge 7 commits intofeature-engine:mainfrom
direkkakkar319-ops:issue-904-categorical-imputer-multimodal
Open

feat: add errors parameter to CategoricalImputer for multimodal variables#908
direkkakkar319-ops wants to merge 7 commits intofeature-engine:mainfrom
direkkakkar319-ops:issue-904-categorical-imputer-multimodal

Conversation

@direkkakkar319-ops
Copy link

Description

Fixes #904

Adds an errors parameter to CategoricalImputer to handle multimodal categorical variables gracefully, instead of always raising a ValueError.

Changes

  • Added errors parameter to CategoricalImputer.__init__() with options 'raise' (default), 'warn', and 'ignore'
  • Updated both single-variable and multi-variable branches in .fit() to respect the new parameter
  • When errors='warn', emits a UserWarning and imputes using the first most frequent category found
  • When errors='ignore', silently imputes using the first most frequent category found
  • Default errors='raise' preserves existing behaviour — no breaking changes
  • Updated docstring with full parameter documentation
  • Added tests covering all three errors values and invalid input
  • Added CHANGELOG.rst entry

Type of Change

  • Bug fix
  • New feature (non-breaking)
  • Breaking change
  • Documentation update

Tests

All new and existing tests pass:

pytest tests/test_imputation/test_categorical_imputer.py

Notes

The existing error message ("contains multiple frequent categories") is preserved so no existing test matchers break.

Screenshot 2026-03-08 195813

@direkkakkar319-ops direkkakkar319-ops marked this pull request as draft March 8, 2026 14:36
@direkkakkar319-ops direkkakkar319-ops marked this pull request as ready for review March 8, 2026 15:11
@direkkakkar319-ops direkkakkar319-ops marked this pull request as draft March 8, 2026 15:14
@codecov
Copy link

codecov bot commented Mar 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.27%. Comparing base (f72a2b7) to head (a0ea71d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #908   +/-   ##
=======================================
  Coverage   98.27%   98.27%           
=======================================
  Files         116      116           
  Lines        4978     4988   +10     
  Branches      795      800    +5     
=======================================
+ Hits         4892     4902   +10     
  Misses         55       55           
  Partials       31       31           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@direkkakkar319-ops
Copy link
Author

@solegalli facing issue with the 2 checks will work on this and move the PR for review in some time

@direkkakkar319-ops direkkakkar319-ops marked this pull request as ready for review March 8, 2026 16:35
@direkkakkar319-ops direkkakkar319-ops marked this pull request as draft March 8, 2026 17:26
@direkkakkar319-ops
Copy link
Author

the test pass percentage has increased still below the set benchmark
trying to resolve the problems

@direkkakkar319-ops direkkakkar319-ops marked this pull request as ready for review March 9, 2026 19:06
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.

make CategoricalImputer not raise an error with multimodal variables

1 participant