Skip to content
Merged
1 change: 1 addition & 0 deletions changelog.d/record-la-dependent-exemption-reading.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Recorded Louisiana's 2021–2024 exemption treatment for claimable filers whose claimants meet the filing exception.
40 changes: 40 additions & 0 deletions policyengine_us/tests/code_health/test_la_source_captures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Keep Louisiana's source captures separate from interpretive notes."""

import hashlib
from pathlib import Path
import re

import pytest


CAPTURES = Path(__file__).resolve().parents[3] / "source_conflicts/sources/us-la"
# Hash each complete page's unedited pdftotext output from the official PDFs.
# Each capture records the PDF's URL, page and SHA256 separately in its header.
PAGE_SHA256 = {
"rr18-001-p2.txt": "a43f13d365031ab018df1a1ce943e667a8c32c308b652b09c4c6d8292dfdd186",
"it540-instructions-2021-p3.txt": "ccfb814f1fb72db6ac7edb8816fe1fba7497c380618710ecfbe78e837189c217",
"it540-instructions-2022-p2.txt": "3b42f352f733e59c1dabc4183b5c095b5e73802ee123bbe64138d49331ae07d0",
"it540-instructions-2023-p3.txt": "2f7cddefbcf3b9689669e2adfb8fec2377091302ecd20f99ef5244459cac8ba7",
"it540-instructions-2024-p3.txt": "13bd6a7c7ff96fe43055fc97db3ed74e55606eae24d1f9cef8fdf06b4fd84a56",
"it540-instructions-2024-p18.txt": "9c82e330bdcd2d453ea1f288c54c333e3fbab8e71013be4d50ef486c1af6a52e",
"it540-tax-table-2022-p1.txt": "8161e8611736a9518c905742c812f9e4d9722ea2fa7c032b8cb5a11bf732741b",
"it540-tax-table-2023-p1.txt": "a65515fe9e1a8c11a2567577b67d449a5b750a5140a0861476af7cba56d55edc",
}


def test_la_captures_record_page_extraction():
for name in PAGE_SHA256:
path = CAPTURES / name
header = path.read_bytes().split(b"\n\n", 1)[0].decode()
assert re.fullmatch(
r"Source: https://dam\.ldr\.la\.gov/[^\n]+#page=(\d+)\n"
r"Pages \1-\1, text extracted with pdftotext \(poppler\), reading order\.\n"
r"PDF SHA256: [0-9a-f]{64}",
header,
), f"{path.name} must identify one official document page and its extraction"


@pytest.mark.parametrize("name, expected_sha256", PAGE_SHA256.items())
def test_la_captures_contain_complete_official_pages(name, expected_sha256):
_, body = (CAPTURES / name).read_bytes().split(b"\n\n", 1)
assert hashlib.sha256(body).hexdigest() == expected_sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
"""Check Louisiana's retained exemption reading for claimable filers.

Compare ordinary filers with claimable filers whose claimants do or do not
meet the filing exception. Each batch covers every filing status and zero
through four dependents, with fixed ages below the aged-exemption limit.
Preserve the model's joint-spouse treatment by analogy with the head; the
cited Louisiana instructions do not resolve a claimable spouse's exemption.
"""

import numpy as np
import pytest

from policyengine_us import Simulation

YEARS = (2021, 2022, 2023, 2024)
STATUSES = (
"SINGLE",
"SEPARATE",
"SURVIVING_SPOUSE",
"HEAD_OF_HOUSEHOLD",
"JOINT",
)


def _situation(year, head_age, spouse_age, child_ages):
people = {}
groups = {
name: {}
for name in (
"tax_units",
"households",
"families",
"spm_units",
"marital_units",
)
}
rows = []

def add_person(name, age, role, claimable=False, exception=False):
inputs = {
"age": age,
"is_blind": False,
"is_tax_unit_head": role == "head",
"is_tax_unit_spouse": role == "spouse",
"is_tax_unit_dependent": role == "dependent",
"claimable_as_dependent_on_another_return": claimable,
"dependent_claimant_filing_exception": exception,
}
people[name] = {variable: {year: value} for variable, value in inputs.items()}

