Skip to content

Commit

Permalink
Merge pull request PolicyEngine#41 from noman404/noman404/issue27
Browse files Browse the repository at this point in the history
issue fix PolicyEngine#27 - returning taxsimid passed in csv
  • Loading branch information
noman404 authored Oct 23, 2024
2 parents 5aa1991 + ee66d3f commit 9b631aa
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions output/policyengine_taxsim_output.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
taxsimid,year,state,mstat,page,sage,fiitax,siitax,fica
1,2021,3,1,40,0,2775.0,1008.87,3748.5
1,2021,3,1,40,0,2535.0,942.07,3595.5
999,2021,3,1,40,0,2775.0,1008.87,3748.5
11,2021,3,1,40,0,2535.0,942.07,3595.5
4 changes: 2 additions & 2 deletions output/taxsim35_output.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
taxsimid,year,state,fiitax,siitax,fica,frate,srate,ficar,tfica,credits,v10,v11,v12,v13,v14,v15,v16,v17,v18,v19,v20, v21,v22,v23,v24,v25,v26,v27,v28,v29,v30,v31,v32,v33,v34, v35,v36,v37,v38,v39,v40,v41,staxbc,v42,v43,v44,v45
1.,2021,3,2775.00,1008.87,7497.00,12.00,3.34,15.30,3748.50,.00,49000.00,.00,.00,12550.00,.00,.00,.00,.00,36450.00,4175.00,.00,.00,.00,.00,.00,.00,49000.00,.00,4175.00,7497.00,49000.01,.00,49000.01,.00,12550.00,1008.87,36450.01,.00,.00,.00,.00,3.34,.00,.00,.00,.00,1400.00
1.,2021,3,2535.00,942.07,7191.00,12.00,3.34,15.30,3595.50,.00,47000.00,.00,.00,12550.00,.00,.00,.00,.00,34450.00,3935.00,.00,.00,.00,.00,.00,.00,47000.00,.00,3935.00,7191.00,47001.01,.00,47000.01,.00,12550.00,942.07,34450.01,.00,.00,.00,.00,3.34,.00,.00,.00,.00,1400.00
999.,2021,3,2775.00,1008.87,7497.00,12.00,3.34,15.30,3748.50,.00,49000.00,.00,.00,12550.00,.00,.00,.00,.00,36450.00,4175.00,.00,.00,.00,.00,.00,.00,49000.00,.00,4175.00,7497.00,49000.01,.00,49000.01,.00,12550.00,1008.87,36450.01,.00,.00,.00,.00,3.34,.00,.00,.00,.00,1400.00
11.,2021,3,2535.00,942.07,7191.00,12.00,3.34,15.30,3595.50,.00,47000.00,.00,.00,12550.00,.00,.00,.00,.00,34450.00,3935.00,.00,.00,.00,.00,.00,.00,47000.00,.00,3935.00,7191.00,47001.01,.00,47000.01,.00,12550.00,942.07,34450.01,.00,.00,.00,.00,3.34,.00,.00,.00,.00,1400.00
2 changes: 1 addition & 1 deletion policyengine_taxsim/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def main(input_file, output):
for _, row in df.iterrows():
taxsim_input = row.to_dict()
pe_situation = import_single_household(taxsim_input)
taxsim_output = export_single_household(pe_situation)
taxsim_output = export_single_household(taxsim_input, pe_situation)
results.append(taxsim_output)

# Create output dataframe and save to csv
Expand Down
4 changes: 2 additions & 2 deletions policyengine_taxsim/core/output_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from policyengine_us import Simulation


def export_single_household(policyengine_situation):
def export_single_household(taxsim_input, policyengine_situation):
"""
Convert a PolicyEngine situation to TAXSIM output variables.
Expand All @@ -29,7 +29,7 @@ def export_single_household(policyengine_situation):
][year]

taxsim_output = {
"taxsimid": policyengine_situation.get("taxsimid", 1),
"taxsimid": policyengine_situation.get("taxsimid", taxsim_input['taxsimid']),
"year": int(year),
"state": get_state_number(state_name),
"mstat": policyengine_situation["tax_units"]["your tax unit"]
Expand Down
4 changes: 2 additions & 2 deletions resources/taxsim35/taxsim_input.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
year,state,depx,pwages,mstat,mortgage,taxsimid,idtl
2021,3,0,49000,1,0,1,2
2021,3,0,47000,1,0,1,2
2021,3,0,49000,1,0,999,2
2021,3,0,47000,1,0,11,2
15 changes: 12 additions & 3 deletions tests/test_mappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def test_import_single_household():
"state": 6, # Colorado
"page": 35,
"pwages": 50000,
"taxsimid": 999
}

expected_output = {
Expand All @@ -29,6 +30,14 @@ def test_import_single_household():


def test_export_single_household():
taxsim_input = {
"year": 2022,
"state": 6, # Colorado
"page": 35,
"pwages": 50000,
"taxsimid": 999
}

policyengine_situation = {
"people": {
"you": {"age": {"2022": 35}, "employment_income": {"2022": 50000}}
Expand All @@ -42,7 +51,7 @@ def test_export_single_household():
"tax_units": {"your tax unit": {"members": ["you"]}},
}

result = export_single_household(policyengine_situation)
result = export_single_household(taxsim_input, policyengine_situation)

assert result["year"] == 2022
assert result["state"] == 6 # Colorado
Expand All @@ -54,15 +63,15 @@ def test_export_single_household():

@pytest.fixture
def sample_taxsim_input():
return {"year": 2022, "state": 6, "page": 35, "pwages": 50000} # Colorado
return {"year": 2022, "state": 6, "page": 35, "pwages": 50000, "taxsimid": 999} # Colorado


def test_roundtrip(sample_taxsim_input):
# Import TAXSIM input to PolicyEngine situation
pe_situation = import_single_household(sample_taxsim_input)

# Export PolicyEngine situation back to TAXSIM output
taxsim_output = export_single_household(pe_situation)
taxsim_output = export_single_household(sample_taxsim_input, pe_situation)

# Check that key information is preserved
assert taxsim_output["year"] == sample_taxsim_input["year"]
Expand Down

0 comments on commit 9b631aa

Please sign in to comment.