Skip to content

Conversation

@vahid-ahmadi
Copy link
Collaborator

Summary

  • Add np.maximum(0, ...) clipping to 5 income variables that previously allowed negative values
  • Add test to validate all income variables are non-negative

Variables fixed

Variable Line
employment_income 342
self_employment_income 368
tax_free_savings_income 372-380
savings_interest_income 393-395
dividend_income 396-411

Variables already protected (no changes needed)

  • private_pension_income - filters (pension.penpay > 0)
  • property_income - uses np.maximum(0, ...)
  • maintenance_income - uses sum_positive_variables()
  • miscellaneous_income - uses sum_from_positive_fields()

Test plan

  • Run pytest policyengine_uk_data/tests/test_non_negative_incomes.py
  • Verify all 9 income variables pass the non-negative check

@vahid-ahmadi vahid-ahmadi self-assigned this Dec 18, 2025
@vahid-ahmadi
Copy link
Collaborator Author

This PR should fix the error @anth-volk raised.

@vahid-ahmadi
Copy link
Collaborator Author

@PolicyEngine Review this pr pls

@policyengine
Copy link

policyengine bot commented Dec 19, 2025

Code Review ✅

I've reviewed this PR and the implementation looks solid. Here's my assessment:

Changes Verified

Variables correctly fixed with np.maximum(0, ...):

  • employment_income (line 342-343)
  • self_employment_income (line 370-371)
  • tax_free_savings_income (line 376-383)
  • savings_interest_income (line 397-400)
  • dividend_income (line 401-415)

Variables already protected (correctly identified in PR):

  • private_pension_income: uses pension.penpay > 0 filter (line 347)
  • property_income: uses np.maximum(0, ...) (line 430)
  • maintenance_income: uses sum_positive_variables() helper (line 446)
  • miscellaneous_income: uses sum_from_positive_fields() helper (line 464)

Test Quality

The test in test_non_negative_incomes.py is well-designed:

  • Parametrised across all 9 income variables
  • Provides clear error messages with actual minimum values
  • Comprehensive coverage

Code Quality

✅ Consistent use of np.maximum(0, ...) pattern
✅ Maintains existing code style and structure
✅ No over-engineering or unnecessary changes
✅ Proper changelog entry added

Recommendation

Approve and merge. This PR correctly addresses the negative income issue whilst respecting existing patterns and helper functions. The implementation is clean and the test coverage is appropriate.

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.

2 participants