for status in STATUSES:
variants = [
("ordinary", None, False),
("blocked_head", "head", False),
("except_head", "head", True),
]
if status == "JOINT":
# Preserve the model's spouse treatment by analogy with the head.
variants += [
("blocked_spouse", "spouse", False),
("except_spouse", "spouse", True),
]
for dependents in range(5):
for variant, claimable_role, exception in variants:
index = len(rows)
head = f"head_{index}"
add_person(
head,
head_age,
"head",
claimable_role == "head",
exception and claimable_role == "head",
)
members = [head]
couple = [head]
if status == "JOINT":
spouse = f"spouse_{index}"
add_person(
spouse,
spouse_age,
"spouse",
claimable_role == "spouse",
exception and claimable_role == "spouse",
)
members.append(spouse)
couple.append(spouse)
groups["marital_units"][f"couple_{index}"] = {"members": couple}
for child_index, age in enumerate(child_ages[:dependents]):
child = f"child_{index}_{child_index}"
add_person(child, age, "dependent")
members.append(child)
groups["marital_units"][child] = {"members": [child]}
groups["tax_units"][f"tax_unit_{index}"] = {
"members": members,
"filing_status": {year: status},
}
groups["households"][f"household_{index}"] = {
"members": members,
"state_code": {year: "LA"},
}
for group in ("families", "spm_units"):
groups[group][f"{group}_{index}"] = {"members": members}
rows.append((status, dependents, variant))
return {"people": people, **groups}, rows


@pytest.mark.parametrize("year", YEARS)
def test_la_claimable_filer_exemption_invariants(year):
situation, rows = _situation(year, 20, 20, (4, 4, 4, 4))
simulation = Simulation(situation=situation)
values = {
variable: np.asarray(simulation.calculate(variable, year))
for variable in (
"tax_unit_dependents",
"la_dependents_exemption",
"la_personal_exemption",
"la_blind_exemption",
"la_aged_exemption",
"la_exemptions",
)
}
counts = np.array([dependents for _, dependents, _ in rows])
blocked = np.array([variant.startswith("blocked") for _, _, variant in rows])
own = np.array(
[4_500 if status in ("SINGLE", "SEPARATE") else 9_000 for status, _, _ in rows]
)

np.testing.assert_array_equal(values["tax_unit_dependents"], counts)
# Filers keep $1,000 per dependent when no claimant blocks the return.
dependent_amount = np.where(blocked, 0, counts * 1_000)
np.testing.assert_array_equal(values["la_dependents_exemption"], dependent_amount)
# Claimable filers keep the personal amount for their filing status.
np.testing.assert_array_equal(values["la_personal_exemption"], own)
np.testing.assert_array_equal(values["la_blind_exemption"], 0)
np.testing.assert_array_equal(values["la_aged_exemption"], 0)
np.testing.assert_array_equal(values["la_exemptions"], own + dependent_amount)

