Skip to content

Commit 8a8bbef

Browse files
committed
Format SOI target refresh changes
1 parent 4812657 commit 8a8bbef

5 files changed

Lines changed: 38 additions & 45 deletions

File tree

policyengine_us_data/db/etl_national_targets.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,15 @@ def extract_national_targets(dataset: str = DEFAULT_DATASET):
251251
# Retirement contribution targets — see issue #553
252252
{
253253
"variable": "traditional_ira_contributions",
254-
"value": RETIREMENT_CONTRIBUTION_TARGETS[
255-
"traditional_ira_contributions"
256-
]["value"],
257-
"source": RETIREMENT_CONTRIBUTION_TARGETS[
258-
"traditional_ira_contributions"
259-
]["source"],
260-
"notes": RETIREMENT_CONTRIBUTION_TARGETS[
261-
"traditional_ira_contributions"
262-
]["notes"],
254+
"value": RETIREMENT_CONTRIBUTION_TARGETS["traditional_ira_contributions"][
255+
"value"
256+
],
257+
"source": RETIREMENT_CONTRIBUTION_TARGETS["traditional_ira_contributions"][
258+
"source"
259+
],
260+
"notes": RETIREMENT_CONTRIBUTION_TARGETS["traditional_ira_contributions"][
261+
"notes"
262+
],
263263
"year": HARDCODED_YEAR,
264264
},
265265
{
@@ -291,15 +291,11 @@ def extract_national_targets(dataset: str = DEFAULT_DATASET):
291291
},
292292
{
293293
"variable": "roth_ira_contributions",
294-
"value": RETIREMENT_CONTRIBUTION_TARGETS["roth_ira_contributions"][
295-
"value"
296-
],
294+
"value": RETIREMENT_CONTRIBUTION_TARGETS["roth_ira_contributions"]["value"],
297295
"source": RETIREMENT_CONTRIBUTION_TARGETS["roth_ira_contributions"][
298296
"source"
299297
],
300-
"notes": RETIREMENT_CONTRIBUTION_TARGETS["roth_ira_contributions"][
301-
"notes"
302-
],
298+
"notes": RETIREMENT_CONTRIBUTION_TARGETS["roth_ira_contributions"]["notes"],
303299
"year": HARDCODED_YEAR,
304300
},
305301
]

