Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply five year forward checks with utility function #5175

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: minor
changes:
added:
- Add five-year-forward check on all reforms
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from policyengine_us.model_api import *
from policyengine_us.reforms.utils import create_reform_if_active


def create_capital_gains_tax_increase() -> Reform:
Expand Down Expand Up @@ -141,15 +142,14 @@ def apply(self):
def create_capital_gains_tax_increase_reform(
parameters, period, bypass: bool = False
):
if bypass:
return create_capital_gains_tax_increase()

p = parameters(period).gov.contrib.biden.budget_2025.capital_gains

if p.active:
return create_capital_gains_tax_increase()
else:
return None
return create_reform_if_active(
parameters,
period,
"gov.contrib.biden.budget_2025.capital_gains",
"active",
create_capital_gains_tax_increase,
bypass,
)


capital_gains_tax_increase = create_capital_gains_tax_increase_reform(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from policyengine_us.model_api import *
from policyengine_us.reforms.utils import create_reform_two_threshold_check
import operator


def create_medicare_and_investment_tax_increase() -> Reform:
Expand Down Expand Up @@ -71,15 +73,19 @@ def apply(self):
def create_medicare_and_investment_tax_increase_reform(
parameters, period, bypass: bool = False
):
if bypass:
return create_medicare_and_investment_tax_increase()

p = parameters(period).gov.contrib.biden.budget_2025

if (p.medicare.rate > 0) | (p.net_investment_income.rate > 0):
return create_medicare_and_investment_tax_increase()
else:
return None
return create_reform_two_threshold_check(
parameters=parameters,
period=period,
parameter_path="gov.contrib.biden.budget_2025",
reform_function=create_medicare_and_investment_tax_increase,
comparison_parameter_path_1="medicare.rate",
comparison_parameter_path_2="net_investment_income.rate",
threshold_check_1=0,
threshold_check_2=0,
comparison_operator_1=operator.gt,
comparison_operator_2=operator.gt,
bypass=bypass,
)


medicare_and_investment_tax_increase = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from policyengine_us.model_api import *
from policyengine_us.reforms.utils import create_reform_threshold_check
import operator
import numpy as np


def create_increase_taxable_earnings_for_social_security() -> Reform:
Expand Down Expand Up @@ -29,15 +32,16 @@ def apply(self):
def create_increase_taxable_earnings_for_social_security_reform(
parameters, period, bypass: bool = False
):
if bypass:
return create_increase_taxable_earnings_for_social_security()

p = parameters(period).gov.contrib.cbo.payroll

if p.secondary_earnings_threshold < np.inf:
return create_increase_taxable_earnings_for_social_security()
else:
return None
return create_reform_threshold_check(
reform_function=create_increase_taxable_earnings_for_social_security,
parameters=parameters,
period=period,
parameter_path="gov.contrib.cbo.payroll",
comparison_parameter_path="secondary_earnings_threshold",
comparison_operator=operator.lt,
threshold_check=np.inf,
bypass=bypass,
)


increase_taxable_earnings_for_social_security = (
Expand Down
31 changes: 12 additions & 19 deletions policyengine_us/reforms/congress/delauro/american_family_act.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from policyengine_us.model_api import *
from policyengine_core.periods import period as period_
from policyengine_us.reforms.utils import create_reform_threshold_check
import operator


def create_american_family_act_with_baby_bonus() -> Reform:
Expand Down Expand Up @@ -35,24 +36,16 @@ def apply(self):
def create_american_family_act_with_baby_bonus_reform(
parameters, period, bypass: bool = False
):
if bypass:
return create_american_family_act_with_baby_bonus()

p = parameters.gov.contrib.congress.delauro.american_family_act

reform_active = False
current_period = period_(period)

for i in range(5):
if p(current_period).baby_bonus > 0:
reform_active = True
break
current_period = current_period.offset(1, "year")

if reform_active:
return create_american_family_act_with_baby_bonus()
else:
return None
return create_reform_threshold_check(
reform_function=create_american_family_act_with_baby_bonus,
parameters=parameters,
period=period,
parameter_path="gov.contrib.congress.delauro.american_family_act",
comparison_parameter_path="baby_bonus",
comparison_operator=operator.gt,
threshold_check=0,
bypass=bypass,
)


american_family_act = create_american_family_act_with_baby_bonus_reform(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from policyengine_us.model_api import *
from policyengine_core.periods import period as period_
from policyengine_us.reforms.utils import create_reform_if_active


def create_remove_head_of_household() -> Reform:
Expand All @@ -13,24 +13,14 @@ def apply(self):
def create_remove_head_of_household_reform(
parameters, period, bypass: bool = False
):
if bypass:
return create_remove_head_of_household()

# Look ahead for the next five years
p = parameters.gov.contrib.congress.romney.family_security_act
reform_active = False
current_period = period_(period)

for i in range(5):
if p(current_period).remove_head_of_household:
reform_active = True
break
current_period = current_period.offset(1, "year")

if reform_active:
return create_remove_head_of_household()
else:
return None
return create_reform_if_active(
parameters,
period,
"gov.contrib.congress.romney.family_security_act",
"remove_head_of_household",
create_remove_head_of_household,
bypass,
)


remove_head_of_household = create_remove_head_of_household_reform(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from policyengine_us.model_api import *
from policyengine_core.periods import period as period_
from policyengine_us.reforms.utils import create_reform_if_active


def create_family_security_act_2024_ctc() -> Reform:
Expand Down Expand Up @@ -142,24 +142,14 @@ def apply(self):
def create_family_security_act_2024_ctc_reform(
parameters, period, bypass: bool = False
):
if bypass:
return create_family_security_act_2024_ctc()

# Look ahead for the next five years
p = parameters.gov.contrib.congress.romney.family_security_act_2_0.ctc
reform_active = False
current_period = period_(period)

for i in range(5):
if p(current_period).apply_ctc_structure:
reform_active = True
break
current_period = current_period.offset(1, "year")

if reform_active:
return create_family_security_act_2024_ctc()
else:
return None
return create_reform_if_active(
parameters,
period,
"gov.contrib.congress.romney.family_security_act_2_0.ctc",
"apply_ctc_structure",
create_family_security_act_2024_ctc,
bypass,
)


family_security_act_2024_ctc = create_family_security_act_2024_ctc_reform(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from policyengine_us.model_api import *
from policyengine_core.periods import period as period_
from policyengine_us.reforms.utils import create_reform_if_active


def create_family_security_act_2024_eitc() -> Reform:
Expand Down Expand Up @@ -33,24 +33,14 @@ def apply(self):
def create_family_security_act_2024_eitc_reform(
parameters, period, bypass: bool = False
):
if bypass:
return create_family_security_act_2024_eitc()

# Look ahead for the next five years
p = parameters.gov.contrib.congress.romney.family_security_act_2_0.eitc
reform_active = False
current_period = period_(period)

for i in range(5):
if p(current_period).apply_eitc_structure:
reform_active = True
break
current_period = current_period.offset(1, "year")

if reform_active:
return create_family_security_act_2024_eitc()
else:
return None
return create_reform_if_active(
parameters,
period,
"gov.contrib.congress.romney.family_security_act_2_0.eitc",
"apply_eitc_structure",
create_family_security_act_2024_eitc,
bypass,
)


family_security_act_2024_eitc = create_family_security_act_2024_eitc_reform(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from policyengine_us.model_api import *
from policyengine_us.reforms.utils import create_reform_if_active


def create_boost_middle_class_tax_credit() -> Reform:
Expand Down Expand Up @@ -143,15 +144,14 @@ def apply(self):
def create_boost_middle_class_tax_credit_reform(
parameters, period, bypass: bool = False
):
if bypass:
return create_boost_middle_class_tax_credit()

p = parameters(period).gov.contrib.harris.lift.middle_class_tax_credit

if p.in_effect:
return create_boost_middle_class_tax_credit()
else:
return None
return create_reform_if_active(
parameters,
period,
"gov.contrib.harris.lift.middle_class_tax_credit",
"in_effect",
create_boost_middle_class_tax_credit,
bypass,
)


boost_middle_class_tax_credit = create_boost_middle_class_tax_credit_reform(
Expand Down
18 changes: 9 additions & 9 deletions policyengine_us/reforms/congress/tlaib/end_child_poverty_act.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from policyengine_us.model_api import *
from policyengine_us.reforms.utils import create_reform_if_active


def create_end_child_poverty_act() -> Reform:
Expand Down Expand Up @@ -176,15 +177,14 @@ def apply(self):
def create_end_child_poverty_act_reform(
parameters, period, bypass: bool = False
):
if bypass:
return create_end_child_poverty_act()

p = parameters(period).gov.contrib.congress.tlaib.end_child_poverty_act

if p.in_effect:
return create_end_child_poverty_act()
else:
return None
return create_reform_if_active(
parameters,
period,
"gov.contrib.congress.tlaib.end_child_poverty_act",
"in_effect",
create_end_child_poverty_act,
bypass,
)


end_child_poverty_act = create_end_child_poverty_act_reform(
Expand Down
18 changes: 9 additions & 9 deletions policyengine_us/reforms/eitc/halve_joint_eitc_phase_out_rate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from policyengine_us.model_api import *
from policyengine_us.reforms.utils import create_reform_if_active


def create_halve_joint_eitc_phase_out_rate() -> Reform:
Expand Down Expand Up @@ -28,15 +29,14 @@ def apply(self):
def create_halve_joint_eitc_phase_out_rate_reform(
parameters, period, bypass: bool = False
):
if bypass:
return create_halve_joint_eitc_phase_out_rate()

p = parameters(period).gov.contrib.joint_eitc

if p.in_effect:
return create_halve_joint_eitc_phase_out_rate()
else:
return None
return create_reform_if_active(
parameters,
period,
"gov.contrib.joint_eitc",
"in_effect",
create_halve_joint_eitc_phase_out_rate,
bypass,
)


halve_joint_eitc_phase_out_rate = (
Expand Down
18 changes: 9 additions & 9 deletions policyengine_us/reforms/federal/abolish_federal_income_tax.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from policyengine_us.model_api import *
from policyengine_us.reforms.utils import create_reform_if_active


def create_abolish_federal_income_tax() -> Reform:
Expand Down Expand Up @@ -50,15 +51,14 @@ def apply(self):
def create_abolish_federal_income_tax_reform(
parameters, period, bypass: bool = False
):
if bypass:
return create_abolish_federal_income_tax()

p = parameters(period).gov.contrib.ubi_center.flat_tax

if p.abolish_federal_income_tax:
return create_abolish_federal_income_tax()
else:
return None
return create_reform_if_active(
parameters,
period,
"gov.contrib.ubi_center.flat_tax",
"abolish_federal_income_tax",
create_abolish_federal_income_tax,
bypass,
)


abolish_federal_income_tax = create_abolish_federal_income_tax_reform(
Expand Down
Loading