Skip to content

Commit

Permalink
Rename utility function and fix dc_kccatc
Browse files Browse the repository at this point in the history
  • Loading branch information
leehengpan committed Oct 22, 2024
1 parent 81c65c9 commit cd45dd1
Show file tree
Hide file tree
Showing 21 changed files with 70 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_capital_gains_tax_increase() -> Reform:
class capital_gains_tax(Variable):
Expand Down Expand Up @@ -145,7 +146,7 @@ def create_capital_gains_tax_increase_reform(
return create_capital_gains_tax_increase()

p = parameters(period).gov.contrib.biden.budget_2025.capital_gains
reform_active = is_reform_active(p, period, "active")
reform_active = reform_is_active(p, period, "active")

if reform_active:
return create_capital_gains_tax_increase()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_remove_head_of_household() -> Reform:
Expand All @@ -18,7 +18,7 @@ def create_remove_head_of_household_reform(

# Look ahead for the next five years
p = parameters.gov.contrib.congress.romney.family_security_act
reform_active = is_reform_active(p, period, "remove_head_of_household")
reform_active = reform_is_active(p, period, "remove_head_of_household")

if reform_active:
return create_remove_head_of_household()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_family_security_act_2024_ctc() -> Reform:
class ctc_phase_in_rate(Variable):
Expand Down Expand Up @@ -146,7 +147,7 @@ def create_family_security_act_2024_ctc_reform(

# Look ahead for the next five years
p = parameters.gov.contrib.congress.romney.family_security_act_2_0.ctc
reform_active = is_reform_active(p, period, "apply_ctc_structure")
reform_active = reform_is_active(p, period, "apply_ctc_structure")

if reform_active:
return create_family_security_act_2024_ctc()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_family_security_act_2024_eitc() -> Reform:
Expand Down Expand Up @@ -38,7 +38,7 @@ def create_family_security_act_2024_eitc_reform(

# Look ahead for the next five years
p = parameters.gov.contrib.congress.romney.family_security_act_2_0.eitc
reform_active = is_reform_active(p, period, "apply_eitc_structure")
reform_active = reform_is_active(p, period, "apply_eitc_structure")

if reform_active:
return create_family_security_act_2024_eitc()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_boost_middle_class_tax_credit() -> Reform:
class boost_middle_class_tax_credit(Variable):
Expand Down Expand Up @@ -147,7 +148,7 @@ def create_boost_middle_class_tax_credit_reform(
return create_boost_middle_class_tax_credit()

p = parameters(period).gov.contrib.harris.lift.middle_class_tax_credit
reform_active = is_reform_active(p, period)
reform_active = reform_is_active(p, period)

if reform_active:
return create_boost_middle_class_tax_credit()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_end_child_poverty_act() -> Reform:
Expand Down Expand Up @@ -181,7 +181,7 @@ def create_end_child_poverty_act_reform(
return create_end_child_poverty_act()

p = parameters(period).gov.contrib.congress.tlaib.end_child_poverty_act
reform_active = is_reform_active(p, period)
reform_active = reform_is_active(p, period)

if reform_active:
return create_end_child_poverty_act()
Expand Down
6 changes: 4 additions & 2 deletions policyengine_us/reforms/congress/wyden_smith/ctc_expansion.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_ctc_expansion() -> Reform:
Expand Down Expand Up @@ -111,7 +111,9 @@ def create_ctc_expansion_reform(parameters, period, bypass: bool = False):
# Look ahead for the next five years

p = parameters.gov.contrib.congress.wyden_smith
reform_active = is_reform_active(p, period, "actc_lookback") or is_reform_active(p, period, "per_child_actc_phase_in")
reform_active = reform_is_active(
p, period, "actc_lookback"
) or reform_is_active(p, period, "per_child_actc_phase_in")

if reform_active:
return create_ctc_expansion()
Expand Down
18 changes: 6 additions & 12 deletions policyengine_us/reforms/dc_kccatc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active

def create_dc_kccatc():

def create_dc_kccatc_reform(parameters, period, bypass=False):
class dc_kccatc(Variable):
value_type = float
entity = TaxUnit
Expand Down Expand Up @@ -87,18 +88,11 @@ class reform(Reform):
def apply(self):
self.update_variable(dc_kccatc)

return reform


def create_dc_kccatc_reform(parameters, period, bypass=False):
if bypass:
return create_dc_kccatc()

p = parameters(period).gov.contrib.dc_kccatc
reform_active = is_reform_active(p, period, "active")
reform_active = reform_is_active(p, period, "active")

if reform_active:
return create_dc_kccatc()
if bypass or reform_active:
return reform
else:
return None

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_halve_joint_eitc_phase_out_rate() -> Reform:
Expand Down Expand Up @@ -33,7 +33,7 @@ def create_halve_joint_eitc_phase_out_rate_reform(
return create_halve_joint_eitc_phase_out_rate()

p = parameters(period).gov.contrib.joint_eitc
reform_active = is_reform_active(p, period)
reform_active = reform_is_active(p, period)

if reform_active:
return create_halve_joint_eitc_phase_out_rate()
Expand Down
5 changes: 3 additions & 2 deletions policyengine_us/reforms/federal/abolish_federal_income_tax.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_abolish_federal_income_tax() -> Reform:
class household_tax_before_refundable_credits(Variable):
Expand Down Expand Up @@ -54,7 +55,7 @@ def create_abolish_federal_income_tax_reform(
return create_abolish_federal_income_tax()

p = parameters(period).gov.contrib.ubi_center.flat_tax
reform_active = is_reform_active(p, period, "abolish_federal_income_tax")
reform_active = reform_is_active(p, period, "abolish_federal_income_tax")

if reform_active:
return create_abolish_federal_income_tax()
Expand Down
5 changes: 3 additions & 2 deletions policyengine_us/reforms/federal/abolish_payroll_tax.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_abolish_payroll_tax() -> Reform:
class household_tax_before_refundable_credits(Variable):
Expand Down Expand Up @@ -34,7 +35,7 @@ def create_abolish_payroll_tax_reform(
return create_abolish_payroll_tax()

p = parameters(period).gov.contrib.ubi_center.flat_tax
reform_active = is_reform_active(p, period, "abolish_payroll_tax")
reform_active = reform_is_active(p, period, "abolish_payroll_tax")

if reform_active:
return create_abolish_payroll_tax()
Expand Down
5 changes: 3 additions & 2 deletions policyengine_us/reforms/federal/reported_state_income_tax.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_reported_state_income_tax() -> Reform:
class household_tax_before_refundable_credits(Variable):
Expand Down Expand Up @@ -61,7 +62,7 @@ def create_reported_state_income_tax_reform(
return create_reported_state_income_tax()

p = parameters(period).simulation
reform_active = is_reform_active(p, period, "reported_state_income_tax")
reform_active = reform_is_active(p, period, "reported_state_income_tax")

if reform_active:
return create_reported_state_income_tax()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_middle_class_tax_credit() -> Reform:
class middle_class_tax_credit(Variable):
Expand Down Expand Up @@ -61,7 +62,7 @@ def create_middle_class_tax_credit_reform(
return create_middle_class_tax_credit()

p = parameters(period).gov.contrib.harris.lift.middle_class_tax_credit
reform_active = is_reform_active(p, period)
reform_active = reform_is_active(p, period)

if reform_active:
return create_middle_class_tax_credit()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_rent_relief_tax_credit() -> Reform:
class rent_relief_tax_credit(Variable):
Expand Down Expand Up @@ -83,7 +84,7 @@ def create_rent_relief_tax_credit_reform(
p = parameters(
period
).gov.contrib.harris.rent_relief_act.rent_relief_credit
reform_active = is_reform_active(p, period)
reform_active = reform_is_active(p, period)

if reform_active:
return create_rent_relief_tax_credit()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_adjust_income_limit_and_min_children_by_filing_status() -> Reform:
class nyc_school_tax_credit_eligible(Variable):
Expand Down Expand Up @@ -55,7 +56,11 @@ def create_adjust_income_limit_by_filing_status_and_eligibility_by_children_refo
return create_adjust_income_limit_and_min_children_by_filing_status()

p = parameters(period).gov.contrib.local.nyc.stc
reform_active = is_reform_active(p, period, "adjust_income_limit_by_filing_status_and_eligibility_by_children")
reform_active = reform_is_active(
p,
period,
"adjust_income_limit_by_filing_status_and_eligibility_by_children",
)

if reform_active:
return create_adjust_income_limit_and_min_children_by_filing_status()
Expand Down
5 changes: 3 additions & 2 deletions policyengine_us/reforms/states/dc/dc_ctc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_dc_ctc() -> Reform:
class dc_ctc(Variable):
Expand Down Expand Up @@ -60,7 +61,7 @@ def create_dc_ctc_reform(parameters, period, bypass: bool = False):
return create_dc_ctc()

p = parameters.gov.contrib.states.dc.ctc
reform_active = is_reform_active(p, period)
reform_active = reform_is_active(p, period)

if reform_active:
return create_dc_ctc()
Expand Down
5 changes: 3 additions & 2 deletions policyengine_us/reforms/states/mn/walz/mn_walz_hf1938.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


# Repealing Minnesota Bill HF1938 to pre 2023 rules
def create_mn_walz_hf1938_repeal() -> Reform:
Expand Down Expand Up @@ -212,7 +213,7 @@ def create_mn_walz_hf1938_repeal_reform(
return create_mn_walz_hf1938_repeal()

p = parameters(period).gov.contrib.states.mn.walz.hf1938
reform_active = is_reform_active(p, period, "repeal")
reform_active = reform_is_active(p, period, "repeal")

if reform_active:
return create_mn_walz_hf1938_repeal()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_ny_working_families_tax_credit() -> Reform:
class ny_working_families_tax_credit(Variable):
Expand Down Expand Up @@ -530,7 +531,7 @@ def create_ny_working_families_tax_credit_reform(
return create_ny_working_families_tax_credit()

p = parameters(period).gov.contrib.states.ny.wftc
reform_active = is_reform_active(p, period)
reform_active = reform_is_active(p, period)

if reform_active:
return create_ny_working_families_tax_credit()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_or_rebate_state_tax_exempt() -> Reform:
class or_rebate_subtraction(Variable):
Expand Down Expand Up @@ -49,7 +50,7 @@ def create_or_rebate_state_tax_exempt_reform(
return create_or_rebate_state_tax_exempt()

p = parameters(period).gov.contrib.states["or"].rebate
reform_active = is_reform_active(p, period, "state_tax_exempt")
reform_active = reform_is_active(p, period, "state_tax_exempt")

if reform_active:
return create_or_rebate_state_tax_exempt()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from policyengine_us.model_api import *
from reforms.utilities import is_reform_active
from reforms.utilities import reform_is_active


def create_repeal_dependent_exemptions() -> Reform:
class exemptions_count(Variable):
Expand Down Expand Up @@ -28,7 +29,7 @@ def create_repeal_dependent_exemptions_reform(
return create_repeal_dependent_exemptions()

p = parameters.gov.contrib.treasury
reform_active = is_reform_active(p, period, "repeal_dependent_exemptions")
reform_active = reform_is_active(p, period, "repeal_dependent_exemptions")

if reform_active:
return create_repeal_dependent_exemptions()
Expand Down
9 changes: 6 additions & 3 deletions policyengine_us/reforms/utilities.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from policyengine_core.periods import period as period_

def is_reform_active(parameter, period, years_to_check=5, condition_attr='in_effect'):

def reform_is_active(
parameter, period, years_to_check=5, condition_attr="in_effect"
):
"""
Check if a reform is active within the specified number of years.
Expand All @@ -14,11 +17,11 @@ def is_reform_active(parameter, period, years_to_check=5, condition_attr='in_eff
bool: True if the reform is active within the specified years, False otherwise.
"""
current_period = period_(period)

for _ in range(years_to_check):
param_value = parameter(current_period)
if getattr(param_value, condition_attr, False):
return True
current_period = current_period.offset(1, "year")

return False

0 comments on commit cd45dd1

Please sign in to comment.