From f376f9570c7cec2cab09329a8e4ea7cf4aa13afe Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Thu, 12 Nov 2026 01:05:52 -0500 Subject: [PATCH 1/3] Gate CSFP payments on an explicit take-up input Co-Authored-By: Claude Opus 5.5 --- changelog.d/csfp-take-up-input.breaking.md | 1 + .../tests/core/test_csfp_takeup_invariants.py | 132 ++++++++++++++++++ .../gov/states/ks/dcf/csfp/integration.yaml | 36 +++++ .../commodity_supplemental_food_program.yaml | 6 + .../baseline/gov/usda/csfp/integration.yaml | 4 + .../usda/csfp/takes_up_csfp_if_eligible.yaml | 39 ++++++ .../commodity_supplemental_food_program.py | 6 +- .../usda/csfp/takes_up_csfp_if_eligible.py | 17 +++ 8 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 changelog.d/csfp-take-up-input.breaking.md create mode 100644 policyengine_us/tests/core/test_csfp_takeup_invariants.py create mode 100644 policyengine_us/tests/policy/baseline/gov/usda/csfp/takes_up_csfp_if_eligible.yaml create mode 100644 policyengine_us/variables/gov/usda/csfp/takes_up_csfp_if_eligible.py diff --git a/changelog.d/csfp-take-up-input.breaking.md b/changelog.d/csfp-take-up-input.breaking.md new file mode 100644 index 00000000000..db842901c7c --- /dev/null +++ b/changelog.d/csfp-take-up-input.breaking.md @@ -0,0 +1 @@ +Added an annual person input for CSFP take-up that defaults to false and requires explicit take-up for payments. diff --git a/policyengine_us/tests/core/test_csfp_takeup_invariants.py b/policyengine_us/tests/core/test_csfp_takeup_invariants.py new file mode 100644 index 00000000000..ebc86436fd8 --- /dev/null +++ b/policyengine_us/tests/core/test_csfp_takeup_invariants.py @@ -0,0 +1,132 @@ +"""Check CSFP take-up across people and years in one vectorized simulation. + +YAML covers fixed policy cases. With explicit flags for each year, Hypothesis +checks that changing one person's input changes only their payment for that +year. Each example +also compares all-true take-up with the payment before the take-up gate and +recomputes eligibility after each change to detect any take-up dependency. +""" + +import numpy as np +from hypothesis import HealthCheck, given, settings +from hypothesis import strategies as st + +from policyengine_us import Simulation + +YEARS = (2019, 2024, 2025, 2026) +BENEFIT = "commodity_supplemental_food_program" +ELIGIBILITY = "commodity_supplemental_food_program_eligible" +TAKEUP = "takes_up_csfp_if_eligible" + +people = st.tuples( + st.integers(0, 100), + st.sampled_from([0.0, 0.5, 1.0, 1.3, 1.5, 2.0, 3.0]), + st.tuples(*(st.booleans() for _ in YEARS)), +) + + +def _simulation(rows): + persons = {} + groups = { + name: {} for name in ("tax_units", "marital_units", "spm_units", "families") + } + for i, (age, ratio, _) in enumerate(rows): + person = f"person_{i}" + persons[person] = { + "age": {year: age for year in YEARS}, + "tx_dta_csfp_income_eligible": {year: False for year in YEARS}, + "ks_dcf_csfp_categorically_eligible": { + f"{year}-12": False for year in YEARS + }, + } + for name, units in groups.items(): + units[f"{name}_{i}"] = {"members": [person]} + groups["spm_units"][f"spm_units_{i}"]["school_meal_fpg_ratio"] = { + year: ratio for year in YEARS + } + # Share a household so a household-wide take-up gate would fail. + household = { + "members": list(persons), + "state_code": {year: "CA" for year in YEARS}, + } + for name in ( + "ks_dcf_csfp_county_eligible", + "ma_dese_csfp_county_eligible", + "il_dhs_csfp_county_eligible", + ): + household[name] = {year: True for year in YEARS} + return Simulation( + situation={ + "people": persons, + "households": {"household": household}, + **groups, + } + ) + + +def _recalculate(simulation, year): + # Clear both outputs to recompute eligibility after changing take-up. + simulation.delete_arrays(BENEFIT, year) + simulation.delete_arrays(ELIGIBILITY, year) + eligibility = np.asarray(simulation.calculate(ELIGIBILITY, year)).copy() + benefit = np.asarray(simulation.calculate(BENEFIT, year)).copy() + return eligibility, benefit + + +@settings( + max_examples=6, + deadline=None, + derandomize=True, + suppress_health_check=[HealthCheck.too_slow, HealthCheck.data_too_large], +) +@given( + drawn=st.lists(people, min_size=4, max_size=12), + changed_year=st.sampled_from(YEARS), +) +def test_csfp_takeup_invariants(drawn, changed_year): + # Anchor an eligible person and two people who fail age or income. + rows = [ + (70, 0.0, (False, True, False, True)), + (30, 0.0, (True, False, True, False)), + (70, 100.0, (True, True, True, True)), + *drawn, + ] + simulation = _simulation(rows) + eligibility_before = {} + old_payments = {} + for year in YEARS: + amount = simulation.tax_benefit_system.parameters(year).gov.usda.csfp.amount + eligibility_before[year], default_benefit = _recalculate(simulation, year) + assert eligibility_before[year][0] + assert not eligibility_before[year][1:3].any() + old_payments[year] = eligibility_before[year] * amount + assert not np.asarray(simulation.calculate(TAKEUP, year)).any() + np.testing.assert_array_equal(default_benefit, np.zeros(len(rows))) + + for year in YEARS: + amount = simulation.tax_benefit_system.parameters(year).gov.usda.csfp.amount + flags = np.array([row[2][YEARS.index(year)] for row in rows]) + simulation.set_input(TAKEUP, year, flags) + eligible, benefit = _recalculate(simulation, year) + np.testing.assert_array_equal(eligible, eligibility_before[year]) + assert (benefit >= 0).all() + assert (benefit <= amount).all() + assert (benefit[~flags | ~eligible] == 0).all() + np.testing.assert_array_equal(benefit, old_payments[year] * flags) + + for year in YEARS: + simulation.set_input(TAKEUP, year, np.ones(len(rows), dtype=bool)) + eligible, benefit = _recalculate(simulation, year) + np.testing.assert_array_equal(eligible, eligibility_before[year]) + np.testing.assert_array_equal(benefit, old_payments[year]) + + flags = np.ones(len(rows), dtype=bool) + flags[0] = False + simulation.set_input(TAKEUP, changed_year, flags) + for year in YEARS: + eligible, benefit = _recalculate(simulation, year) + np.testing.assert_array_equal(eligible, eligibility_before[year]) + expected = old_payments[year].copy() + if year == changed_year: + expected[0] = 0 + np.testing.assert_array_equal(benefit, expected) diff --git a/policyengine_us/tests/policy/baseline/gov/states/ks/dcf/csfp/integration.yaml b/policyengine_us/tests/policy/baseline/gov/states/ks/dcf/csfp/integration.yaml index a217c0a9ef9..6b645c54a2b 100644 --- a/policyengine_us/tests/policy/baseline/gov/states/ks/dcf/csfp/integration.yaml +++ b/policyengine_us/tests/policy/baseline/gov/states/ks/dcf/csfp/integration.yaml @@ -9,21 +9,25 @@ input: people: person1: + takes_up_csfp_if_eligible: true age: 60 ssi: 1_200 receives_ssi: false msp: 0 person2: + takes_up_csfp_if_eligible: true age: 68 ssi: 0 receives_ssi: false msp: 0 person3: + takes_up_csfp_if_eligible: true age: 35 ssi: 1_200 receives_ssi: false msp: 0 person4: + takes_up_csfp_if_eligible: true age: 70 ssi: 0 receives_ssi: false @@ -56,21 +60,25 @@ input: people: person1: + takes_up_csfp_if_eligible: true age: 60 ssi: 0 receives_ssi: true msp: 0 person2: + takes_up_csfp_if_eligible: true age: 68 ssi: 0 receives_ssi: false msp: 0 person3: + takes_up_csfp_if_eligible: true age: 35 ssi: 0 receives_ssi: true msp: 0 person4: + takes_up_csfp_if_eligible: true age: 70 ssi: 0 receives_ssi: false @@ -103,21 +111,25 @@ input: people: person1: + takes_up_csfp_if_eligible: true age: 60 ssi: 0 receives_ssi: false msp: 0 person2: + takes_up_csfp_if_eligible: true age: 68 ssi: 0 receives_ssi: false msp: 0 person3: + takes_up_csfp_if_eligible: true age: 35 ssi: 0 receives_ssi: false msp: 0 person4: + takes_up_csfp_if_eligible: true age: 70 ssi: 0 receives_ssi: false @@ -150,21 +162,25 @@ input: people: person1: + takes_up_csfp_if_eligible: true age: 60 ssi: 0 receives_ssi: false msp: 0 person2: + takes_up_csfp_if_eligible: true age: 68 ssi: 0 receives_ssi: false msp: 0 person3: + takes_up_csfp_if_eligible: true age: 35 ssi: 0 receives_ssi: false msp: 0 person4: + takes_up_csfp_if_eligible: true age: 70 ssi: 0 receives_ssi: false @@ -197,21 +213,25 @@ input: people: person1: + takes_up_csfp_if_eligible: true age: 60 ssi: 0 receives_ssi: false msp: 0 person2: + takes_up_csfp_if_eligible: true age: 68 ssi: 0 receives_ssi: false msp: 0 person3: + takes_up_csfp_if_eligible: true age: 35 ssi: 0 receives_ssi: false msp: 0 person4: + takes_up_csfp_if_eligible: true age: 70 ssi: 0 receives_ssi: false @@ -244,21 +264,25 @@ input: people: person1: + takes_up_csfp_if_eligible: true age: 60 ssi: 0 receives_ssi: false msp: 1_200 person2: + takes_up_csfp_if_eligible: true age: 68 ssi: 0 receives_ssi: false msp: 0 person3: + takes_up_csfp_if_eligible: true age: 35 ssi: 0 receives_ssi: false msp: 1_200 person4: + takes_up_csfp_if_eligible: true age: 70 ssi: 0 receives_ssi: false @@ -289,6 +313,7 @@ - name: Case 7, income at the limit qualifies without program receipt. period: 2026 input: + takes_up_csfp_if_eligible: true age: 60 school_meal_fpg_ratio: 1.5 state_code: KS @@ -306,6 +331,7 @@ - name: Case 8, income above the limit fails without program receipt. period: 2026 input: + takes_up_csfp_if_eligible: true age: 68 school_meal_fpg_ratio: 1.51 state_code: KS @@ -323,6 +349,7 @@ - name: Case 9, categorical income eligibility does not waive the county gate. period: 2026 input: + takes_up_csfp_if_eligible: true age: 68 school_meal_fpg_ratio: 2 state_code: KS @@ -340,6 +367,7 @@ - name: Case 10, categorical income eligibility does not waive minimum age. period: 2026 input: + takes_up_csfp_if_eligible: true age: 59 school_meal_fpg_ratio: 2 state_code: KS @@ -357,6 +385,7 @@ - name: Case 11, Kansas categorical option does not apply to other states. period: 2026 input: + takes_up_csfp_if_eligible: true age: 68 school_meal_fpg_ratio: 2 state_code: MO @@ -374,6 +403,7 @@ - name: Case 12, categorical income bypass is not backdated before the state plan. period: 2024 input: + takes_up_csfp_if_eligible: true age: 68 school_meal_fpg_ratio: 2 state_code: KS @@ -391,6 +421,7 @@ - name: Case 13, categorical income bypass applies in the state plan year. period: 2025 input: + takes_up_csfp_if_eligible: true age: 68 school_meal_fpg_ratio: 2 state_code: KS @@ -410,11 +441,13 @@ input: people: person2: + takes_up_csfp_if_eligible: true age: 68 ssi: 10_800 receives_ssi: false msp: 0 person3: + takes_up_csfp_if_eligible: true age: 35 ssi: 0 receives_ssi: false @@ -442,10 +475,12 @@ input: people: person2: + takes_up_csfp_if_eligible: true age: 68 receives_ssi: false msp: 0 person3: + takes_up_csfp_if_eligible: true age: 35 receives_ssi: false msp: 0 @@ -479,6 +514,7 @@ - name: Case 16, single senior with reported SSI receipt qualifies in a post-plan year. period: 2026 input: + takes_up_csfp_if_eligible: true age: 68 school_meal_fpg_ratio: 2 state_code: KS diff --git a/policyengine_us/tests/policy/baseline/gov/usda/csfp/commodity_supplemental_food_program.yaml b/policyengine_us/tests/policy/baseline/gov/usda/csfp/commodity_supplemental_food_program.yaml index 83a70af38a5..30ed3c48650 100644 --- a/policyengine_us/tests/policy/baseline/gov/usda/csfp/commodity_supplemental_food_program.yaml +++ b/policyengine_us/tests/policy/baseline/gov/usda/csfp/commodity_supplemental_food_program.yaml @@ -1,6 +1,7 @@ - name: Age ineligible period: 2019 input: + takes_up_csfp_if_eligible: true school_meal_fpg_ratio: 1.3 age: 59 output: @@ -9,6 +10,7 @@ - name: Income ineligible period: 2019 input: + takes_up_csfp_if_eligible: true school_meal_fpg_ratio: 1.31 age: 60 output: @@ -17,6 +19,7 @@ - name: Eligible period: 2019 input: + takes_up_csfp_if_eligible: true school_meal_fpg_ratio: 1.30 age: 60 output: @@ -25,6 +28,7 @@ - name: Case 4, eligible in 2024. period: 2024 input: + takes_up_csfp_if_eligible: true school_meal_fpg_ratio: 1.30 age: 60 output: @@ -33,6 +37,7 @@ - name: Case 5, eligible in 2025 with updated amount. period: 2025 input: + takes_up_csfp_if_eligible: true school_meal_fpg_ratio: 1.50 age: 60 output: @@ -41,6 +46,7 @@ - name: Case 6, eligible in 2026 with updated amount. period: 2026 input: + takes_up_csfp_if_eligible: true school_meal_fpg_ratio: 1.50 age: 60 output: diff --git a/policyengine_us/tests/policy/baseline/gov/usda/csfp/integration.yaml b/policyengine_us/tests/policy/baseline/gov/usda/csfp/integration.yaml index 8a17e637b99..ffda0e2fc50 100644 --- a/policyengine_us/tests/policy/baseline/gov/usda/csfp/integration.yaml +++ b/policyengine_us/tests/policy/baseline/gov/usda/csfp/integration.yaml @@ -1,6 +1,7 @@ - name: Income integration test ineligible period: 2019 input: + takes_up_csfp_if_eligible: true employment_income: 3_248 self_employment_income: 3_248 rental_income: 3_248 @@ -13,6 +14,7 @@ - name: Income integration test eligible period: 2019 input: + takes_up_csfp_if_eligible: true employment_income: 3_247 self_employment_income: 3_247 rental_income: 3_247 @@ -25,6 +27,7 @@ - name: Child support received counts toward CSFP income, pushing over the limit period: 2026 input: + takes_up_csfp_if_eligible: true employment_income: 21_600 child_support_received: 3_000 age: 62 @@ -34,6 +37,7 @@ - name: Same earnings without child support stay under the limit period: 2026 input: + takes_up_csfp_if_eligible: true employment_income: 21_600 age: 62 output: diff --git a/policyengine_us/tests/policy/baseline/gov/usda/csfp/takes_up_csfp_if_eligible.yaml b/policyengine_us/tests/policy/baseline/gov/usda/csfp/takes_up_csfp_if_eligible.yaml new file mode 100644 index 00000000000..c2187a4138e --- /dev/null +++ b/policyengine_us/tests/policy/baseline/gov/usda/csfp/takes_up_csfp_if_eligible.yaml @@ -0,0 +1,39 @@ +- name: CSFP pays only eligible people who take it up + period: 2025 + input: + commodity_supplemental_food_program_eligible: [true, true, false, false] + takes_up_csfp_if_eligible: [true, false, true, false] + output: + # $601 times eligibility times take-up gives [601, 0, 0, 0]. + commodity_supplemental_food_program: [601, 0, 0, 0] + +- name: CSFP requires an explicit take-up input + period: 2025 + input: + commodity_supplemental_food_program_eligible: true + output: + takes_up_csfp_if_eligible: false + # $601 times the default false take-up flag gives $0. + commodity_supplemental_food_program: 0 + +- name: Declining CSFP leaves eligibility unchanged + period: 2025 + input: + age: 60 + school_meal_fpg_ratio: 1.50 + takes_up_csfp_if_eligible: false + output: + commodity_supplemental_food_program_eligible: true + # $601 times false gives $0 despite eligibility. + commodity_supplemental_food_program: 0 + +- name: Taking up CSFP does not override age eligibility + period: 2025 + input: + age: 59 + school_meal_fpg_ratio: 1.50 + takes_up_csfp_if_eligible: true + output: + commodity_supplemental_food_program_eligible: false + # An ineligible person receives $0 even when take-up equals true. + commodity_supplemental_food_program: 0 diff --git a/policyengine_us/variables/gov/usda/csfp/commodity_supplemental_food_program.py b/policyengine_us/variables/gov/usda/csfp/commodity_supplemental_food_program.py index 47332e69c31..1aae80c8f4a 100644 --- a/policyengine_us/variables/gov/usda/csfp/commodity_supplemental_food_program.py +++ b/policyengine_us/variables/gov/usda/csfp/commodity_supplemental_food_program.py @@ -8,4 +8,8 @@ class commodity_supplemental_food_program(Variable): definition_period = YEAR label = "Commodity Supplemental Food Program" defined_for = "commodity_supplemental_food_program_eligible" - adds = ["gov.usda.csfp.amount"] + + def formula(person, period, parameters): + amount = parameters(period).gov.usda.csfp.amount + takes_up = person("takes_up_csfp_if_eligible", period) + return amount * takes_up diff --git a/policyengine_us/variables/gov/usda/csfp/takes_up_csfp_if_eligible.py b/policyengine_us/variables/gov/usda/csfp/takes_up_csfp_if_eligible.py new file mode 100644 index 00000000000..cef7da9c579 --- /dev/null +++ b/policyengine_us/variables/gov/usda/csfp/takes_up_csfp_if_eligible.py @@ -0,0 +1,17 @@ +from policyengine_us.model_api import * + + +class takes_up_csfp_if_eligible(Variable): + value_type = bool + entity = Person + label = "Takes up the Commodity Supplemental Food Program if eligible" + documentation = ( + "Whether this person receives CSFP when eligible. Set this annual input " + "during data construction or in a household calculation. It defaults " + "to false; setting it to true pays the modeled annual amount when " + "eligible. The input does not determine eligibility or enforce the " + "caseload limits in 7 CFR 247.11." + ) + reference = "https://www.govinfo.gov/content/pkg/CFR-2025-title7-vol4/pdf/CFR-2025-title7-vol4-sec247-10.pdf" + definition_period = YEAR + default_value = False From 088e677bfb32190e9d65b7e3ab6b8b685241d3e4 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sat, 14 Nov 2026 23:33:34 -0500 Subject: [PATCH 2/3] Preserve CSFP payments when take-up is omitted Co-Authored-By: Claude Opus 5.5 --- changelog.d/csfp-take-up-input.added.md | 1 + changelog.d/csfp-take-up-input.breaking.md | 1 - .../tests/core/test_csfp_takeup_invariants.py | 6 ++-- .../gov/states/ks/dcf/csfp/integration.yaml | 36 ------------------- .../usda/csfp/takes_up_csfp_if_eligible.yaml | 8 ++--- .../usda/csfp/takes_up_csfp_if_eligible.py | 8 ++--- 6 files changed, 12 insertions(+), 48 deletions(-) create mode 100644 changelog.d/csfp-take-up-input.added.md delete mode 100644 changelog.d/csfp-take-up-input.breaking.md diff --git a/changelog.d/csfp-take-up-input.added.md b/changelog.d/csfp-take-up-input.added.md new file mode 100644 index 00000000000..33a20fa754d --- /dev/null +++ b/changelog.d/csfp-take-up-input.added.md @@ -0,0 +1 @@ +Add an annual CSFP take-up input that defaults to true and lets callers decline payments without changing eligibility. diff --git a/changelog.d/csfp-take-up-input.breaking.md b/changelog.d/csfp-take-up-input.breaking.md deleted file mode 100644 index db842901c7c..00000000000 --- a/changelog.d/csfp-take-up-input.breaking.md +++ /dev/null @@ -1 +0,0 @@ -Added an annual person input for CSFP take-up that defaults to false and requires explicit take-up for payments. diff --git a/policyengine_us/tests/core/test_csfp_takeup_invariants.py b/policyengine_us/tests/core/test_csfp_takeup_invariants.py index ebc86436fd8..8fa0ce1b73e 100644 --- a/policyengine_us/tests/core/test_csfp_takeup_invariants.py +++ b/policyengine_us/tests/core/test_csfp_takeup_invariants.py @@ -3,7 +3,7 @@ YAML covers fixed policy cases. With explicit flags for each year, Hypothesis checks that changing one person's input changes only their payment for that year. Each example -also compares all-true take-up with the payment before the take-up gate and +also compares default and all-true take-up with the payment before the gate and recomputes eligibility after each change to detect any take-up dependency. """ @@ -100,8 +100,8 @@ def test_csfp_takeup_invariants(drawn, changed_year): assert eligibility_before[year][0] assert not eligibility_before[year][1:3].any() old_payments[year] = eligibility_before[year] * amount - assert not np.asarray(simulation.calculate(TAKEUP, year)).any() - np.testing.assert_array_equal(default_benefit, np.zeros(len(rows))) + assert np.asarray(simulation.calculate(TAKEUP, year)).all() + np.testing.assert_array_equal(default_benefit, old_payments[year]) for year in YEARS: amount = simulation.tax_benefit_system.parameters(year).gov.usda.csfp.amount diff --git a/policyengine_us/tests/policy/baseline/gov/states/ks/dcf/csfp/integration.yaml b/policyengine_us/tests/policy/baseline/gov/states/ks/dcf/csfp/integration.yaml index 6b645c54a2b..a217c0a9ef9 100644 --- a/policyengine_us/tests/policy/baseline/gov/states/ks/dcf/csfp/integration.yaml +++ b/policyengine_us/tests/policy/baseline/gov/states/ks/dcf/csfp/integration.yaml @@ -9,25 +9,21 @@ input: people: person1: - takes_up_csfp_if_eligible: true age: 60 ssi: 1_200 receives_ssi: false msp: 0 person2: - takes_up_csfp_if_eligible: true age: 68 ssi: 0 receives_ssi: false msp: 0 person3: - takes_up_csfp_if_eligible: true age: 35 ssi: 1_200 receives_ssi: false msp: 0 person4: - takes_up_csfp_if_eligible: true age: 70 ssi: 0 receives_ssi: false @@ -60,25 +56,21 @@ input: people: person1: - takes_up_csfp_if_eligible: true age: 60 ssi: 0 receives_ssi: true msp: 0 person2: - takes_up_csfp_if_eligible: true age: 68 ssi: 0 receives_ssi: false msp: 0 person3: - takes_up_csfp_if_eligible: true age: 35 ssi: 0 receives_ssi: true msp: 0 person4: - takes_up_csfp_if_eligible: true age: 70 ssi: 0 receives_ssi: false @@ -111,25 +103,21 @@ input: people: person1: - takes_up_csfp_if_eligible: true age: 60 ssi: 0 receives_ssi: false msp: 0 person2: - takes_up_csfp_if_eligible: true age: 68 ssi: 0 receives_ssi: false msp: 0 person3: - takes_up_csfp_if_eligible: true age: 35 ssi: 0 receives_ssi: false msp: 0 person4: - takes_up_csfp_if_eligible: true age: 70 ssi: 0 receives_ssi: false @@ -162,25 +150,21 @@ input: people: person1: - takes_up_csfp_if_eligible: true age: 60 ssi: 0 receives_ssi: false msp: 0 person2: - takes_up_csfp_if_eligible: true age: 68 ssi: 0 receives_ssi: false msp: 0 person3: - takes_up_csfp_if_eligible: true age: 35 ssi: 0 receives_ssi: false msp: 0 person4: - takes_up_csfp_if_eligible: true age: 70 ssi: 0 receives_ssi: false @@ -213,25 +197,21 @@ input: people: person1: - takes_up_csfp_if_eligible: true age: 60 ssi: 0 receives_ssi: false msp: 0 person2: - takes_up_csfp_if_eligible: true age: 68 ssi: 0 receives_ssi: false msp: 0 person3: - takes_up_csfp_if_eligible: true age: 35 ssi: 0 receives_ssi: false msp: 0 person4: - takes_up_csfp_if_eligible: true age: 70 ssi: 0 receives_ssi: false @@ -264,25 +244,21 @@ input: people: person1: - takes_up_csfp_if_eligible: true age: 60 ssi: 0 receives_ssi: false msp: 1_200 person2: - takes_up_csfp_if_eligible: true age: 68 ssi: 0 receives_ssi: false msp: 0 person3: - takes_up_csfp_if_eligible: true age: 35 ssi: 0 receives_ssi: false msp: 1_200 person4: - takes_up_csfp_if_eligible: true age: 70 ssi: 0 receives_ssi: false @@ -313,7 +289,6 @@ - name: Case 7, income at the limit qualifies without program receipt. period: 2026 input: - takes_up_csfp_if_eligible: true age: 60 school_meal_fpg_ratio: 1.5 state_code: KS @@ -331,7 +306,6 @@ - name: Case 8, income above the limit fails without program receipt. period: 2026 input: - takes_up_csfp_if_eligible: true age: 68 school_meal_fpg_ratio: 1.51 state_code: KS @@ -349,7 +323,6 @@ - name: Case 9, categorical income eligibility does not waive the county gate. period: 2026 input: - takes_up_csfp_if_eligible: true age: 68 school_meal_fpg_ratio: 2 state_code: KS @@ -367,7 +340,6 @@ - name: Case 10, categorical income eligibility does not waive minimum age. period: 2026 input: - takes_up_csfp_if_eligible: true age: 59 school_meal_fpg_ratio: 2 state_code: KS @@ -385,7 +357,6 @@ - name: Case 11, Kansas categorical option does not apply to other states. period: 2026 input: - takes_up_csfp_if_eligible: true age: 68 school_meal_fpg_ratio: 2 state_code: MO @@ -403,7 +374,6 @@ - name: Case 12, categorical income bypass is not backdated before the state plan. period: 2024 input: - takes_up_csfp_if_eligible: true age: 68 school_meal_fpg_ratio: 2 state_code: KS @@ -421,7 +391,6 @@ - name: Case 13, categorical income bypass applies in the state plan year. period: 2025 input: - takes_up_csfp_if_eligible: true age: 68 school_meal_fpg_ratio: 2 state_code: KS @@ -441,13 +410,11 @@ input: people: person2: - takes_up_csfp_if_eligible: true age: 68 ssi: 10_800 receives_ssi: false msp: 0 person3: - takes_up_csfp_if_eligible: true age: 35 ssi: 0 receives_ssi: false @@ -475,12 +442,10 @@ input: people: person2: - takes_up_csfp_if_eligible: true age: 68 receives_ssi: false msp: 0 person3: - takes_up_csfp_if_eligible: true age: 35 receives_ssi: false msp: 0 @@ -514,7 +479,6 @@ - name: Case 16, single senior with reported SSI receipt qualifies in a post-plan year. period: 2026 input: - takes_up_csfp_if_eligible: true age: 68 school_meal_fpg_ratio: 2 state_code: KS diff --git a/policyengine_us/tests/policy/baseline/gov/usda/csfp/takes_up_csfp_if_eligible.yaml b/policyengine_us/tests/policy/baseline/gov/usda/csfp/takes_up_csfp_if_eligible.yaml index c2187a4138e..a0393bc007c 100644 --- a/policyengine_us/tests/policy/baseline/gov/usda/csfp/takes_up_csfp_if_eligible.yaml +++ b/policyengine_us/tests/policy/baseline/gov/usda/csfp/takes_up_csfp_if_eligible.yaml @@ -7,14 +7,14 @@ # $601 times eligibility times take-up gives [601, 0, 0, 0]. commodity_supplemental_food_program: [601, 0, 0, 0] -- name: CSFP requires an explicit take-up input +- name: CSFP preserves payments when take-up is omitted period: 2025 input: commodity_supplemental_food_program_eligible: true output: - takes_up_csfp_if_eligible: false - # $601 times the default false take-up flag gives $0. - commodity_supplemental_food_program: 0 + takes_up_csfp_if_eligible: true + # $601 times the default true take-up flag gives $601. + commodity_supplemental_food_program: 601 - name: Declining CSFP leaves eligibility unchanged period: 2025 diff --git a/policyengine_us/variables/gov/usda/csfp/takes_up_csfp_if_eligible.py b/policyengine_us/variables/gov/usda/csfp/takes_up_csfp_if_eligible.py index cef7da9c579..93b38bea548 100644 --- a/policyengine_us/variables/gov/usda/csfp/takes_up_csfp_if_eligible.py +++ b/policyengine_us/variables/gov/usda/csfp/takes_up_csfp_if_eligible.py @@ -8,10 +8,10 @@ class takes_up_csfp_if_eligible(Variable): documentation = ( "Whether this person receives CSFP when eligible. Set this annual input " "during data construction or in a household calculation. It defaults " - "to false; setting it to true pays the modeled annual amount when " - "eligible. The input does not determine eligibility or enforce the " + "to true to preserve payments when omitted. Set it to false to decline " + "payments. The input does not determine eligibility or enforce the " "caseload limits in 7 CFR 247.11." ) - reference = "https://www.govinfo.gov/content/pkg/CFR-2025-title7-vol4/pdf/CFR-2025-title7-vol4-sec247-10.pdf" + reference = "https://www.govinfo.gov/content/pkg/CFR-2025-title7-vol4/pdf/CFR-2025-title7-vol4-sec247-11.pdf#page=1" definition_period = YEAR - default_value = False + default_value = True From 69cde2a8fce8c0980c122fb1e182e64863812580 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 16 Nov 2026 15:07:22 -0500 Subject: [PATCH 3/3] Set CSFP income in the take-up tests After #10873, CSFP eligibility divides csfp_countable_income by spm_unit_fpg, and an input of school_meal_fpg_ratio no longer reaches it. Two take-up cases and the property test still set that ratio. The property test's third anchor, a 70-year-old with a ratio of 100, then qualifies on computed income, which fails the test's check that the anchor stays ineligible. Set csfp_countable_income and spm_unit_fpg in place of the ratio. In the property test, each person's income equals the drawn ratio times a 10,000 guideline, so each person stays on the same side of the limit. The two YAML cases set 15,000 against 10,000, the 2025 limit of 1.5, and keep their expected outputs. Co-Authored-By: Claude Opus 5.5 --- .../tests/core/test_csfp_takeup_invariants.py | 11 ++++++++--- .../gov/usda/csfp/takes_up_csfp_if_eligible.yaml | 10 ++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/policyengine_us/tests/core/test_csfp_takeup_invariants.py b/policyengine_us/tests/core/test_csfp_takeup_invariants.py index 8fa0ce1b73e..39c3e1b11bd 100644 --- a/policyengine_us/tests/core/test_csfp_takeup_invariants.py +++ b/policyengine_us/tests/core/test_csfp_takeup_invariants.py @@ -17,6 +17,8 @@ BENEFIT = "commodity_supplemental_food_program" ELIGIBILITY = "commodity_supplemental_food_program_eligible" TAKEUP = "takes_up_csfp_if_eligible" +# Each SPM unit's poverty guideline; income equals the drawn ratio times it. +GUIDELINE = 10_000 people = st.tuples( st.integers(0, 100), @@ -41,9 +43,12 @@ def _simulation(rows): } for name, units in groups.items(): units[f"{name}_{i}"] = {"members": [person]} - groups["spm_units"][f"spm_units_{i}"]["school_meal_fpg_ratio"] = { - year: ratio for year in YEARS - } + # Eligibility divides csfp_countable_income by spm_unit_fpg, so a ratio + # of 1.3 gives 13,000 / 10,000 = 1.3 and the anchor's 100.0 gives + # 1,000,000 / 10,000 = 100. + spm_unit = groups["spm_units"][f"spm_units_{i}"] + spm_unit["csfp_countable_income"] = {year: ratio * GUIDELINE for year in YEARS} + spm_unit["spm_unit_fpg"] = {year: GUIDELINE for year in YEARS} # Share a household so a household-wide take-up gate would fail. household = { "members": list(persons), diff --git a/policyengine_us/tests/policy/baseline/gov/usda/csfp/takes_up_csfp_if_eligible.yaml b/policyengine_us/tests/policy/baseline/gov/usda/csfp/takes_up_csfp_if_eligible.yaml index a0393bc007c..054ccba1901 100644 --- a/policyengine_us/tests/policy/baseline/gov/usda/csfp/takes_up_csfp_if_eligible.yaml +++ b/policyengine_us/tests/policy/baseline/gov/usda/csfp/takes_up_csfp_if_eligible.yaml @@ -20,9 +20,12 @@ period: 2025 input: age: 60 - school_meal_fpg_ratio: 1.50 + csfp_countable_income: 15_000 + spm_unit_fpg: 10_000 takes_up_csfp_if_eligible: false output: + # Age 60 meets the minimum of 60, and 15,000 / 10,000 = 1.5 meets the + # 2025 limit of 1.5. commodity_supplemental_food_program_eligible: true # $601 times false gives $0 despite eligibility. commodity_supplemental_food_program: 0 @@ -31,9 +34,12 @@ period: 2025 input: age: 59 - school_meal_fpg_ratio: 1.50 + csfp_countable_income: 15_000 + spm_unit_fpg: 10_000 takes_up_csfp_if_eligible: true output: + # 15,000 / 10,000 = 1.5 meets the 2025 limit of 1.5, and age 59 falls + # short of the minimum of 60. commodity_supplemental_food_program_eligible: false # An ineligible person receives $0 even when take-up equals true. commodity_supplemental_food_program: 0