Skip to content

Commit

Permalink
Updated test_microsim.py
Browse files Browse the repository at this point in the history
  • Loading branch information
rickecon committed May 10, 2024
1 parent 70810f1 commit 2a41703
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
37 changes: 29 additions & 8 deletions fiscalsim_us/tests/microsimulation/test_microsim.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
def test_microsim_runs_cps():
import numpy as np
from fiscalsim_us import Microsimulation
import numpy as np
from fiscalsim_us import Microsimulation
from policyengine_core.reforms import Reform
from policyengine_core.periods import instant

"""
In US nationwide simulations, use reported state income tax liabilities
"""
def use_reported_state_income_tax(parameters):
parameters.simulation.reported_state_income_tax.update(
start=instant("2024-01-01"), stop=instant("2100-12-31"),
value=True)
return parameters


sim = Microsimulation()
hnet = sim.calc("household_net_income")
class baseline_reform(Reform):
def apply(self):
self.modify_parameters(use_reported_state_income_tax)


def test_microsim_runs_cps():
sim = Microsimulation(reform=baseline_reform)
hnet = sim.calc("household_net_income", period=2024, map_to="person")
assert not hnet.isna().any(), "Some households have NaN net income."
hidecile = sim.calc("household_income_decile")
hidecile = sim.calc(
"household_income_decile", period=2024, map_to="person"
)
assert np.all(hidecile >= 1) and np.all(hidecile <= 10)
sidecile = sim.calc("spm_unit_income_decile")
sidecile = sim.calc(
"spm_unit_income_decile", period=2024, map_to="person"
)
assert np.all(sidecile >= 1) and np.all(sidecile <= 10)
idecile = sim.calc("income_decile")
idecile = sim.calc("income_decile", period=2024, map_to="person")
assert np.all(idecile >= 1) and np.all(idecile <= 10)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class mn_subtractions(Variable):
"""
Line 7 of form M1 (2023)
"""

value_type = float
entity = TaxUnit
label = "Minnesota subtractions from federal AGI"
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"click==8.1.3",
"h5py",
"microdf_python",
"numpy>=1.24, <1.25",
"numpy>=1.24",
"scipy==1.10.1",
"pandas",
"pathlib",
"policyengine-core>=2.8,<2.9",
Expand Down

0 comments on commit 2a41703

Please sign in to comment.