diff --git a/changelog.d/fix-microsim-self-employment.fixed.md b/changelog.d/fix-microsim-self-employment.fixed.md new file mode 100644 index 00000000000..ff4dc1cd121 --- /dev/null +++ b/changelog.d/fix-microsim-self-employment.fixed.md @@ -0,0 +1 @@ +Fix the microsimulation smoke test for self-employment income when weighted business losses exceed profits. diff --git a/policyengine_us/tests/microsimulation/test_microsim.py b/policyengine_us/tests/microsimulation/test_microsim.py index 1e99c266e93..094645d343f 100644 --- a/policyengine_us/tests/microsimulation/test_microsim.py +++ b/policyengine_us/tests/microsimulation/test_microsim.py @@ -30,9 +30,16 @@ def test_microsim_runs(dataset: str, year: int): f"{decile_var} out of bounds." ) - # Check that the microsim calculates important variables as nonzero in current year. - for var in ["employment_income", "self_employment_income"]: - assert sim.calc(var, period=2024).sum() > 0, f"{var} is zero in 2024." + # Employment income should aggregate positive in the sample. + assert sim.calc("employment_income", period=2024).sum() > 0, ( + "employment_income is zero in 2024." + ) + + # Self-employment is net business income, so weighted totals can be + # negative when losses outweigh profits in the sampled records. + assert sim.calc("self_employment_income", period=2024).abs().sum() > 0, ( + "self_employment_income is zero in 2024." + ) def test_county_persists_across_periods():