feat: add `errors` parameter to CategoricalImputer for multimodal variables
Description
Fixes #904
Adds an errors parameter to CategoricalImputer to handle multimodal categorical variables gracefully, instead of always raising a ValueError.
Changes
- Added
errorsparameter toCategoricalImputer.__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 aUserWarningand 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
errorsvalues and invalid input - Added
CHANGELOG.rstentry
Type of Change
- [ ] Bug fix
- [x] 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.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 98.27%. Comparing base (f72a2b7) to head (6f5b4da).
:warning: Report is 1 commits behind head on main.
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
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@solegalli facing issue with the 2 checks will work on this and move the PR for review in some time
the test pass percentage has increased still below the set benchmark trying to resolve the problems
Hi, @solegalli , I have made the implementations that you asked me to
also ran all the tests cases for just in case if there would an issue, all of them are passing
made formatting changes for passing the ci:test_style from this
"city": ["London", "London", "Paris", "Paris", "Berlin", "Berlin", "Madrid"],
"country": ["UK", "UK", "FR", "FR", "DE", "DE", "ES"],
"one_mode": ["London", "London", "London", "Paris", "Paris", "Berlin", "Berlin"],
to
"city": [
"London", "London", "Paris", "Paris", "Berlin", "Berlin", "Madrid"
],
"country": ["UK", "UK", "FR", "FR", "DE", "DE", "ES"],
"one_mode": [
"London", "London", "London", "Paris", "Paris", "Berlin", "Berlin"
],
Hey @solegalli, the only failing checks are the Codecov coverage ones.
Could you guide me on which test file I should add the coverage for the new errors='warn' and errors='raise' branches?
Changes made
- Rename of errors to multimodal in
categorical.py,test_categorical_imputer.py - Added missing Unit test case
test_warning_when_single_variable_in_list_is_multimodalintest_categorical_imputer.py
tests cases are passing locally
Hi, @solegalli the changes required in the comments you mentioned i will do then shortly
Hi, @solegalli the changes required in the comments you mentioned i will do then shortly
Alright! No problem at all. Give me a shout when you are ready! Thanks a lot for your support.
Hi, @solegalli , Changes have been added , now the pr is ready for your review
hi, @solegalli , the changes are done and the checks are passing would appreciate a merge.