From 65e4304f48b9922fb38b3f804c83b2255008cd11 Mon Sep 17 00:00:00 2001 From: Daphne Hansell <128793799+daphnehanse11@users.noreply.github.com> Date: Fri, 10 Apr 2026 14:54:25 -0400 Subject: [PATCH 1/2] Fix microsim self-employment smoke test --- changelog.d/fix-microsim-self-employment.fixed.md | 1 + policyengine_us/tests/microsimulation/test_microsim.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelog.d/fix-microsim-self-employment.fixed.md 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..3dfd76ed77f 100644 --- a/policyengine_us/tests/microsimulation/test_microsim.py +++ b/policyengine_us/tests/microsimulation/test_microsim.py @@ -31,8 +31,10 @@ def test_microsim_runs(dataset: str, year: int): ) # Check that the microsim calculates important variables as nonzero in current year. + # Self-employment is net business income, so weighted totals can be negative + # when losses outweigh profits in the sampled records. for var in ["employment_income", "self_employment_income"]: - assert sim.calc(var, period=2024).sum() > 0, f"{var} is zero in 2024." + assert sim.calc(var, period=2024).abs().sum() > 0, f"{var} is zero in 2024." def test_county_persists_across_periods(): From fea3d00fa7905be2d1a6a37a89b6fd5c1d6075be Mon Sep 17 00:00:00 2001 From: Daphne Hansell <128793799+daphnehanse11@users.noreply.github.com> Date: Mon, 13 Apr 2026 16:25:09 -0400 Subject: [PATCH 2/2] Address microsim self-employment review feedback --- .../tests/microsimulation/test_microsim.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/policyengine_us/tests/microsimulation/test_microsim.py b/policyengine_us/tests/microsimulation/test_microsim.py index 3dfd76ed77f..094645d343f 100644 --- a/policyengine_us/tests/microsimulation/test_microsim.py +++ b/policyengine_us/tests/microsimulation/test_microsim.py @@ -30,11 +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. - # Self-employment is net business income, so weighted totals can be negative - # when losses outweigh profits in the sampled records. - for var in ["employment_income", "self_employment_income"]: - assert sim.calc(var, period=2024).abs().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():