positions = {row: index for index, row in enumerate(rows)}
for status in STATUSES:
variants = {variant for row_status, _, variant in rows if row_status == status}
for variant in variants:
indices = [positions[(status, count, variant)] for count in range(5)]
amounts = values["la_dependents_exemption"][indices]
# Adding a dependent increases an allowed exemption by $1,000.
increment = 0 if variant.startswith("blocked") else 1_000
np.testing.assert_array_equal(np.diff(amounts), increment)
assert (amounts >= 0).all()
assert (amounts <= counts[indices] * 1_000).all()
for count in range(5):
ordinary = positions[(status, count, "ordinary")]
restored = positions[(status, count, "except_head")]
np.testing.assert_array_equal(
values["la_exemptions"][restored], values["la_exemptions"][ordinary]
)
if status == "JOINT":
spouse = positions[(status, count, "except_spouse")]
np.testing.assert_array_equal(
values["la_exemptions"][spouse], values["la_exemptions"][ordinary]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
- name: 2021 claimable filer keeps personal and dependent exemptions under the filing exception
period: 2021
input:
people:
filer:
age: 20
claimable_as_dependent_on_another_return: true
dependent_claimant_filing_exception: true
is_tax_unit_head: true
is_tax_unit_spouse: false
child:
age: 4
is_tax_unit_dependent: true
tax_units:
tax_unit:
members: [filer, child]
filing_status: SINGLE
households:
household:
members: [filer, child]
state_code: LA
output:
# 2021 IT-540 instructions, PDF p. 3, Lines 6A and 6C:
# https://dam.ldr.la.gov/taxforms/IT540i(2021)%20Instructions.pdf#page=3
# RR 18-001, PDF p. 2, quotes pre-2025 R.S. 47:294(A) and (B):
# https://dam.ldr.la.gov/lawspolicies/RR%2018-001%20Personal%20Exemptions.pdf#page=2
# LDR counts the filer on Line 6A and the federal dependent on Line 6C.
# (1 filer + 1 child - 1 personal allowance) * $1,000 = $1,000.
# $4,500 personal + $1,000 dependent + $0 blind + $0 aged = $5,500.
la_personal_exemption: 4_500
la_dependents_exemption: 1_000
la_exemptions: 5_500

- name: 2022 claimable filer keeps personal and dependent exemptions under the filing exception
period: 2022
input:
people:
filer:
age: 20
claimable_as_dependent_on_another_return: true
dependent_claimant_filing_exception: true
is_tax_unit_head: true
is_tax_unit_spouse: false
child:
age: 4
is_tax_unit_dependent: true
tax_units:
tax_unit:
members: [filer, child]
filing_status: SINGLE
households:
household:
members: [filer, child]
state_code: LA
output:
# 2022 IT-540 instructions, PDF p. 2, Lines 6A and 6C:
# https://dam.ldr.la.gov/taxforms/IT540iWEB(2022)D1.pdf#page=2
# 2022 Louisiana Tax Table, PDF p. 1, single or married filing separately:
# https://dam.ldr.la.gov/taxforms/IT540(2022)%20Tax%20Table.pdf#page=1
# LDR counts the filer on Line 6A and the federal dependent on Line 6C.
# (1 filer + 1 child - 1 personal allowance) * $1,000 = $1,000.
# $4,500 personal + $1,000 dependent + $0 blind + $0 aged = $5,500.
la_personal_exemption: 4_500
la_dependents_exemption: 1_000
la_exemptions: 5_500

- name: 2023 claimable filer keeps personal and dependent exemptions under the filing exception
period: 2023
input:
people:
filer:
age: 20
claimable_as_dependent_on_another_return: true
dependent_claimant_filing_exception: true
is_tax_unit_head: true
is_tax_unit_spouse: false
child:
age: 4
is_tax_unit_dependent: true
tax_units:
tax_unit:
members: [filer, child]
filing_status: SINGLE
households:
household:
members: [filer, child]
state_code: LA
output:
# 2023 IT-540 instructions, PDF p. 3, Lines 6A and 6C:
# https://dam.ldr.la.gov/taxforms/IT540i%20WEB(2023)%20INSTRUCTIONS.pdf#page=3
# 2023 Louisiana Tax Table, PDF p. 1, single or married filing separately:
# https://dam.ldr.la.gov/taxforms/IT540(2023)%20TT.pdf#page=1
# LDR counts the filer on Line 6A and the federal dependent on Line 6C.
# (1 filer + 1 child - 1 personal allowance) * $1,000 = $1,000.
# $4,500 personal + $1,000 dependent + $0 blind + $0 aged = $5,500.
la_personal_exemption: 4_500
la_dependents_exemption: 1_000
la_exemptions: 5_500

- name: 2024 claimable filer keeps personal and dependent exemptions under the filing exception
period: 2024
input:
people:
filer:
age: 20
claimable_as_dependent_on_another_return: true
dependent_claimant_filing_exception: true
is_tax_unit_head: true
is_tax_unit_spouse: false
child:
age: 4
is_tax_unit_dependent: true
tax_units:
tax_unit:
members: [filer, child]
filing_status: SINGLE
households:
household:
members: [filer, child]
state_code: LA
output:
# 2024 IT-540 instructions, PDF pp. 3 and 18, Lines 6A/6C and single tax table:
# https://dam.ldr.la.gov/taxforms/IT540i%20WEB%20(2024)D18%20INSTRUCTIONS.pdf#page=3
# https://dam.ldr.la.gov/taxforms/IT540i%20WEB%20(2024)D18%20INSTRUCTIONS.pdf#page=18
# LDR counts the filer on Line 6A and the federal dependent on Line 6C.
# (1 filer + 1 child - 1 personal allowance) * $1,000 = $1,000.
# $4,500 personal + $1,000 dependent + $0 blind + $0 aged = $5,500.
la_personal_exemption: 4_500
la_dependents_exemption: 1_000
la_exemptions: 5_500
Loading
Loading