Skip to content

Guard income imputation rescale against zero-total baseline#350

Merged
MaxGhenis merged 2 commits intomainfrom
fix/income-zero-guard
Apr 17, 2026
Merged

Guard income imputation rescale against zero-total baseline#350
MaxGhenis merged 2 commits intomainfrom
fix/income-zero-guard

Conversation

@MaxGhenis
Copy link
Copy Markdown
Contributor

Summary

impute_over_incomes in policyengine_uk_data/datasets/imputations/income.py computed new_income_total / original_income_total with no guard for the case where original_income_total == 0. That case is reachable from within impute_income itself, where the zero_weight_copy dataset is constructed specifically so its imputation columns contribute nothing — and it will become more common as additional callers of impute_over_incomes land.

Before: ZeroDivisionError (or silent NaN/inf propagating into household rent and mortgage columns).

After: _safe_rescale_factor(original, new) returns 1.0 when the baseline is zero (leaves rent/mortgage untouched), otherwise returns new / original as before.

Test plan

  • uv run pytest policyengine_uk_data/tests/test_income_rescale_factor.py -q passes.
  • Tests cover the zero-original case, the normal non-zero case, and finiteness of the returned factor across several representative inputs.

Finding U3 from the bug hunt.

@MaxGhenis
Copy link
Copy Markdown
Contributor Author

Self-review: APPROVE. See /tmp/bug-hunt/reviews/uk-data-reviews.md for detail. (GitHub blocks self-approve, so leaving as comment.)

@MaxGhenis MaxGhenis force-pushed the fix/income-zero-guard branch from af8315c to 5b1034d Compare April 17, 2026 16:22
@MaxGhenis MaxGhenis merged commit dbf7d21 into main Apr 17, 2026
2 of 3 checks passed
@MaxGhenis MaxGhenis deleted the fix/income-zero-guard branch April 17, 2026 16:26
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.

1 participant