Skip to content
Draft
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
17 changes: 17 additions & 0 deletions changelog.d/irs-soi-ht2-us-charitable.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Add Schedule A line 14, the contributions deduction (`N19700`/`A19700`), to
the US rows of IRS SOI Historic Table 2: `soi-historic-table-2` (TY2022) and
`soi-historic-table-2-2023` (TY2023) each read `charitable_returns` and
`charitable_amount` at all 11 AGI classes, 22 facts each (each package now has
57 measures and 627 facts). The measures use the ids, concepts and labels that
Table 2.1 and the state broad packages use for the same line. The US row is the
file's total for all returns: it includes the file's other-areas and Puerto
Rico rows as well as the 50 states and DC.

The congressional district files' United States totals of line 14 now share a
semantic key with these facts, so chronicle#449's third rule pairs 15 United
States totals of each year with Publication 1304, not 17 (eight Schedule A
items in Table 2.1, not ten). 3,571 TY2022 and 3,468 TY2023 removed totals have
a same-key twin, not 3,569 and 3,466. The new twins are in packages pinned to
their tax year, so twelve, not fourteen, of the removed United States totals of
each year have their only twin in a Publication 1304 package that builds one
tax year at a time. No district fact changes.
2 changes: 1 addition & 1 deletion docs/us-legacy-etl-cleanup.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ counted 32,067,810. The retired tests pinned the invented levels: for example
| `db/etl_soi_credits.py` CTC and ACTC by number of children (national) | — | Gap: no packaged IRS table publishes CTC or ACTC by number of qualifying children. |
| `db/etl_soi_deductions.py` `salt_claims`, `salt_amount` (state) | `soi-historic-table-2-state-broad-2022` `taxes_paid_deduction_*` (`N18300`/`A18300`, Schedule A line 7), `limited_state_local_taxes_*` (line 5e), `real_estate_taxes_*` (line 5b) | The legacy "SALT" named no IRS line, so no one measure is a like-for-like replacement. None for 2022. |
| `db/etl_soi_deductions.py` `mortgage_interest_claims`, `mortgage_interest_amount` (state) | state: `soi-historic-table-2-state-broad-2022` `mortgage_interest_paid_*` (`N19300`/`A19300`, Schedule A line 8a, Historic Table 2's state rows; the district file's state-total rows for the same column give no fact since chronicle#449); national: `soi-table-2-1` `mortgage_interest_paid_*` | None for 2022. The two state series are separate IRS tabulations of one line and differ by state. |
| `db/etl_soi_deductions.py` `charitable_claims`, `charitable_amount` (state) | state: `soi-historic-table-2-state-broad-2022` `charitable_*` (`N19700`/`A19700`, Schedule A line 14, Historic Table 2's state rows; the district file's state-total rows for the same column give no fact since chronicle#449); national: `soi-table-2-1` `charitable_*` | None for 2022. The two state series are separate IRS tabulations of one line and differ by state (WY `A19700`: $572M in the district file, $1,204M in Historic Table 2). |
| `db/etl_soi_deductions.py` `charitable_claims`, `charitable_amount` (state) | state: `soi-historic-table-2-state-broad-2022` `charitable_*` (`N19700`/`A19700`, Schedule A line 14, Historic Table 2's state rows; the district file's state-total rows for the same column give no fact since chronicle#449); national: `soi-historic-table-2` and `soi-historic-table-2-2023` `charitable_*` (the same file's US row), `soi-table-2-1` `charitable_*` | None for 2022. The two state series are separate IRS tabulations of one line and differ by state (WY `A19700`: $572M in the district file, $1,204M in Historic Table 2). The two national series are separate tabulations too: Historic Table 2's US row is 0.5% to 1.6% below Table 2.1 for TY2022 and TY2023. |
| `db/etl_soi_deductions.py` `medical_claims`, `medical_amount` (state) | `soi-historic-table-2-state-broad-2022` `medical_dental_expense_*` | None for 2022. |
| `db/etl_soi_deductions.py` `qbi_claims`, `qbi_amount` (state) | `soi-historic-table-2-state-broad-2022` `qbi_claims`, `qbi_amount`; `soi-congressional-district-2022` `qualified_business_income_deduction_*` (`N04475`/`A04475`) for districts only: its state-total rows give no fact since chronicle#449 | None for 2022. chronicle#345 repinned the broad package's `qbi_*` from `N03270`/`A03270` to `N04475`/`A04475`. |
| `db/etl_soi_income_sources.py` taxable and tax-exempt interest, ordinary and qualified dividends, Schedule C, partnership and S corporation, rental and royalty (national and state) | national: `soi-historic-table-2` (US row); state: `soi-historic-table-2-state-broad-2022` `taxable_interest_*`, `tax_exempt_interest_*`, `ordinary_dividends_*`, `qualified_dividends_*`, `schedule_c_income_*`, `partnership_scorp_income_*`, `rental_royalty_income_*` | None for 2022. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14425,8 +14425,8 @@ artifact:
# state data);
# 2. the same IRS column in a Historic Table 2 package at the same level, under
# another concept id or domain;
# 3. for 17 United States totals, the same tax-form line in Publication 1304
# Table 2.1 (ten Schedule A items), Table 2.5 (the EITC for no, one and two
# 3. for 15 United States totals, the same tax-form line in Publication 1304
# Table 2.1 (eight Schedule A items), Table 2.5 (the EITC for no, one and two
# qualifying children) or Table 1.4 (the self-employed retirement plans
# deduction), which use another domain or concept id. The pairs are listed
# in tests/test_chronicle_soi_district_agi_classes.py.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14455,8 +14455,8 @@ artifact:
# state data);
# 2. the same IRS column in a Historic Table 2 package at the same level, under
# another concept id or domain;
# 3. for 17 United States totals, the same tax-form line in Publication 1304
# Table 2.1 (ten Schedule A items), Table 2.5 (the EITC for no, one and two
# 3. for 15 United States totals, the same tax-form line in Publication 1304
# Table 2.1 (eight Schedule A items), Table 2.5 (the EITC for no, one and two
# qualifying children) or Table 1.4 (the self-employed retirement plans
# deduction), which use another domain or concept id. The pairs are listed
# in tests/test_chronicle_soi_district_agi_classes.py.
Expand Down
23 changes: 23 additions & 0 deletions packages/irs_soi/historic_table_2/source_package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -902,3 +902,26 @@ record_sets:
expected_column_header_row: 1
expected_column_header: A11070
value_scale: 1000
- measure_id: charitable_returns
label: Returns with contributions deduction
ordinal: 55
column: CP
source_column_id: N19700
concept: irs_soi.returns_with_contributions_deduction
unit: count
aggregation: sum
expected_cell_type: number
expected_column_header_row: 1
expected_column_header: N19700
- measure_id: charitable_amount
label: Contributions deduction amount
ordinal: 56
column: CQ
source_column_id: A19700
concept: irs_soi.contributions_deduction
unit: usd
aggregation: sum
expected_cell_type: number
expected_column_header_row: 1
expected_column_header: A19700
value_scale: 1000
23 changes: 23 additions & 0 deletions packages/irs_soi/historic_table_2_2023/source_package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -953,3 +953,26 @@ record_sets:
expected_column_header_row: 1
expected_column_header: A11070
value_scale: 1000
- measure_id: charitable_returns
label: Returns with contributions deduction
ordinal: 55
column: CP
source_column_id: N19700
concept: irs_soi.returns_with_contributions_deduction
unit: count
aggregation: sum
expected_cell_type: number
expected_column_header_row: 1
expected_column_header: N19700
- measure_id: charitable_amount
label: Contributions deduction amount
ordinal: 56
column: CQ
source_column_id: A19700
concept: irs_soi.contributions_deduction
unit: usd
aggregation: sum
expected_cell_type: number
expected_column_header_row: 1
expected_column_header: A19700
value_scale: 1000
28 changes: 20 additions & 8 deletions tests/test_chronicle_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,11 @@ def test_build_bundle_writes_merged_consumer_contract(tmp_path):
# 4,462 TY2023 totals go), and the one row of each single-district
# jurisdiction becomes a district fact (1,000 and 868 new). TY2022
# goes from 59,982 facts to 56,366 and TY2023 from 59,626 to 56,032.
"fact_count": 2416365,
# Historic Table 2's US rows add Schedule A line 14 (N19700/A19700) at
# the 11 AGI classes of TY2022 and TY2023: 44 tax-unit facts. Measured
# with the IRS SOI packages at bundle year 2023: no new geography,
# period or entity key, duplicate key or warning.
"fact_count": 2416409,
# The same change adds 82,064 geography keys: 46,363 Scottish 2022
# output areas (UV404), 35,673 LSOA-level keys from the DESNZ LSOA
# workbooks (Scotland's data zones already exist), the 26 Northern
Expand Down Expand Up @@ -858,7 +862,8 @@ def test_build_bundle_writes_merged_consumer_contract(tmp_path):
if row_count == 1:
assert row["aggregate_fact_key"].startswith("ledger.aggregate_fact.v2:")
assert row["semantic_fact_key"].startswith("ledger.semantic_fact.v2:")
assert row_count == 2416365
# The same count as the summary's and the coverage's fact_count pins.
assert row_count == 2416409
assert provenance_classes <= {
"administrative",
"census",
Expand Down Expand Up @@ -912,7 +917,7 @@ def test_build_bundle_writes_merged_consumer_contract(tmp_path):
"jct-tax-expenditures-2024",
"jct-tax-expenditures-2025",
]
assert coverage["fact_count"] == 2416365
assert coverage["fact_count"] == 2416409
assert coverage["counts"]["by_source"] == {
"bea": 446,
"bfp_economic_outlook": 5,
Expand All @@ -939,7 +944,7 @@ def test_build_bundle_writes_merged_consumer_contract(tmp_path):
"hmrc": 40025,
"ici": 12,
"ird": 4362,
"irs_soi": 146622,
"irs_soi": 146666,
"isc": 4,
"jrc_euromod_be": 90,
"kff": 52,
Expand Down Expand Up @@ -2440,6 +2445,10 @@ def test_build_bundle_writes_merged_consumer_contract(tmp_path):
# go and 1,000 district facts are new. TY2023: 4,462 go and 868 are new.
expected_period_counts["tax_year:2022"] += 1000 - 4616
expected_period_counts["tax_year:2023"] += 868 - 4462
# Historic Table 2's US rows: Schedule A line 14, two measures at 11 AGI
# classes, for each of TY2022 and TY2023.
expected_period_counts["tax_year:2022"] += 22
expected_period_counts["tax_year:2023"] += 22
# BEA NIPA Table 7.8 line 17 (B4923C): the bundle year's own column.
expected_period_counts["calendar_year:2023"] += 1
# chronicle#343: ONS constituency sales and medians for the years ending
Expand Down Expand Up @@ -3145,7 +3154,9 @@ def test_build_bundle_writes_merged_consumer_contract(tmp_path):
# chronicle#449 takes 153 off: the district file's United States totals
# that another package gives (77 of TY2022 and 76 of TY2023). 30 stay for
# each year.
assert coverage["counts"]["by_geography"]["country:0100000US"] == 10840
# Historic Table 2's US rows add 44: Schedule A line 14, two measures at
# 11 AGI classes, for TY2022 and TY2023.
assert coverage["counts"]["by_geography"]["country:0100000US"] == 10884
# 255, less Vintage 2024's state total (chronicle#397), + 16 Census Vintage
# 2025 age groups (15 groups and the total), + 6 from SSA's Supplement
# Tables 7.B3 (four California cells) and 7.B7 (two), + 8 Historic Table 2
Expand Down Expand Up @@ -3327,7 +3338,8 @@ def test_build_bundle_writes_merged_consumer_contract(tmp_path):
# Trustees 1) and household 55 (SNAP 54, LIHEAP 1).
# chronicle#444 adds 73,805 tax units.
# chronicle#449's rule for the district file's totals takes 7,210 off.
"tax_unit": 147927,
# Historic Table 2's US rows add 44 (Schedule A line 14).
"tax_unit": 147971,
}
assert not coverage["duplicates"]["aggregate_fact_keys"]
assert len(coverage["duplicates"]["semantic_fact_keys"]) == 2355
Expand Down Expand Up @@ -3736,9 +3748,9 @@ def test_build_bundle_cli_supports_historic_table_2_source(tmp_path, capsys):
assert exit_code == 0
assert payload["valid"]
assert payload["counts"]["source_package_count"] == 1
assert payload["counts"]["fact_count"] == 605
assert payload["counts"]["fact_count"] == 627
assert payload["coverage"]["counts"]["by_source_table"] == {
"irs_soi:Historic Table 2": 605
"irs_soi:Historic Table 2": 627
}
assert (
output_dir / "sources" / "soi-historic-table-2" / "source_rows.jsonl"
Expand Down
30 changes: 17 additions & 13 deletions tests/test_chronicle_soi_district_agi_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
district (value id ``<state>_00``). The file's United States row and its state
total rows give a fact only where no other IRS package gives the same quantity:
the same semantic key, the same IRS column in Historic Table 2, or one of the
17 tax-form lines of ``PUBLICATION_1304_LINES`` below.
15 tax-form lines of ``PUBLICATION_1304_LINES`` below.
Those totals sit in the ``*_state_totals`` and ``*_us_total`` record sets, under
the source record ids they had before. Checks about the file itself (its
classes add up, its districts add up to its state rows) read the CSV, where
Expand Down Expand Up @@ -916,8 +916,10 @@ def test_a_state_total_row_is_never_a_district_fact(district):
TABLE_2_5 = "table_2_5.eitc_by_agi_children"
TABLE_2_5_PACKAGE = "soi-table-2-5-eitc-agi-children-{year}"
PUBLICATION_1304_LINES = {
# Table 2.1, returns with itemized deductions: Schedule A lines 8a, 8b, 8c,
# 9 and 14, under the district file's measure ids.
# Table 2.1, returns with itemized deductions: Schedule A lines 8a, 8b, 8c
# and 9, under the district file's measure ids. Line 14 (``charitable_*``)
# is not here: Historic Table 2's US row reads its columns (N19700, A19700)
# under the same semantic key, so the first rule removes that total.
"mortgage_interest_paid_returns": (
"soi-table-2-1",
f"{TABLE_2_1}.mortgage_interest_paid_returns",
Expand Down Expand Up @@ -950,8 +952,6 @@ def test_a_state_total_row_is_never_a_district_fact(district):
"soi-table-2-1",
f"{TABLE_2_1}.investment_interest_paid_amount",
),
"charitable_returns": ("soi-table-2-1", f"{TABLE_2_1}.charitable_returns"),
"charitable_amount": ("soi-table-2-1", f"{TABLE_2_1}.charitable_amount"),
# Table 2.5: the EITC for no, one and two qualifying children.
"eitc_no_children_claims": (
TABLE_2_5_PACKAGE,
Expand Down Expand Up @@ -1106,7 +1106,7 @@ def test_publication_1304_gives_each_paired_us_line(district):
domain or its concept id is another: that is why no semantic key pairs the
two. Its value is close to the district file's US cell, read from the CSV,
and above it: the district file protects small cells and leaves out returns
that match no district by ZIP code. Over the 17 pairs and both years the
that match no district by ZIP code. Over the 15 pairs and both years the
cell is 0.8307 to 0.9895 of the Publication 1304 value, so the bound is
0.80 to 1. A line of the wrong size fails it;
``tests/test_chronicle_soi_doc_guide_columns.py`` tells line 8a from the
Expand All @@ -1120,13 +1120,13 @@ def test_publication_1304_gives_each_paired_us_line(district):
a_district = all_returns["rows"][0]["value_id"]
pairs = _publication_1304_records(district)

assert len(pairs) == 17
assert len(pairs) == 15
assert {package_id for package_id, _ in pairs.values()} == {
"soi-table-1-4",
"soi-table-2-1",
f"soi-table-2-5-eitc-agi-children-{year}",
}
assert len(set(pairs.values())) == 17
assert len(set(pairs.values())) == 15
ratios = {}
for measure_id, (package_id, record_id) in pairs.items():
(paired,) = [
Expand Down Expand Up @@ -1174,7 +1174,7 @@ def test_publication_1304_gives_each_paired_us_line(district):
def test_the_table_1_4_pair_is_schedule_1_line_16_on_both_sides(district):
"""The Table 1.4 pair is tied to each publication's own words.

The ten Table 2.1 pairs share a measure id and a concept id, and the six
The eight Table 2.1 pairs share a measure id and a concept id, and the six
Table 2.5 pairs share a qualifying-children constraint. The Table 1.4 pair
shares none of these, and the size bound alone does not tell its line from
the next one of Table 1.4: the district file's cell is also 0.92 to 0.93
Expand Down Expand Up @@ -1378,7 +1378,7 @@ def test_no_fact_repeats_a_quantity_another_irs_package_gives(district):
ids (A00900, A01700, A06500, A25870, A26270 and their N columns) and
Historic Table 2's state EITC package has another domain, so the keys
differ where the column and its guide text are the same. Third, none of
the 17 United States totals of ``PUBLICATION_1304_LINES`` is a fact. The
the 15 United States totals of ``PUBLICATION_1304_LINES`` is a fact. The
first two are derived here, and only sets of keys and of columns are
compared.
"""
Expand Down Expand Up @@ -1436,7 +1436,7 @@ def test_a_total_stays_only_where_no_other_package_gives_it(district):
gives the total when (1) a ``soi-*`` package of the tax year has that key,
(2) a Historic Table 2 package of the tax year reads the same IRS column
at the same level for the same class of returns, or (3) it is one of the
17 United States totals of ``PUBLICATION_1304_LINES``. The total is a fact
15 United States totals of ``PUBLICATION_1304_LINES``. The total is a fact
exactly when none of the three gives it, and a total that stays keeps the
source record id it had before. Rules 1 and 2 are derived here, with no
list of measures; rule 3's pairs are the declared list, and they are the
Expand Down Expand Up @@ -1495,9 +1495,9 @@ def test_a_total_stays_only_where_no_other_package_gives_it(district):
assert len(kept) == district.state_total_facts + district.us_total_facts
# 4,539 state and 77 US totals in TY2022, 4,386 and 76 in TY2023.
assert len(dropped) == {2022: 4_616, 2023: 4_462}[district.year]
# Each of the 17 pairs is needed: neither a key nor a column removes it.
# Each of the 15 pairs is needed: neither a key nor a column removes it.
assert by_line_only == publication_1304_lines
assert len(by_line_only) == 17
assert len(by_line_only) == 15
# The totals sit in their own record sets, apart from the district rows.
for record_id, fact in facts.items():
record_set_id = fact.layout.record_set_id
Expand All @@ -1520,6 +1520,10 @@ def test_a_total_stays_only_where_no_other_package_gives_it(district):
# retirement plans deduction in Table 1.4 under another concept id.
"all_returns.us.mortgage_interest_paid_amount": False,
"all_returns.us.self_employed_retirement_plans_amount": False,
# Historic Table 2's US row gives Schedule A line 14 under the same
# semantic key.
"all_returns.us.charitable_amount": False,
"all_returns.us.charitable_returns": False,
# No package gives the returns with that deduction or the total tax
# liability for the nation, or the standard deduction of a state.
"all_returns.us.self_employed_retirement_plans_returns": True,
Expand Down
6 changes: 5 additions & 1 deletion tests/test_chronicle_soi_doc_guide_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,14 +1129,18 @@ def test_congressional_district_us_row_is_a_subset_of_historic_table_2(
"real_estate_taxes_claims",
"real_estate_taxes_amount",
"itemized_deductions_returns",
# Schedule A line 14, which Historic Table 2's US row reads like its
# state rows.
"charitable_returns",
"charitable_amount",
} <= set(pairs)
missing = {
measure_id
for measure_id in ht2
if HT2_TO_DISTRICT_IDS.get(measure_id, measure_id) not in district
}
assert missing == NOT_READ_BY_DISTRICT[year]
assert len(pairs) == 55 - len(missing)
assert len(pairs) == 57 - len(missing)
# None of the compared US cells is a fact of the district package.
assert not {
HT2_TO_DISTRICT_IDS.get(measure_id, measure_id) for measure_id in pairs
Expand Down
Loading