Handle falsy explicit impute replacements#1087
Conversation
|
The |
|
|
||
|
|
||
| @pytest.mark.parametrize("array_type", ARRAY_TYPES_NONNUMERIC) | ||
| def test_explicit_impute_subset_accepts_falsy_replacement_value(impute_edata, array_type): |
There was a problem hiding this comment.
It would be nice to test other falsy values than only 0, what do you think?
eroell
left a comment
There was a problem hiding this comment.
I see the point. Thank you!
Additional regression test is great, with all previous tests still passing: as this is of course correcting the function towards intended behavior, although for quite a special case.
Please add a release note - this is also to give your work visible credit!
|
Seems here on the CI some tests fail, which are most likely unrelated and are due to new releases. For |
Problem
explicit_impute()accepts mapping replacement values typed asstr | int | float, but falsy values such as0are skipped because the current implementation checks replacement values by truthiness.For example,
replacement={'intcol': 0}should be a valid per-column replacement, but0is treated as if no replacement was configured.Fix
Use mapping key existence checks in
_extract_impute_value()andis not Nonein the caller, so valid falsy replacements are applied. Added a regression test forreplacement={'intcol': 0}.Validation
Risk
Low. This changes behavior only for mapping replacement values that are valid by type but were previously skipped because they are falsy.