diff --git a/changelog.d/dependent-state-subtractions-dc-de-oh.fixed.md b/changelog.d/dependent-state-subtractions-dc-de-oh.fixed.md new file mode 100644 index 00000000000..1b6f5ad349b --- /dev/null +++ b/changelog.d/dependent-state-subtractions-dc-de-oh.fixed.md @@ -0,0 +1 @@ +Leave tax unit dependents' own income and expenses out of the DC, Delaware and Ohio subtractions on the filers' return, and their contributions out of Ohio's 529 deduction. Count the DC disability income exclusion once per return, split between the filers by their capped payments. diff --git a/policyengine_us/parameters/gov/states/oh/tax/income/deductions/filer_amounts_recorded_on_dependents.yaml b/policyengine_us/parameters/gov/states/oh/tax/income/deductions/filer_amounts_recorded_on_dependents.yaml new file mode 100644 index 00000000000..805f13c2d99 --- /dev/null +++ b/policyengine_us/parameters/gov/states/oh/tax/income/deductions/filer_amounts_recorded_on_dependents.yaml @@ -0,0 +1,16 @@ +description: Ohio deducts these medical amounts the filer paid for dependents, even when recorded on the covered dependent. Other deductions on a dependent belong on their own return. +values: + 2021-01-01: + # Premiums and medical care the taxpayer paid "for the taxpayer, the + # taxpayer's spouse, and dependents" (R.C. 5747.01(A)(10)), recorded on + # the person they covered. + - oh_unreimbursed_medical_care_expense_deduction_person +metadata: + unit: list + period: year + label: Ohio filer-paid medical deductions recorded on dependents + reference: + - title: Ohio Revised Code 5747.01(A)(10) + href: https://codes.ohio.gov/ohio-revised-code/section-5747.01 + - title: Ohio 2025 IT 1040 Instructions, Schedule of Adjustments line 44 + href: https://dam.assets.ohio.gov/image/upload/v1767095693/tax.ohio.gov/forms/ohio_individual/individual/2025/it1040-booklet.pdf#page=25 diff --git a/policyengine_us/tests/core/test_dependent_state_subtractions_invariants.py b/policyengine_us/tests/core/test_dependent_state_subtractions_invariants.py new file mode 100644 index 00000000000..0166c1e0b28 --- /dev/null +++ b/policyengine_us/tests/core/test_dependent_state_subtractions_invariants.py @@ -0,0 +1,450 @@ +"""Property tests: a dependent's own items stay off the filers' DC, Delaware +and Ohio returns, and per-return amounts are counted once. + +DC, Delaware and Ohio subtract per-person items from each person's federal +adjusted gross income and pool every member into the filer's state AGI +(dc_taxable_income_joint, de_agi_joint, oh_agi). Federal adjusted gross income +leaves out a tax unit dependent's income (irs_gross_income); the dependent +reports it, and takes these subtractions, on their own return. Each subtracted +item is the taxpayer's own: + +- DC subtracts income "included in federal gross income" or entered from the + filer's federal return (D.C. Code 47-1803.02(a)(2)(A), (E), (L), (LL); D-40 + lines 9, 10 and 13), the D-2440 disability income exclusion ((M)), one per + return with a column for you and one for your spouse, and up to $10,000 of + a disabled person's own income ((V)). +- Delaware subtracts income "to the extent included in federal adjusted gross + income" (30 Del. C. 1106(b)(4), (9), (10)) and 529 contributions made by + the individual, or by the spouses on a joint return ((b)(11)). +- Ohio deducts the taxpayer's own income and expenses (R.C. 5747.01(A)(4), + (11), (18), (23), (27), (31)), and the medical and 529 amounts the taxpayer + paid, including for dependents ((A)(9), (A)(10)). + +So for every tax unit in these states, and any income items its dependents +have (unemployment compensation, state tax refunds, U.S. government interest, +D-2440 disability payments, SSI, Pell grants, disability benefits, Ohio +section 179 add-backs, uniformed services retirement and educator expenses): + +1. DC, Delaware and Ohio AGI, taxable income and tax before credits are the + same as when the dependents have none of these items. DC units with a + disabled filer are left out: the (V) exclusion's limit on household + adjusted gross income counts every household member's income, so a + dependent's income can rightly end a filer's exclusion (the model tests + tax-unit AGI for now). +2. A dependent's dc_income_subtractions and de_subtractions are zero, and + their oh_deductions retain only their shares of the filer's medical + deduction. +3. Per-return amounts are counted once over the tax unit: + - the Ohio unreimbursed medical deduction is the members' medical expenses + over 7.5% of federal AGI; + - the DC disability exclusion is the filers' capped payments less federal + AGI over taxable Social Security plus $15,000. + +Dependents are 1 to 17, so they are qualifying children with no income test. +Amounts are whole dollars of at most $200,000. +""" + +import numpy as np +from hypothesis import HealthCheck, given, settings +from hypothesis import strategies as st + +from policyengine_us import Simulation + +YEAR = 2025 +TOLERANCE = 0.01 + +# A dependent's own items, zeroed in the twin. +OWN_ITEMS = [ + "unemployment_compensation", + "salt_refund_income", + "taxable_interest_income", + "us_govt_interest_person", + "total_disability_payments", + "ssi", + "pell_grant", + "disability_benefits", + "oh_section_179_expense_add_back", + "oh_uniformed_services_retirement_income_deduction", + "oh_educator_expense_deduction_person", + "investment_in_529_plan_indv", + "count_529_contribution_beneficiaries", +] +# The filer's amounts, recorded on whoever they were for. +FILER_ITEMS = [ + "other_medical_expenses", +] +SAME_AS_WITHOUT_DEPENDENT_ITEMS = { + "DC": [ + "dc_taxable_income_joint", + "dc_income_tax_before_credits", + ], + "DE": [ + "de_income_tax_before_non_refundable_credits_unit", + ], + "OH": [ + "oh_agi", + "oh_taxable_income", + "oh_income_tax_before_non_refundable_credits", + "oh_529_plan_deduction", + ], +} +UNIT_OUTPUTS = sorted( + {v for variables in SAME_AS_WITHOUT_DEPENDENT_ITEMS.values() for v in variables} + | { + "adjusted_gross_income", + "tax_unit_taxable_social_security", + "oh_unreimbursed_medical_care_expense_deduction", + } +) +PERSON_OUTPUTS = [ + "dc_income_subtractions", + "dc_disability_exclusion", + "de_subtractions", + "de_agi_joint", + "oh_deductions", + "oh_529_plan_deduction_person", + "oh_unreimbursed_medical_care_expense_deduction_person", + "is_tax_unit_dependent", +] + + +def amount(low, high): + return st.integers(low, high).map(float) + + +def maybe(draw, high): + """Zero half the time, so items also appear alone.""" + return draw(st.one_of(st.just(0.0), amount(0, high))) + + +@st.composite +def items(draw): + interest = maybe(draw, 20_000) + return { + "unemployment_compensation": maybe(draw, 20_000), + "salt_refund_income": maybe(draw, 5_000), + "taxable_interest_income": interest, + "us_govt_interest_person": draw(amount(0, int(interest))), + "total_disability_payments": maybe(draw, 8_000), + "ssi": maybe(draw, 10_000), + "pell_grant": maybe(draw, 7_000), + "disability_benefits": maybe(draw, 20_000), + "oh_section_179_expense_add_back": maybe(draw, 5_000), + "oh_uniformed_services_retirement_income_deduction": maybe(draw, 30_000), + "oh_educator_expense_deduction_person": maybe(draw, 300), + "other_medical_expenses": maybe(draw, 20_000), + "investment_in_529_plan_indv": maybe(draw, 5_000), + "count_529_contribution_beneficiaries": draw(st.integers(0, 2)), + } + + +@st.composite +def tax_units(draw): + state = draw(st.sampled_from(["DC", "DE", "OH"])) + n_filers = draw(st.integers(1, 2)) + filers = [ + { + "age": draw(st.integers(25, 64)), + # Low wages too, where the D-2440 exclusion applies. + "employment_income": draw(amount(0, 200_000)), + "is_permanently_and_totally_disabled": draw(st.booleans()), + **draw(items()), + } + for _ in range(n_filers) + ] + dependents = [ + { + "age": draw(st.integers(1, 17)), + "is_permanently_and_totally_disabled": draw(st.booleans()), + **draw(items()), + } + for _ in range(draw(st.integers(1, 3))) + ] + return {"state": state, "filers": filers, "dependents": dependents} + + +def without_dependent_items(unit): + zero = {name: 0.0 for name in OWN_ITEMS} + return {**unit, "dependents": [{**d, **zero} for d in unit["dependents"]]} + + +def build_situation(units): + """One tax unit per household: the head, an optional spouse and the + dependents, each dependent in a marital unit of their own.""" + people, tax_units_out, marital_units, households = {}, {}, {}, {} + for i, unit in enumerate(units): + members = [] + for j, person in enumerate(unit["filers"] + unit["dependents"]): + name = f"person_{i}_{j}" + filer = j < len(unit["filers"]) + people[name] = { + "is_tax_unit_head": {YEAR: j == 0}, + "is_tax_unit_spouse": {YEAR: j == 1 and filer}, + "is_tax_unit_dependent": {YEAR: not filer}, + **{key: {YEAR: value} for key, value in person.items()}, + } + members.append(name) + if not filer: + marital_units[f"dependent_{i}_{j}"] = {"members": [name]} + tax_units_out[f"tax_unit_{i}"] = {"members": members} + marital_units[f"filers_{i}"] = {"members": members[: len(unit["filers"])]} + households[f"household_{i}"] = { + "members": members, + "state_code": {YEAR: unit["state"]}, + } + return { + "people": people, + "tax_units": tax_units_out, + "marital_units": marital_units, + "households": households, + } + + +def calculate(units): + simulation = Simulation(situation=build_situation(units)) + unit_results = { + variable: np.asarray(simulation.calculate(variable, YEAR)) + for variable in UNIT_OUTPUTS + } + person_results = { + variable: np.asarray(simulation.calculate(variable, YEAR)) + for variable in PERSON_OUTPUTS + } + p = simulation.tax_benefit_system.parameters(YEAR).gov + return unit_results, person_results, p + + +def unit_index(units): + """The tax unit of each person, in the order build_situation adds them.""" + return np.concatenate( + [ + np.full(len(unit["filers"]) + len(unit["dependents"]), i) + for i, unit in enumerate(units) + ] + ) + + +def unit_sum(values, index, n): + return np.bincount(index, weights=values, minlength=n) + + +def person_inputs(units, name): + return np.array( + [ + person[name] + for unit in units + for person in unit["filers"] + unit["dependents"] + ] + ) + + +def check(units): + twins = [without_dependent_items(unit) for unit in units] + unit_results, person_results, p = calculate(units + twins) + n = len(units) + states = np.array([unit["state"] for unit in units]) + index = unit_index(units) + n_people = len(index) + people = {name: values[:n_people] for name, values in person_results.items()} + person_state = states[index] + dependent = people["is_tax_unit_dependent"].astype(bool) + + # 1. The same state AGI, taxable income and tax as without the + # dependents' own items, except DC units with a disabled filer, whose + # household income test counts the dependents' income. + disabled_filer = np.array( + [ + any( + filer["is_permanently_and_totally_disabled"] for filer in unit["filers"] + ) + for unit in units + ] + ) + for state, variables in SAME_AS_WITHOUT_DEPENDENT_ITEMS.items(): + in_state = (states == state) & ~((states == "DC") & disabled_filer) + for variable in variables: + np.testing.assert_allclose( + unit_results[variable][:n][in_state], + unit_results[variable][n:][in_state], + atol=TOLERANCE, + err_msg=variable, + ) + in_de = person_state == "DE" + np.testing.assert_allclose( + unit_sum(people["de_agi_joint"], index, n)[states == "DE"], + unit_sum(person_results["de_agi_joint"][n_people:], index, n)[states == "DE"], + atol=TOLERANCE, + err_msg="de_agi_joint", + ) + + # 2. Dependents' rows. + in_dc = person_state == "DC" + in_oh = person_state == "OH" + assert np.all(people["dc_income_subtractions"][dependent & in_dc] == 0) + assert np.all(people["de_subtractions"][dependent & in_de] == 0) + np.testing.assert_allclose( + people["oh_deductions"][dependent & in_oh], + people["oh_unreimbursed_medical_care_expense_deduction_person"][ + dependent & in_oh + ], + atol=TOLERANCE, + ) + + # 3. Per-return amounts counted once. + agi = unit_results["adjusted_gross_income"][:n] + is_oh = states == "OH" + filer = ~dependent + contributions = unit_sum( + person_inputs(units, "investment_in_529_plan_indv") * filer, index, n + ) + beneficiaries = unit_sum( + person_inputs(units, "count_529_contribution_beneficiaries") * filer, + index, + n, + ) + cap = p.states.oh.tax.income.deductions.plan_529_contributions.cap + expected_529 = np.minimum(contributions, cap * beneficiaries) + np.testing.assert_allclose( + unit_results["oh_529_plan_deduction"][:n][is_oh], + expected_529[is_oh], + atol=TOLERANCE, + ) + np.testing.assert_allclose( + unit_sum(people["oh_529_plan_deduction_person"], index, n)[is_oh], + expected_529[is_oh], + atol=TOLERANCE, + ) + assert np.all(people["oh_529_plan_deduction_person"][dependent & in_oh] == 0) + medical = unit_sum(person_inputs(units, "other_medical_expenses"), index, n) + oh_rate = p.states.oh.tax.income.deductions.unreimbursed_medical_care_expenses.rate + expected_medical = np.maximum(0, medical - oh_rate * agi) + np.testing.assert_allclose( + unit_sum( + people["oh_unreimbursed_medical_care_expense_deduction_person"], index, n + )[is_oh], + expected_medical[is_oh], + atol=TOLERANCE, + ) + np.testing.assert_allclose( + unit_results["oh_unreimbursed_medical_care_expense_deduction"][:n][is_oh], + expected_medical[is_oh], + atol=TOLERANCE, + ) + + is_dc = states == "DC" + d2440 = p.irs.income.disability_income_exclusion + capped = filer * np.minimum( + person_inputs(units, "total_disability_payments"), d2440.cap + ) + reduced = np.maximum( + 0, + agi - unit_results["tax_unit_taxable_social_security"][:n] - d2440.amount, + ) + expected_d2440 = np.maximum(0, unit_sum(capped, index, n) - reduced) + np.testing.assert_allclose( + unit_sum(people["dc_disability_exclusion"], index, n)[is_dc], + expected_d2440[is_dc], + atol=TOLERANCE, + ) + assert np.all(people["dc_disability_exclusion"][dependent & in_dc] == 0) + + +# A simulation's cost is mostly fixed, so each example is a batch of tax +# units and there are few examples. +@settings( + max_examples=5, + deadline=None, + derandomize=True, + suppress_health_check=[HealthCheck.too_slow, HealthCheck.data_too_large], +) +@given(st.lists(tax_units(), min_size=10, max_size=30)) +def test_dependent_items_stay_off_dc_de_and_oh_returns(units): + check(units) + + +def test_reported_examples(): + """A head with $60,000 of wages and a dependent child with their own + unemployment compensation, state tax refund, disability exclusion and + Ohio items, in each state; an Ohio household whose medical deduction used + to be given to every member; and a DC couple with a positive D-2440 + exclusion, which used to be given to every member too.""" + zero = {name: 0.0 for name in OWN_ITEMS + FILER_ITEMS} + filer = { + "age": 40, + "employment_income": 60_000.0, + "is_permanently_and_totally_disabled": False, + **zero, + } + child = { + "age": 15, + "is_permanently_and_totally_disabled": True, + **zero, + "unemployment_compensation": 10_000.0, + "salt_refund_income": 5_000.0, + "ssi": 9_000.0, + "pell_grant": 3_000.0, + "disability_benefits": 3_000.0, + "oh_section_179_expense_add_back": 3_000.0, + } + units = [ + {"state": state, "filers": [filer], "dependents": [child]} + for state in ["DC", "DE", "OH"] + ] + units.append( + { + "state": "OH", + "filers": [{**filer, "other_medical_expenses": 6_000.0}], + "dependents": [{**zero, "age": 10, "other_medical_expenses": 3_000.0}], + } + ) + units.append( + { + "state": "OH", + "filers": [ + { + **filer, + "investment_in_529_plan_indv": 6_000.0, + "count_529_contribution_beneficiaries": 1, + } + ], + "dependents": [ + { + **zero, + "age": 10, + "investment_in_529_plan_indv": 5_000.0, + "count_529_contribution_beneficiaries": 1, + } + ], + } + ) + units.append( + { + "state": "DC", + "filers": [ + { + **filer, + "employment_income": 8_000.0, + "total_disability_payments": 6_000.0, + }, + { + **filer, + "employment_income": 0.0, + "total_disability_payments": 3_000.0, + }, + ], + "dependents": [{**zero, "age": 10, "total_disability_payments": 5_000.0}], + } + ) + check(units) + unit_results, person_results, _ = calculate(units) + # DC: $60,000 less the $22,500 head of household standard deduction. + assert unit_results["dc_taxable_income_joint"][0] == 37_500 + # Ohio: 9,000 of medical expenses over 7.5% of 60,000, once. + assert unit_results["oh_unreimbursed_medical_care_expense_deduction"][3] == 4_500 + assert unit_results["oh_529_plan_deduction"][4] == 4_000 + # D-2440: line 4 is 5,200 + 3,000 (the child's payments are on the + # child's return), and line 9 is zero, as federal AGI of 8,000 is under + # $15,000. Line 10 is 8,200 for the return, shared 5,200 and 3,000. + np.testing.assert_allclose( + person_results["dc_disability_exclusion"][-3:], [5_200, 3_000, 0] + ) diff --git a/policyengine_us/tests/core/test_person_non_dep_add.py b/policyengine_us/tests/core/test_person_non_dep_add.py new file mode 100644 index 00000000000..2d04bf80d92 --- /dev/null +++ b/policyengine_us/tests/core/test_person_non_dep_add.py @@ -0,0 +1,133 @@ +import numpy as np +import pytest + +from policyengine_core.model_api import add +from policyengine_core.periods import period as make_period +from policyengine_us import Simulation +from policyengine_us.model_api import person_non_dep_add + + +YEAR = 2025 +PERIOD = make_period(YEAR) +MEDICAL = "oh_unreimbursed_medical_care_expense_deduction_person" +OWN_ITEMS = ["salt_refund_income", "taxable_interest_income"] + + +@pytest.fixture(scope="module") +def simulation(): + names = [ + "head", + "spouse", + "child", + "single", + "dependent", + "childless_head", + "childless_spouse", + ] + dependents = [False, False, True, False, True, False, False] + members = {"joint": names[:3], "single": names[3:5], "childless": names[5:]} + sim = Simulation( + situation={ + "people": { + name: { + "age": {YEAR: age}, + "is_tax_unit_head": {YEAR: i in (0, 3, 5)}, + "is_tax_unit_spouse": {YEAR: i in (1, 6)}, + "is_tax_unit_dependent": {YEAR: dependent}, + } + for i, (name, age, dependent) in enumerate( + zip(names, [45, 43, 10, 35, 7, 55, 53], dependents) + ) + }, + "tax_units": { + name: { + "members": people, + "filing_status": {YEAR: "SINGLE" if name == "single" else "JOINT"}, + } + for name, people in members.items() + }, + "marital_units": { + "joint": {"members": names[:2]}, + "child": {"members": [names[2]]}, + "single": {"members": [names[3]]}, + "dependent": {"members": [names[4]]}, + "childless": {"members": names[5:]}, + }, + "families": {name: {"members": people} for name, people in members.items()}, + "spm_units": { + name: {"members": people} for name, people in members.items() + }, + "households": { + name: {"members": people, "state_code": {YEAR: "OH"}} + for name, people in members.items() + }, + } + ) + sim.set_input("salt_refund_income", YEAR, [100, 200, 300, 400, 500, 600, 700]) + sim.set_input("taxable_interest_income", YEAR, [1, 2, 3, 4, 5, 6, 7]) + sim.set_input(MEDICAL, YEAR, [10, 20, 30, 40, 50, 60, 70]) + sim.set_input("tax_unit_social_security", YEAR, [1_000, 2_000, 3_000]) + sim.set_input("employment_income", YEAR, np.full(len(names), 2**24)) + sim.set_input("self_employment_income", YEAR, np.ones(len(names))) + sim.set_input("short_term_capital_gains", YEAR, np.full(len(names), -(2**24))) + return sim + + +def test_masks_dependents_own_amounts(simulation): + person = simulation.populations["person"] + result = person_non_dep_add(person, PERIOD, OWN_ITEMS) + np.testing.assert_array_equal(result, [101, 202, 0, 404, 0, 606, 707]) + + +def test_keeps_named_medical_amounts_on_dependents(simulation): + person = simulation.populations["person"] + result = person_non_dep_add( + person, + PERIOD, + OWN_ITEMS + [MEDICAL], + include_dependents=[MEDICAL], + ) + np.testing.assert_array_equal(result, [111, 222, 30, 444, 50, 666, 777]) + + +def test_empty_sum_preserves_person_shape_and_float32(simulation): + person = simulation.populations["person"] + result = person_non_dep_add(person, PERIOD, []) + assert result.shape == (person.count,) + assert result.dtype == np.float32 + np.testing.assert_array_equal(result, np.zeros(person.count, dtype=np.float32)) + + +@pytest.mark.parametrize("include_dependents", [(), ("tax_unit_social_security",)]) +def test_rejects_group_variables_even_when_named_as_exceptions( + simulation, include_dependents +): + with pytest.raises(ValueError, match="tax_unit_social_security"): + person_non_dep_add( + simulation.populations["person"], + PERIOD, + ["tax_unit_social_security"], + include_dependents=include_dependents, + ) + + +@pytest.mark.parametrize("variables", [[], OWN_ITEMS]) +def test_rejects_a_tax_unit_population(simulation, variables): + with pytest.raises(ValueError, match="person"): + person_non_dep_add(simulation.populations["tax_unit"], PERIOD, variables) + + +def test_matches_add_rounding_in_tax_unit_without_dependents(simulation): + person = simulation.populations["person"] + variables = [ + "employment_income", + "self_employment_income", + "short_term_capital_gains", + ] + assert not person("is_tax_unit_dependent", PERIOD)[-2:].any() + expected = add(person, PERIOD, variables)[-2:] + result = person_non_dep_add(person, PERIOD, variables)[-2:] + # float32 rounds 2**24 + 1 to 2**24 before subtracting 2**24. + np.testing.assert_array_equal(expected, np.zeros(2, dtype=np.float32)) + np.testing.assert_array_equal(result, expected) + assert result.dtype == expected.dtype == np.float32 diff --git a/policyengine_us/tests/policy/baseline/gov/states/dc/tax/income/dc_disability_exclusion.yaml b/policyengine_us/tests/policy/baseline/gov/states/dc/tax/income/dc_disability_exclusion.yaml index 911618083d2..f8d08552dc4 100644 --- a/policyengine_us/tests/policy/baseline/gov/states/dc/tax/income/dc_disability_exclusion.yaml +++ b/policyengine_us/tests/policy/baseline/gov/states/dc/tax/income/dc_disability_exclusion.yaml @@ -1,5 +1,10 @@ -- name: disability payments are over the cap,and the reduced income is positive +# Form D-2440 is one per return: line 4 adds the capped payments of you and +# your spouse, and line 10 subtracts federal AGI less taxable Social Security +# less $15,000. Each filer gets a share of the line 10 exclusion in proportion +# to their capped payments, so the return's exclusion is counted once. +- name: disability payments are over the cap, and the reduced income is positive period: 2021 + absolute_error_margin: 0.01 input: people: person1: @@ -19,7 +24,9 @@ members: [person1, person2] state_code: DC output: - dc_disability_exclusion: 200 + # Line 4: 5,200 + 4,000 = 9,200. Line 9: 30,000 - 6,000 - 15,000 = 9,000. + # Line 10: 200, split 5,200:4,000. + dc_disability_exclusion: [113.04, 86.96] - name: disability payments are over the cap, and the reduced income is negative period: 2021 @@ -42,7 +49,8 @@ members: [person1, person2] state_code: DC output: - dc_disability_exclusion: 10_400 + # Line 10: 5,200 + 5,200 = 10,400, as 20,000 - 6,000 - 15,000 < 0. + dc_disability_exclusion: [5_200, 5_200] - name: disability payments are under the cap, and the reduced income is negative period: 2021 @@ -65,4 +73,55 @@ members: [person1, person2] state_code: DC output: - dc_disability_exclusion: 7_000 + dc_disability_exclusion: [4_000, 3_000] + +- name: The exclusion is counted once in DC AGI + # Line 9: 18,000 - 15,000 = 3,000, so line 10 is 5,000 - 3,000 = 2,000. + # It used to go to every member, so a household of three subtracted 6,000. + period: 2025 + input: + people: + head: + is_tax_unit_head: true + age: 50 + employment_income: 18_000 + total_disability_payments: 5_000 + spouse: + is_tax_unit_spouse: true + age: 50 + child: + age: 10 + tax_units: + tax_unit: + members: [head, spouse, child] + households: + household: + members: [head, spouse, child] + state_code: DC + output: + dc_disability_exclusion: [2_000, 0, 0] + dc_income_subtractions: [2_000, 0, 0] + dc_agi: [16_000, 0, 0] + +- name: A dependent's disability payments are on their own return + period: 2021 + input: + people: + head: + is_tax_unit_head: true + total_disability_payments: 4_000 + child: + is_tax_unit_dependent: true + total_disability_payments: 5_000 + tax_units: + tax_unit: + members: [head, child] + adjusted_gross_income: 20_000 + tax_unit_taxable_social_security: 0 + households: + household: + members: [head, child] + state_code: DC + output: + # Line 4 is the head's 4,000. Line 9: 20,000 - 15,000 = 5,000. Line 10: 0. + dc_disability_exclusion: [0, 0] diff --git a/policyengine_us/tests/policy/baseline/gov/states/dc/tax/income/dc_income_subtractions.yaml b/policyengine_us/tests/policy/baseline/gov/states/dc/tax/income/dc_income_subtractions.yaml new file mode 100644 index 00000000000..71d1fdbeeb0 --- /dev/null +++ b/policyengine_us/tests/policy/baseline/gov/states/dc/tax/income/dc_income_subtractions.yaml @@ -0,0 +1,97 @@ +- name: A dependent's U.S. government interest is not subtracted + period: 2025 + input: + people: + head: + is_tax_unit_head: true + age: 40 + employment_income: 60_000 + us_govt_interest_person: 200 + taxable_interest_income: 200 + child: + age: 10 + us_govt_interest_person: 50_000 + taxable_interest_income: 50_000 + household: + state_code: DC + output: + dc_income_subtractions: [200, 0] + +- name: A dependent's unemployment compensation and state tax refund are not subtracted + # D-40 line 13 subtracts unemployment benefits "included on Line 4" (federal + # AGI) and line 9 takes refunds from the filer's own federal return. The + # child's are on the child's own return. + period: 2025 + input: + people: + head: + is_tax_unit_head: true + age: 40 + employment_income: 60_000 + unemployment_compensation: 1_000 + salt_refund_income: 300 + child: + age: 16 + unemployment_compensation: 10_000 + salt_refund_income: 5_000 + household: + state_code: DC + output: + dc_income_subtractions: [1_300, 0] + +- name: A dependent's persons-with-disabilities exclusion is not subtracted + # D.C. Code 47-1803.02(a)(2)(V) excludes the disabled person's own income. + # The disabled head gets the $10,000 exclusion, plus $6,200 of taxable + # Social Security Disability (D-40 line 10). The disabled child's exclusion + # would be on the child's own return. + period: 2025 + input: + people: + head: + is_tax_unit_head: true + age: 40 + employment_income: 30_000 + is_permanently_and_totally_disabled: true + social_security_disability: 12_000 + child: + is_tax_unit_dependent: true + age: 10 + is_permanently_and_totally_disabled: true + ssi: 9_000 + tax_units: + tax_unit: + members: [head, child] + households: + household: + members: [head, child] + state_code: DC + output: + dc_disabled_exclusion_subtraction: [10_000, 10_000] + dc_income_subtractions: [16_200, 0] + +- name: Without the head's disability, a disabled child gives the filer no exclusion + # Taxable income is $30,000 of wages less the $22,500 head of household + # standard deduction. Counting the child's exclusion took it to -$2,500. + period: 2025 + input: + people: + head: + is_tax_unit_head: true + age: 40 + employment_income: 30_000 + child: + is_tax_unit_dependent: true + age: 10 + is_permanently_and_totally_disabled: true + ssi: 9_000 + tax_units: + tax_unit: + members: [head, child] + households: + household: + members: [head, child] + state_code: DC + output: + dc_disabled_exclusion_subtraction: [0, 10_000] + dc_income_subtractions: [0, 0] + dc_taxable_income_joint: 7_500 diff --git a/policyengine_us/tests/policy/baseline/gov/states/de/tax/income/subtractions/de_subtractions.yaml b/policyengine_us/tests/policy/baseline/gov/states/de/tax/income/subtractions/de_subtractions.yaml new file mode 100644 index 00000000000..ffe7e728182 --- /dev/null +++ b/policyengine_us/tests/policy/baseline/gov/states/de/tax/income/subtractions/de_subtractions.yaml @@ -0,0 +1,96 @@ +- name: A dependent's U.S. government interest is not subtracted + period: 2025 + input: + people: + head: + is_tax_unit_head: true + age: 40 + employment_income: 60_000 + us_govt_interest_person: 200 + taxable_interest_income: 200 + child: + age: 10 + us_govt_interest_person: 50_000 + taxable_interest_income: 50_000 + household: + state_code: DE + output: + de_subtractions: [200, 0] + +- name: A dependent's state tax refund is not subtracted + # 30 Del. C. 1106(b)(9) subtracts a Delaware refund "to the extent included + # in federal adjusted gross income". The child's is on the child's return. + period: 2025 + input: + people: + head: + is_tax_unit_head: true + age: 40 + employment_income: 60_000 + salt_refund_income: 300 + child: + age: 16 + salt_refund_income: 5_000 + household: + state_code: DE + output: + de_subtractions: [300, 0] + +- name: A dependent's 2021 unemployment compensation is not subtracted + # 30 Del. C. 1106(b)(10): 2020 and 2021 unemployment benefits, "to the + # extent included in federal adjusted gross income". + period: 2021 + input: + people: + head: + is_tax_unit_head: true + age: 40 + employment_income: 60_000 + unemployment_compensation: 1_000 + child: + age: 16 + unemployment_compensation: 10_000 + household: + state_code: DE + output: + de_subtractions: [1_000, 0] + +- name: A dependent's 529 contribution is not subtracted + # 30 Del. C. 1106(b)(11): amounts "contributed by an individual", or by the + # spouses on a joint return. A contributor's subtraction is on their own + # return. de_529_plan_subtraction already leaves out a dependent's + # contribution, so this case passes with or without the de_subtractions + # mask. + period: 2025 + input: + people: + head: + is_tax_unit_head: true + age: 40 + employment_income: 60_000 + investment_in_529_plan_indv: 300 + child: + age: 16 + investment_in_529_plan_indv: 800 + household: + state_code: DE + output: + de_subtractions: [300, 0] + +- name: A dependent's own items leave Delaware taxable income unchanged + # Taxable income is the head's $60,000 less the $3,250 standard deduction, + # as without the child's refund. Counting the refund made it $51,750. + period: 2025 + input: + people: + head: + is_tax_unit_head: true + age: 40 + employment_income: 60_000 + child: + age: 16 + salt_refund_income: 5_000 + household: + state_code: DE + output: + de_taxable_income_joint: [56_750, 0] diff --git a/policyengine_us/tests/policy/baseline/gov/states/oh/tax/income/deductions/oh_529_plan_deduction.yaml b/policyengine_us/tests/policy/baseline/gov/states/oh/tax/income/deductions/oh_529_plan_deduction.yaml index ce44e805b23..63bb9800b56 100644 --- a/policyengine_us/tests/policy/baseline/gov/states/oh/tax/income/deductions/oh_529_plan_deduction.yaml +++ b/policyengine_us/tests/policy/baseline/gov/states/oh/tax/income/deductions/oh_529_plan_deduction.yaml @@ -7,6 +7,25 @@ output: oh_529_plan_deduction: 4_000 +- name: A dependent contributor cannot increase the filers' contribution or cap + period: 2025 + input: + people: + head: + is_tax_unit_head: true + investment_in_529_plan_indv: 6_000 + count_529_contribution_beneficiaries: 1 + child: + age: 10 + is_tax_unit_dependent: true + investment_in_529_plan_indv: 5_000 + count_529_contribution_beneficiaries: 1 + household: + state_code: OH + output: + # The filer contributed 6,000 for one beneficiary: min(6,000, 4,000). + oh_529_plan_deduction: 4_000 + - name: Two beneficiaries increases the cap period: 2021 input: diff --git a/policyengine_us/tests/policy/baseline/gov/states/oh/tax/income/deductions/oh_529_plan_deduction_person.yaml b/policyengine_us/tests/policy/baseline/gov/states/oh/tax/income/deductions/oh_529_plan_deduction_person.yaml index 8b6a6305eea..42fcb2b8b6b 100644 --- a/policyengine_us/tests/policy/baseline/gov/states/oh/tax/income/deductions/oh_529_plan_deduction_person.yaml +++ b/policyengine_us/tests/policy/baseline/gov/states/oh/tax/income/deductions/oh_529_plan_deduction_person.yaml @@ -54,3 +54,26 @@ state_code: OH output: oh_529_plan_deduction_person: [0, 0] + +- name: Filer contributions determine each share without a dependent's contribution + period: 2025 + input: + people: + head: + is_tax_unit_head: true + investment_in_529_plan_indv: 3_000 + count_529_contribution_beneficiaries: 1 + spouse: + is_tax_unit_spouse: true + investment_in_529_plan_indv: 1_000 + child: + age: 10 + is_tax_unit_dependent: true + investment_in_529_plan_indv: 5_000 + count_529_contribution_beneficiaries: 1 + household: + state_code: OH + output: + # Filer contributions total 4,000 for one beneficiary, shared 3,000:1,000. + oh_529_plan_deduction: 4_000 + oh_529_plan_deduction_person: [3_000, 1_000, 0] diff --git a/policyengine_us/tests/policy/baseline/gov/states/oh/tax/income/deductions/oh_deductions.yaml b/policyengine_us/tests/policy/baseline/gov/states/oh/tax/income/deductions/oh_deductions.yaml index 42abd0b2256..144f23061f3 100644 --- a/policyengine_us/tests/policy/baseline/gov/states/oh/tax/income/deductions/oh_deductions.yaml +++ b/policyengine_us/tests/policy/baseline/gov/states/oh/tax/income/deductions/oh_deductions.yaml @@ -20,3 +20,99 @@ # 6,000 federal AGI - 6,000 deduction = 0. Deducting the full 10,000 # would take Ohio AGI below zero. oh_agi_person: 0 + +- name: A dependent's U.S. government interest is not deducted + period: 2025 + input: + people: + head: + is_tax_unit_head: true + age: 40 + employment_income: 60_000 + us_govt_interest_person: 200 + taxable_interest_income: 200 + child: + age: 10 + us_govt_interest_person: 50_000 + taxable_interest_income: 50_000 + household: + state_code: OH + output: + oh_deductions: [200, 0] + +- name: A dependent's own income and expenses are not deducted + # Each is the dependent's own and on the dependent's own return: section 179 + # add-backs (R.C. 5747.01(A)(18)), uniformed services retired pay "received + # by the taxpayer" ((A)(23)), Pell grant amounts "included in your federal + # adjusted gross income" (2025 IT 1040 instructions, line 38), the educator + # expenses of "a taxpayer who is a qualifying Ohio educator" ((A)(31)), + # disability benefits "to the extent included in federal adjusted gross + # income" ((A)(4)) and refunds of the taxpayer's itemized deductions + # ((A)(11)(a)). + period: 2025 + input: + people: + head: + is_tax_unit_head: true + age: 40 + employment_income: 60_000 + salt_refund_income: 300 + child: + is_tax_unit_dependent: true + is_tax_unit_spouse: false + age: 19 + is_full_time_college_student: true + oh_section_179_expense_add_back: 1_000 + oh_uniformed_services_retirement_income_deduction: 2_000 + pell_grant: 3_000 + oh_educator_expense_deduction_person: 300 + disability_benefits: 4_000 + salt_refund_income: 500 + household: + state_code: OH + output: + oh_deductions: [300, 0] + +- name: Medical expenses the filer paid for a dependent are deducted once + # R.C. 5747.01(A)(10)(b): medical care "of the taxpayer, the taxpayer's + # spouse, and dependents" over 7.5% of federal AGI: 9,000 - 4,500 = 4,500. + # The tax unit's deduction used to be given to every member. + period: 2025 + input: + people: + head: + is_tax_unit_head: true + age: 40 + employment_income: 60_000 + other_medical_expenses: 6_000 + child: + age: 10 + other_medical_expenses: 3_000 + household: + state_code: OH + output: + oh_unreimbursed_medical_care_expense_deduction_person: [3_000, 1_500] + oh_unreimbursed_medical_care_expense_deduction: 4_500 + oh_deductions: [3_000, 1_500] + oh_agi: 55_500 + +- name: A dependent contributor's 529 contribution stays off the filers' return + # R.C. 5747.70 permits the taxpayer's and spouse's contributions. + period: 2025 + input: + people: + head: + is_tax_unit_head: true + age: 40 + employment_income: 60_000 + child: + age: 10 + investment_in_529_plan_indv: 1_000 + count_529_contribution_beneficiaries: 1 + household: + state_code: OH + output: + oh_529_plan_deduction: 0 + oh_529_plan_deduction_person: [0, 0] + oh_deductions: [0, 0] + oh_agi: 60_000 diff --git a/policyengine_us/tools/general.py b/policyengine_us/tools/general.py index 831784336cc..66da7abf428 100644 --- a/policyengine_us/tools/general.py +++ b/policyengine_us/tools/general.py @@ -186,6 +186,33 @@ def person_share_of_tax_unit_amount( return where(filer, filer_share, own) +def person_non_dep_add(person, period, variables, include_dependents=()): + """ + Add person-level variables for each person, leaving out dependents' own. + + Like `add` over people, for per-person amounts that are later pooled into + the filer's return. A tax unit dependent's own items belong on their own + return, as irs_gross_income leaves their income off this one, so a + dependent gets zero for every variable except those named in + `include_dependents`: the filer's amounts even when recorded on a + dependent, such as medical expenses the filer paid for them. Variables + must be person-level; `add` rejects others. + """ + if not person.entity.is_person: + raise ValueError( + f"person_non_dep_add needs a person, not a {person.entity.key}." + ) + filer = ~person("is_tax_unit_dependent", period) + total = np.zeros(person.count, dtype=np.float32) + for variable in variables: + amount = add(person, period, [variable]) + if variable in include_dependents: + total = total + amount + else: + total = total + filer * amount + return total + + def filer_share(person, period, amounts): """ Each head's or spouse's share of the tax unit's total of `amounts`. diff --git a/policyengine_us/variables/gov/states/dc/tax/income/subtractions/dc_disability_exclusion.py b/policyengine_us/variables/gov/states/dc/tax/income/subtractions/dc_disability_exclusion.py index 355a56af7c1..6a66b17ec9c 100644 --- a/policyengine_us/variables/gov/states/dc/tax/income/subtractions/dc_disability_exclusion.py +++ b/policyengine_us/variables/gov/states/dc/tax/income/subtractions/dc_disability_exclusion.py @@ -9,20 +9,33 @@ class dc_disability_exclusion(Variable): definition_period = YEAR defined_for = StateCode.DC reference = ( - "https://code.dccouncil.gov/us/dc/council/code/sections/47-1803.02#(a)(2)(M)" + "https://code.dccouncil.gov/us/dc/council/code/sections/47-1803.02#(a)(2)(M)", + "https://otr.cfo.dc.gov/sites/default/files/dc/sites/otr/publication/attachments/2022_D-2440.pdf#page=1", + "https://otr.cfo.dc.gov/sites/default/files/dc/sites/otr/publication/attachments/2025_D-2440_Form_012626.pdf#page=1", ) def formula(person, period, parameters): p = parameters(period).gov.irs.income.disability_income_exclusion tax_unit = person.tax_unit - + # Form D-2440 is one per return, with a column for you and one for + # your spouse. A dependent's disability payments are on their own + # return. + filer = ~person("is_tax_unit_dependent", period) disability_payments = person("total_disability_payments", period) - capped_disability_payments = min_(disability_payments, p.cap) + # Up to $5,200 per disabled person. + capped_disability_payments = filer * min_(disability_payments, p.cap) + # Line 4. total_capped_payments = tax_unit.sum(capped_disability_payments) - + # Lines 5 to 9. federal_agi = tax_unit("adjusted_gross_income", period) social_security_income = tax_unit("tax_unit_taxable_social_security", period) reduced_income = federal_agi - social_security_income - p.amount capped_reduced_income = max_(reduced_income, 0) - - return max_(total_capped_payments - capped_reduced_income, 0) + # Line 10. + exclusion = max_(total_capped_payments - capped_reduced_income, 0) + # dc_taxable_income_joint sums every person, so each filer gets a + # share of the return's exclusion in proportion to their payments. + share = np.zeros_like(total_capped_payments) + mask = total_capped_payments > 0 + share[mask] = capped_disability_payments[mask] / total_capped_payments[mask] + return exclusion * share diff --git a/policyengine_us/variables/gov/states/dc/tax/income/subtractions/dc_income_subtractions.py b/policyengine_us/variables/gov/states/dc/tax/income/subtractions/dc_income_subtractions.py index a8bccb24d81..5568d9b8b88 100644 --- a/policyengine_us/variables/gov/states/dc/tax/income/subtractions/dc_income_subtractions.py +++ b/policyengine_us/variables/gov/states/dc/tax/income/subtractions/dc_income_subtractions.py @@ -15,6 +15,13 @@ class dc_income_subtractions(Variable): def formula(person, period, parameters): p = parameters(period).gov.states.dc.tax.income.subtractions - total_subtractions = add(person, period, p.sources) + # Each person's DC AGI is summed into the filer's + # (dc_taxable_income_joint), so a tax unit dependent gets none of + # these. Each item is the dependent's own and belongs on their own + # return: income "included in federal gross income" or entered from + # the filer's federal return (D.C. Code 47-1803.02(a)(2)(A), (E), (L) + # and (LL); D-40 lines 9, 10 and 13), and exclusions of a disabled + # person's own income ((M), Form D-2440, and (V)). + total_subtractions = person_non_dep_add(person, period, p.sources) # Prevent negative subtractions from acting as additions return max_(0, total_subtractions) diff --git a/policyengine_us/variables/gov/states/de/tax/income/subtractions/de_subtractions.py b/policyengine_us/variables/gov/states/de/tax/income/subtractions/de_subtractions.py index 708fdab8acb..0816e6c268c 100644 --- a/policyengine_us/variables/gov/states/de/tax/income/subtractions/de_subtractions.py +++ b/policyengine_us/variables/gov/states/de/tax/income/subtractions/de_subtractions.py @@ -11,6 +11,12 @@ class de_subtractions(Variable): def formula(person, period, parameters): p = parameters(period).gov.states.de.tax.income.subtractions - total_subtractions = add(person, period, p.subtractions) + # Each person's net income is summed into the filer's (de_agi_joint), + # so a tax unit dependent gets none of these. The income items are + # subtracted "to the extent included in federal adjusted gross income" + # (30 Del. C. 1106(b)(4), (9), (10)), which leaves a dependent's income + # out, and the 529 subtraction is for amounts "contributed by an + # individual" or, on a joint return, "by the spouses" ((b)(11)). + total_subtractions = person_non_dep_add(person, period, p.subtractions) # Prevent negative subtractions from acting as additions return max_(0, total_subtractions) diff --git a/policyengine_us/variables/gov/states/oh/tax/income/deductions/529_plan/oh_529_plan_deduction.py b/policyengine_us/variables/gov/states/oh/tax/income/deductions/529_plan/oh_529_plan_deduction.py index 7589de15436..f30dff736c7 100644 --- a/policyengine_us/variables/gov/states/oh/tax/income/deductions/529_plan/oh_529_plan_deduction.py +++ b/policyengine_us/variables/gov/states/oh/tax/income/deductions/529_plan/oh_529_plan_deduction.py @@ -8,6 +8,8 @@ class oh_529_plan_deduction(Variable): unit = USD definition_period = YEAR reference = ( + "https://codes.ohio.gov/ohio-revised-code/section-5747.70", + "https://dam.assets.ohio.gov/image/upload/v1767095693/tax.ohio.gov/forms/ohio_individual/individual/2025/it1040-booklet.pdf#page=24", "https://tax.ohio.gov/static/forms/ohio_individual/individual/2021/pit-it1040-booklet.pdf#page=18", ) defined_for = StateCode.OH @@ -16,7 +18,11 @@ def formula(tax_unit, period, parameters): p = parameters( period ).gov.states.oh.tax.income.deductions.plan_529_contributions - contribution_amount = tax_unit("investment_in_529_plan", period) - beneficiaries = add(tax_unit, period, ["count_529_contribution_beneficiaries"]) + contribution_amount = tax_unit_non_dep_add( + tax_unit, period, ["investment_in_529_plan_indv"] + ) + beneficiaries = tax_unit_non_dep_add( + tax_unit, period, ["count_529_contribution_beneficiaries"] + ) cap = p.cap * beneficiaries return min_(contribution_amount, cap) diff --git a/policyengine_us/variables/gov/states/oh/tax/income/deductions/529_plan/oh_529_plan_deduction_person.py b/policyengine_us/variables/gov/states/oh/tax/income/deductions/529_plan/oh_529_plan_deduction_person.py index 8a15af9890c..f4c91b52d10 100644 --- a/policyengine_us/variables/gov/states/oh/tax/income/deductions/529_plan/oh_529_plan_deduction_person.py +++ b/policyengine_us/variables/gov/states/oh/tax/income/deductions/529_plan/oh_529_plan_deduction_person.py @@ -8,16 +8,18 @@ class oh_529_plan_deduction_person(Variable): unit = USD definition_period = YEAR reference = ( + "https://codes.ohio.gov/ohio-revised-code/section-5747.70", "https://tax.ohio.gov/static/forms/ohio_individual/individual/2021/pit-it1040-booklet.pdf#page=18", ) defined_for = StateCode.OH def formula(person, period, parameters): - # Allocating the deduction amount to each person in the tax unit based on their contribution amount - contribution_amount = person("investment_in_529_plan_indv", period) - total_contribtions = person.tax_unit.sum(contribution_amount) + # Allocate the return's deduction among the filer contributors. + filer = ~person("is_tax_unit_dependent", period) + contribution_amount = person("investment_in_529_plan_indv", period) * filer + total_contributions = person.tax_unit.sum(contribution_amount) total_deduction = person.tax_unit("oh_529_plan_deduction", period) - contributions_rate = np.zeros_like(total_contribtions) - mask = total_contribtions != 0 - contributions_rate[mask] = contribution_amount[mask] / total_contribtions[mask] + contributions_rate = np.zeros_like(total_contributions) + mask = total_contributions != 0 + contributions_rate[mask] = contribution_amount[mask] / total_contributions[mask] return contributions_rate * total_deduction diff --git a/policyengine_us/variables/gov/states/oh/tax/income/deductions/oh_deductions.py b/policyengine_us/variables/gov/states/oh/tax/income/deductions/oh_deductions.py index a1b7752db0e..d6a1d98ebf0 100644 --- a/policyengine_us/variables/gov/states/oh/tax/income/deductions/oh_deductions.py +++ b/policyengine_us/variables/gov/states/oh/tax/income/deductions/oh_deductions.py @@ -13,4 +13,16 @@ class oh_deductions(Variable): "https://cms7files1.revize.com/starkcountyoh/Document_center/Offices/Auditor/Services/Homestead%20Exemption/Ohio_Adj_Gross_Income.pdf", ) defined_for = StateCode.OH - adds = "gov.states.oh.tax.income.deductions.deductions" + + def formula(person, period, parameters): + p = parameters(period).gov.states.oh.tax.income.deductions + # Each person's Ohio AGI is summed into the filer's (oh_agi), so a tax + # unit dependent gets only the filer's amounts recorded on them, such + # as medical expenses the filer paid for them. The dependent's own + # income and expenses belong on their own return. + return person_non_dep_add( + person, + period, + p.deductions, + include_dependents=p.filer_amounts_recorded_on_dependents, + )