policyengine_us_data/storage/calibration_targets/refresh_soi_table_targets.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ def build_target_year_rows(
259259
refreshed["Year"] = target_year
260260

261261
semantic_columns = _semantic_columns(refreshed)
262-
if refreshed["SOI table"] in {"Table 1.4", "Table 2.1"} and semantic_columns is None:
262+
if (
263+
refreshed["SOI table"] in {"Table 1.4", "Table 2.1"}
264+
and semantic_columns is None
265+
):
263266
skipped_rows.append((refreshed["SOI table"], refreshed["Variable"]))
264267
continue
265268

@@ -283,7 +286,9 @@ def build_target_year_rows(
283286
refreshed_rows.append(refreshed)
284287

285288
if skipped_rows:
286-
skipped = ", ".join(sorted({f"{table}/{variable}" for table, variable in skipped_rows}))
289+
skipped = ", ".join(
290+
sorted({f"{table}/{variable}" for table, variable in skipped_rows})
291+
)
287292
print(f"Skipped unsupported SOI rows for {target_year}: {skipped}")
288293

289294
return pd.DataFrame(refreshed_rows, columns=all_targets.columns)

policyengine_us_data/utils/loss.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@
9898
# (TY 2022, latest published). Total Roth IRA contributions =
9999
# $34.95B (10.04M contributors). Direct administrative source.
100100
# https://www.irs.gov/statistics/soi-tax-stats-accumulation-and-distribution-of-individual-retirement-arrangements
101-
"roth_ira_contributions": RETIREMENT_CONTRIBUTION_TARGETS[
102-
"roth_ira_contributions"
103-
]["value"],
101+
"roth_ira_contributions": RETIREMENT_CONTRIBUTION_TARGETS["roth_ira_contributions"][
102+
"value"
103+
],
104104
}
105105

106106

policyengine_us_data/utils/soi.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,24 +248,26 @@ def get_soi(year: int) -> pd.DataFrame:
248248
latest_uprating_year = int(uprating_years.max())
249249

250250
uprating_factors = {}
251-
for variable, source_year in soi[["Variable", "Year"]].drop_duplicates().itertuples(
252-
index=False
251+
for variable, source_year in (
252+
soi[["Variable", "Year"]].drop_duplicates().itertuples(index=False)
253253
):
254254
source_year_for_uprating = min(
255255
max(int(source_year), earliest_uprating_year),
256256
latest_uprating_year,
257257
)
258-
target_year_for_uprating = min(max(int(year), earliest_uprating_year), latest_uprating_year)
258+
target_year_for_uprating = min(
259+
max(int(year), earliest_uprating_year), latest_uprating_year
260+
)
259261
pe_name = SOI_UPRATING_MAP.get(variable)
260262
if pe_name in uprating.index:
261-
uprating_factors[variable] = uprating.loc[
262-
pe_name, target_year_for_uprating
263-
] / uprating.loc[pe_name, source_year_for_uprating]
263+
uprating_factors[variable] = (
264+
uprating.loc[pe_name, target_year_for_uprating]
265+
/ uprating.loc[pe_name, source_year_for_uprating]
266+
)
264267
else:
265-
uprating_factors[variable] = uprating.loc[
266-
"employment_income", target_year_for_uprating
267-
] / (
268-
uprating.loc["employment_income", source_year_for_uprating]
268+
uprating_factors[variable] = (
269+
uprating.loc["employment_income", target_year_for_uprating]
270+
/ (uprating.loc["employment_income", source_year_for_uprating])
269271
)
270272

271273
for variable, uprating_factor in uprating_factors.items():

tests/test_soi_utils.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ def test_get_soi_uses_best_available_year_per_variable(monkeypatch):
116116
index=["interest_deduction", "taxable_interest_income"],
117117
)
118118

119-
monkeypatch.setattr(
120-
soi_module, "load_tracked_soi_targets", lambda: fake_soi.copy()
121-
)
119+
monkeypatch.setattr(soi_module, "load_tracked_soi_targets", lambda: fake_soi.copy())
122120
monkeypatch.setattr(
123121
soi_module,
124122
"create_policyengine_uprating_factors_table",
@@ -176,16 +174,10 @@ def test_get_tracked_soi_row_selects_requested_best_year(monkeypatch):
176174
},
177175
]
178176
)
179-
monkeypatch.setattr(
180-
soi_module, "load_tracked_soi_targets", lambda: fake_soi.copy()
181-
)
177+
monkeypatch.setattr(soi_module, "load_tracked_soi_targets", lambda: fake_soi.copy())
182178

183-
row_2022 = soi_module.get_tracked_soi_row(
184-
"business_net_profits", 2022, count=False
185-
)
186-
row_2024 = soi_module.get_tracked_soi_row(
187-
"business_net_profits", 2024, count=False
188-
)
179+
row_2022 = soi_module.get_tracked_soi_row("business_net_profits", 2022, count=False)
180+
row_2024 = soi_module.get_tracked_soi_row("business_net_profits", 2024, count=False)
189181

190182
assert row_2022["Year"] == 2021
191183
assert row_2024["Year"] == 2023
@@ -225,9 +217,7 @@ def test_get_national_soi_aggregate_rows_filters_to_all_returns(monkeypatch):
225217
},
226218
]
227219
)
228-
monkeypatch.setattr(
229-
soi_module, "load_tracked_soi_targets", lambda: fake_soi.copy()
230-
)
220+
monkeypatch.setattr(soi_module, "load_tracked_soi_targets", lambda: fake_soi.copy())
231221

232222
result = soi_module.get_national_soi_aggregate_rows(2024)
233223

0 commit comments

Comments
 (0)