Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions packages/populace-build/src/populace/build/us/fiscal_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,11 @@ def _uprate_cross_period_eitc_decompositions(
continue
kind = _eitc_total_kind(spec)
source_period = spec.metadata.get("source_period", "")
target_total = target_totals.get(kind)
target_total = target_totals.get(kind or "")
source_total = source_totals.get((kind, source_period))
if target_total is None or source_total in (None, 0):
continue
factor = target_total / source_total
factor = target_total.value / source_total
specs.append(
replace(
spec,
Expand All @@ -702,22 +702,45 @@ def _uprate_cross_period_eitc_decompositions(
"uprating_index": _eitc_uprating_index(kind),
"uprating_from_period": source_period,
"uprating_to_period": str(spec.period),
"uprating_index_source_period": target_total.source_period,
"uprating_index_source_record_id": target_total.source_record_id,
"uprating_factor": _format_float(factor),
},
)
)
return TargetRegistry(specs, country=registry.country)


def _eitc_active_totals(registry: TargetRegistry) -> dict[str, float]:
totals: dict[str, float] = {}
@dataclass(frozen=True)
class _EitcActiveTotal:
value: float
source_period: str
source_record_id: str
period_key: tuple[int, int, str]


def _eitc_active_totals(registry: TargetRegistry) -> dict[str, _EitcActiveTotal]:
totals: dict[str, _EitcActiveTotal] = {}
for spec in registry.specs:
kind = _eitc_total_kind(spec)
if kind is None:
continue
if spec.metadata.get("target_role") not in _eitc_total_roles(kind):
continue
totals[kind] = spec.value
source_period = spec.metadata.get("source_period", "")
candidate = _EitcActiveTotal(
value=spec.value,
source_period=source_period,
source_record_id=spec.metadata.get("ledger_source_record_id", spec.name),
period_key=_period_key_from_value(source_period),
)
current = totals.get(kind)
if current is None or _prefer_candidate(
candidate.period_key,
current.period_key,
target_period_key=_period_key_from_value(spec.period),
):
totals[kind] = candidate
return totals


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is a pinned Populace-side copy of the Ledger source coverage contract
merged in ``PolicyEngine/ledger-data`` commit
``4fee6d0ac90b7b58257d025db03ed905fb08fca7``. Ledger owns source packages;
``e2fc882c35f9203c788a7159e7b08b0b5e5ceb58``. Ledger owns source packages;
Populace owns whether source families are active hard targets, validation-only
diagnostics, or explicit source gaps in a release profile.
"""
Expand Down Expand Up @@ -30,7 +30,7 @@
"validation_only_family_ids",
]

LEDGER_US_SOURCE_COVERAGE_CONTRACT_COMMIT = "4fee6d0ac90b7b58257d025db03ed905fb08fca7"
LEDGER_US_SOURCE_COVERAGE_CONTRACT_COMMIT = "e2fc882c35f9203c788a7159e7b08b0b5e5ceb58"

CoverageRole = Literal["hard_target", "validation_only", "source_gap"]

Expand Down Expand Up @@ -82,6 +82,7 @@ class SourceCoverageEntry:
"soi-table-2-1",
"soi-table-2-5",
"soi-table-2-5-eitc-agi-children-2023",
"soi-filing-season-week47-2024-eitc-total",
"soi-table-4-3",
"soi-state-2022",
"soi-historic-table-2",
Expand Down
19 changes: 11 additions & 8 deletions packages/populace-build/tests/test_us_fiscal_refresh_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ def diagnostic(name, target, final_estimate):
17_100_000.0,
),
diagnostic(
"irs_soi.ty2022.historic_table_2.us.all.eitc_amount",
59_204_610_000.0,
63_000_000_000.0,
"irs_soi.ty2024.filing_season_week47.eitc_all_returns."
"earned_income_credit.total_earned_income_credit_amount",
69_041_649_000.0,
70_000_000_000.0,
),
diagnostic(
"irs_soi.ty2022.historic_table_2.us.all.eitc_claims",
23_692_200.0,
"irs_soi.ty2024.filing_season_week47.eitc_all_returns."
"earned_income_credit.total_earned_income_credit_returns",
23_837_149.0,
23_800_000.0,
),
diagnostic(
Expand Down Expand Up @@ -1136,10 +1138,11 @@ def test_release_gate_failures_reject_bad_national_credit_and_ss_fits() -> None:
43_994_700.0,
),
(
"irs_soi.ty2022.historic_table_2.us.all.eitc_amount",
"irs_soi.ty2024.filing_season_week47.eitc_all_returns."
"earned_income_credit.total_earned_income_credit_amount",
"Earned Income Tax Credit amount",
59_204_610_000.0,
70_208_900_000.0,
69_041_649_000.0,
83_000_000_000.0,
),
(
"irs_soi.ty2022.historic_table_2.us.all.premium_tax_credit_amount",
Expand Down
127 changes: 120 additions & 7 deletions packages/populace-build/tests/test_us_fiscal_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,92 @@ def test_cross_period_soi_eitc_decomposition_uprates_to_active_total() -> None:
assert scaled_child_total.metadata["uprating_factor"] == "1.2"


def test_cross_period_soi_eitc_decomposition_uses_latest_source_backed_total() -> None:
source_record_id = (
"irs_soi.ty2023.table_2_5.eitc_by_agi_children.one_qualifying_child."
"25k_to_30k.eitc_total"
)
registry = compile_us_fiscal_target_registry(
[
*packaged_reference_facts(),
_soi_eitc_total_fact(
2023,
measure_id="total_earned_income_credit_amount",
value=66_270_000_000,
),
*_soi_eitc_child_total_facts(
2023,
measure_id="eitc_total",
values={"all_qualifying_children": 66_270_000_000},
),
_soi_eitc_filing_season_total_fact(
measure_id="total_earned_income_credit_amount",
value=69_041_649_000,
),
_soi_eitc_child_fact(
2023,
source_record_id=source_record_id,
measure_id="eitc_total",
value=66_270_000,
),
],
target_period=2024,
)

spec = {spec.name: spec for spec in registry.specs}[source_record_id]
assert spec.value == 69_041_649
assert spec.metadata["uprating_index"] == "total_eitc_amount"
assert spec.metadata["uprating_index_source_period"] == "2024"
assert spec.metadata["uprating_index_source_record_id"] == (
"irs_soi.ty2024.filing_season_week47.eitc_all_returns."
"earned_income_credit.total_earned_income_credit_amount"
)
assert spec.metadata["uprating_factor"] == "1.04182358533273"


def test_cross_period_soi_eitc_returns_uprate_to_filing_season_total() -> None:
source_record_id = (
"irs_soi.ty2023.table_2_5.eitc_by_agi_children.one_qualifying_child."
"25k_to_30k.eitc_returns"
)
registry = compile_us_fiscal_target_registry(
[
*packaged_reference_facts(),
_soi_eitc_total_fact(
2023,
measure_id="total_earned_income_credit_returns",
value=24_439_936,
),
*_soi_eitc_child_total_facts(
2023,
measure_id="eitc_returns",
values={"all_qualifying_children": 24_439_936},
),
_soi_eitc_filing_season_total_fact(
measure_id="total_earned_income_credit_returns",
value=23_837_149,
),
_soi_eitc_child_fact(
2023,
source_record_id=source_record_id,
measure_id="eitc_returns",
value=24_439.936,
),
],
target_period=2024,
)

spec = {spec.name: spec for spec in registry.specs}[source_record_id]
assert spec.value == 23_837.149
assert spec.metadata["uprating_index"] == "total_eitc_returns"
assert spec.metadata["uprating_index_source_period"] == "2024"
assert spec.metadata["uprating_index_source_record_id"] == (
"irs_soi.ty2024.filing_season_week47.eitc_all_returns."
"earned_income_credit.total_earned_income_credit_returns"
)
assert spec.metadata["uprating_factor"] == "0.975335982876551"


def test_soi_eitc_layout_child_count_filter_reaches_compiled_target() -> None:
source_record_id = (
"irs_soi.ty2024.state_2022.us.eitc_three_or_more_children_returns."
Expand Down Expand Up @@ -1621,24 +1707,51 @@ def _soi_eitc_total_fact(
)


def _soi_eitc_filing_season_total_fact(
*,
measure_id: str,
value: float,
) -> dict[str, object]:
source_record_id = (
"irs_soi.ty2024.filing_season_week47.eitc_all_returns."
f"earned_income_credit.{measure_id}"
)
suffix = "count" if measure_id.endswith("_returns") else "amount"
return _dynamic_ledger_fact(
source_record_id=source_record_id,
source_name="irs_soi",
measure_id=measure_id,
value=value,
period_value=2024,
dimensions={"income_range": "all", "filing_status": "all"},
layout_record_set_id=(
f"irs_soi.ty2024.filing_season_week47.eitc_all_returns.{suffix}"
),
groupby_dimension="irs_soi.filing_season_line",
groupby_value_id="earned_income_credit",
)


def _soi_eitc_child_total_facts(
source_period: int,
*,
measure_id: str,
values: dict[str, float] | None = None,
) -> list[dict[str, object]]:
values = {
"no_qualifying_children": 100,
"one_qualifying_child": 200,
"two_qualifying_children": 300,
"three_or_more_qualifying_children": 400,
}
if measure_id == "eitc_returns":
if values is None and measure_id == "eitc_returns":
values = {
"no_qualifying_children": 5,
"one_qualifying_child": 10,
"two_qualifying_children": 15,
"three_or_more_qualifying_children": 20,
}
elif values is None:
values = {
"no_qualifying_children": 100,
"one_qualifying_child": 200,
"two_qualifying_children": 300,
"three_or_more_qualifying_children": 400,
}
return [
_dynamic_ledger_fact(
source_record_id=(
Expand Down
1 change: 1 addition & 0 deletions packages/populace-build/tests/test_us_source_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

def test_us_source_coverage_snapshot_has_expected_roles() -> None:
assert len(LEDGER_US_SOURCE_COVERAGE_CONTRACT_COMMIT) == 40
assert "soi-filing-season-week47-2024-eitc-total" in hard_target_package_aliases()
assert "ssa-ssi-table-7b1-2024" in hard_target_package_aliases()
assert "cms-aca-oep-state-level-2025" in hard_target_package_aliases()
assert "census_cps_spm" in validation_only_family_ids()
Expand Down
11 changes: 9 additions & 2 deletions tools/build_us_fiscal_refresh_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,18 @@
"max_abs_relative_error": 0.10,
},
{
"name": (f"irs_soi.ty2022.historic_table_2.us.all.eitc_amount@{PERIOD}"),
"name": (
"irs_soi.ty2024.filing_season_week47.eitc_all_returns."
f"earned_income_credit.total_earned_income_credit_amount@{PERIOD}"
),
"label": "Earned Income Tax Credit amount",
"max_abs_relative_error": 0.10,
},
{
"name": (f"irs_soi.ty2022.historic_table_2.us.all.eitc_claims@{PERIOD}"),
"name": (
"irs_soi.ty2024.filing_season_week47.eitc_all_returns."
f"earned_income_credit.total_earned_income_credit_returns@{PERIOD}"
),
"label": "Earned Income Tax Credit claims",
"max_abs_relative_error": 0.10,
},
Expand Down Expand Up @@ -187,6 +193,7 @@
"soi-table-2-1",
"soi-table-2-5",
"soi-table-2-5-eitc-agi-children-2023",
"soi-filing-season-week47-2024-eitc-total",
"soi-table-4-3",
"soi-state-2022",
"soi-historic-table-2",
Expand Down
Loading