From dc5d6e7efee8c99c1f495933affb0fb5bbf28179 Mon Sep 17 00:00:00 2001 From: noman404 Date: Mon, 16 Dec 2024 22:48:45 +0800 Subject: [PATCH 1/9] updated logic for files separately special cases --- .../config/variable_mappings.yaml | 66 +++++++--- policyengine_taxsim/core/output_mapper.py | 117 +++++++++++++++--- 2 files changed, 154 insertions(+), 29 deletions(-) diff --git a/policyengine_taxsim/config/variable_mappings.yaml b/policyengine_taxsim/config/variable_mappings.yaml index 569d132..d98f539 100644 --- a/policyengine_taxsim/config/variable_mappings.yaml +++ b/policyengine_taxsim/config/variable_mappings.yaml @@ -357,8 +357,8 @@ policyengine_to_taxsim: full_text_group: "Federal Tax Calculation" group_column: 1 v30: - variable: na_pe - implemented: false + variable: household_net_income + implemented: true idtl: - full: 2 - full_text: 5 @@ -413,25 +413,43 @@ policyengine_to_taxsim: group_order: 4 full_text_group: "State Tax Calculation" group_column: 1 - special_cases: + pre_simulation: - ms: - implemented: false - variable: na_pe + implemented: true + pre_variable: ms_files_separately + variables: + - ms_standard_deduction_indiv + - ms_standard_deduction_joint - ar: - implemented: false - variable: na_pe + implemented: true + pre_variable: ar_files_separately + variables: + - ar_standard_deduction_indiv + - ar_standard_deduction_joint - mt: - implemented: false - variable: na_pe + implemented: true + pre_variable: mt_files_separately + variables: + - mt_standard_deduction_indiv + - mt_standard_deduction_joint - de: - implemented: false - variable: na_pe + implemented: true + pre_variable: de_files_separately + variables: + - de_standard_deduction_indiv + - de_standard_deduction_joint - ia: - implemented: false - variable: na_pe + implemented: true + pre_variable: ia_files_separately + variables: + - ia_standard_deduction_indiv + - ia_standard_deduction_joint - ky: - implemented: false - variable: na_pe + implemented: true + pre_variable: ky_files_separately + variables: + - ky_standard_deduction_indiv + - ky_standard_deduction_joint v35: variable: state_itemized_deductions implemented: true @@ -446,6 +464,9 @@ policyengine_to_taxsim: - il: implemented: false variable: na_pe + - ms: + implemented: false + variable: na_pe v36: variable: state_taxable_income implemented: true @@ -456,6 +477,10 @@ policyengine_to_taxsim: group_order: 4 full_text_group: "State Tax Calculation" group_column: 1 + special_cases: + - ms: + implemented: false + variable: na_pe tax_before_credits: variable: state_income_tax_before_non_refundable_credits implemented: true @@ -488,6 +513,9 @@ policyengine_to_taxsim: - mn: implemented: false variable: na_pe + - ms: + implemented: false + variable: na_pe rent_credit: variable: na_pe implemented: false @@ -522,6 +550,10 @@ policyengine_to_taxsim: group_order: 4 full_text_group: "State Tax Calculation" group_column: 1 + special_cases: + - ms: + implemented: false + variable: na_pe energy_fuel_credit: variable: na_pe implemented: false @@ -557,6 +589,10 @@ policyengine_to_taxsim: variables: - state_non_refundable_credit - state_refundable_credits + special_cases: + - ms: + implemented: false + variable: na_pe energy_fuel_credit2: variable: na_pe implemented: false diff --git a/policyengine_taxsim/core/output_mapper.py b/policyengine_taxsim/core/output_mapper.py index f1c7cff..7a432a6 100644 --- a/policyengine_taxsim/core/output_mapper.py +++ b/policyengine_taxsim/core/output_mapper.py @@ -9,6 +9,8 @@ def generate_non_description_output(taxsim_output, mappings, year, state_name, simulation, output_type, logs): outputs = [] for key, each_item in mappings.items(): + state_initial = state_name.lower() + if each_item['implemented']: if key == "taxsimid": taxsim_output[key] = taxsim_output["taxsimid"] @@ -18,10 +20,28 @@ def generate_non_description_output(taxsim_output, mappings, year, state_name, s taxsim_output[key] = get_state_number(state_name) elif 'variables' in each_item and len(each_item['variables']) > 0: pe_variables = each_item['variables'] - taxsim_output[key] = simulate_multiple(simulation, pe_variables, year) + + if 'special_cases' in each_item: + found_state = next((each for each in each_item['special_cases'] if state_initial in each), + None) + if found_state and found_state[state_initial]['implemented']: + pe_variable = found_state[state_initial]['variable'].replace("state", + state_initial) if "state" in \ + found_state[ + state_initial][ + 'variable'] else \ + found_state[state_initial]['variable'] + taxsim_output[key] = simulate(simulation, pe_variable, year) + + outputs.append({'variable': pe_variable, 'value': taxsim_output[key]}) + else: + taxsim_output[key] = simulate_multiple(simulation, pe_variables, year, state_initial) + + for pe_variable in pe_variables: + outputs.append({'variable': pe_variable, 'value': taxsim_output[key]}) + else: pe_variable = each_item['variable'] - state_initial = state_name.lower() if "state" in pe_variable: pe_variable = pe_variable.replace("state", state_initial) @@ -30,11 +50,40 @@ def generate_non_description_output(taxsim_output, mappings, year, state_name, s if output_type in entry.values(): if 'special_cases' in each_item: - found_state = next((each for each in each_item['special_cases'] if state_initial in each), None) + found_state = next((each for each in each_item['special_cases'] if state_initial in each), + None) if found_state and found_state[state_initial]['implemented']: - pe_variable = found_state[state_initial]['variable'].replace("state", state_initial) if "state" in found_state[state_initial]['variable'] else found_state[state_initial]['variable'] - taxsim_output[key] = simulate(simulation, pe_variable, year) - outputs.append({'variable': pe_variable, 'value': taxsim_output[key]}) + pe_variable = found_state[state_initial]['variable'].replace("state", + state_initial) if "state" in \ + found_state[ + state_initial][ + 'variable'] else \ + found_state[state_initial]['variable'] + taxsim_output[key] = simulate(simulation, pe_variable, year) + + outputs.append({'variable': pe_variable, 'value': taxsim_output[key]}) + + elif 'pre_simulation' in each_item: + found_state = next((each for each in each_item['pre_simulation'] if state_initial in each), + None) + if found_state and found_state[state_initial]['implemented']: + pre_simulation_variable = found_state[state_initial]['pre_variable'] + use_indiv = simulate_to_decide(simulation, pre_simulation_variable, year) + variables = found_state[state_initial]['variables'] + + if use_indiv: + pe_variable = variables[0] + else: + pe_variable = variables[1] + + taxsim_output[key] = simulate(simulation, pe_variable, year) + + outputs.append({'variable': pe_variable, 'value': taxsim_output[key]}) + + else: + taxsim_output[key] = simulate(simulation, pe_variable, year) + + outputs.append({'variable': pe_variable, 'value': taxsim_output[key]}) file_name = f"{taxsim_output['taxsimid']}-{state_name}.yaml" generate_pe_tests_yaml(simulation.situation_input, outputs, file_name, logs) @@ -120,14 +169,39 @@ def generate_text_description_output(taxsim_input, mappings, year, state_name, s elif var_name == "state": value = f"{get_state_number(state_name)}{' ' * LEFT_MARGIN}{state_name}" elif 'variables' in each_item and len(each_item['variables']) > 0: - value = simulate_multiple(simulation, each_item['variables'], year) + value = simulate_multiple(simulation, each_item['variables'], year, state_initial) else: if 'special_cases' in each_item: found_state = next((each for each in each_item['special_cases'] if state_initial in each), None) if found_state and found_state[state_initial]['implemented']: - variable = found_state[state_initial]['variable'].replace("state", state_initial) if "state" in found_state[state_initial]['variable'] else found_state[state_initial]['variable'] - value = simulate(simulation, variable, year) - outputs.append({'variable': variable, 'value': value}) + variable = found_state[state_initial]['variable'].replace("state", + state_initial) if "state" in \ + found_state[ + state_initial][ + 'variable'] else \ + found_state[state_initial]['variable'] + value = simulate(simulation, variable, year) + + outputs.append({'variable': variable, 'value': value}) + + elif 'pre_simulation' in each_item: + found_state = next((each for each in each_item['pre_simulation'] if state_initial in each), + None) + if found_state and found_state[state_initial]['implemented']: + pre_simulation_variable = found_state[state_initial]['pre_variable'] + use_indiv = simulate_to_decide(simulation, pre_simulation_variable, year) + variables = found_state[state_initial]['variables'] + print('use indiv', use_indiv) + if use_indiv: + value = simulate(simulation, variables[0], year) + else: + value = simulate(simulation, variables[1], year) + + outputs.append({'variable': variable, 'value': value}) + + else: + value = simulate(simulation, variable, year) + outputs.append({'variable': variable, 'value': value}) # Format the base value if isinstance(value, (int, float)): @@ -138,13 +212,18 @@ def generate_text_description_output(taxsim_input, mappings, year, state_name, s # Format second column value if needed if has_second_column: if 'variables' in each_item and len(each_item['variables']) > 0: - second_value = simulate_multiple(simulation_1dollar_more, each_item['variables'], year) + second_value = simulate_multiple(simulation_1dollar_more, each_item['variables'], year, state_initial) else: if 'special_cases' in each_item: found_state = next((each for each in each_item['special_cases'] if state_initial in each), None) if found_state and found_state[state_initial]['implemented']: - variable = found_state[state_initial]['variable'].replace("state", state_initial) if "state" in found_state[state_initial]['variable'] else found_state[state_initial]['variable'] + variable = found_state[state_initial]['variable'].replace("state", + state_initial) if "state" in \ + found_state[ + state_initial][ + 'variable'] else \ + found_state[state_initial]['variable'] second_value = simulate(simulation_1dollar_more, variable, year) if isinstance(second_value, (int, float)): @@ -318,12 +397,22 @@ def simulate(simulation, variable, year): try: return to_roundedup_number(simulation.calculate(variable, period=year)) except Exception as error: + print(error) return 0.00 -def simulate_multiple(simulation, variables, year): +def simulate_to_decide(simulation, variable, year) -> bool: + try: + return simulation.calculate(variable, period=year)[0] + except Exception as error: + print(error) + return False + + +def simulate_multiple(simulation, variables, year, state): try: - total = sum(to_roundedup_number(simulation.calculate(variable, period=year)) for variable in variables) + total = sum(to_roundedup_number(simulation.calculate(variable.replace("state", state), period=year)) for variable in variables) except Exception as error: + print(error) total = 0.00 return to_roundedup_number(total) From c4ab084bd98ca028de46b629d0f84db17d95aff3 Mon Sep 17 00:00:00 2001 From: noman404 Date: Wed, 18 Dec 2024 21:45:11 +0800 Subject: [PATCH 2/9] fix bug, added array sum --- policyengine_taxsim/core/output_mapper.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/policyengine_taxsim/core/output_mapper.py b/policyengine_taxsim/core/output_mapper.py index 7a432a6..0587035 100644 --- a/policyengine_taxsim/core/output_mapper.py +++ b/policyengine_taxsim/core/output_mapper.py @@ -395,7 +395,7 @@ def export_household(taxsim_input, policyengine_situation, logs): def simulate(simulation, variable, year): try: - return to_roundedup_number(simulation.calculate(variable, period=year)) + return to_roundedup_number(sum(simulation.calculate(variable, period=year))) except Exception as error: print(error) return 0.00 @@ -411,7 +411,12 @@ def simulate_to_decide(simulation, variable, year) -> bool: def simulate_multiple(simulation, variables, year, state): try: - total = sum(to_roundedup_number(simulation.calculate(variable.replace("state", state), period=year)) for variable in variables) + total = to_roundedup_number( + sum( + sum(simulation.calculate(variable.replace("state", state), period=year)) + for variable in variables + ) + ) except Exception as error: print(error) total = 0.00 From e1c904745aa218b19ca36b3139202b87509f2e68 Mon Sep 17 00:00:00 2001 From: noman404 Date: Fri, 20 Dec 2024 12:22:30 +0800 Subject: [PATCH 3/9] updated pre simulation case for state_itemized_deductions state_taxable_income state_income_tax_before_non_refundable_credits added special case for states which failed --- .../config/variable_mappings.yaml | 169 +++++++++++------- policyengine_taxsim/core/output_mapper.py | 14 +- 2 files changed, 111 insertions(+), 72 deletions(-) diff --git a/policyengine_taxsim/config/variable_mappings.yaml b/policyengine_taxsim/config/variable_mappings.yaml index d98f539..19f8a27 100644 --- a/policyengine_taxsim/config/variable_mappings.yaml +++ b/policyengine_taxsim/config/variable_mappings.yaml @@ -390,6 +390,9 @@ policyengine_to_taxsim: - mn: implemented: false variable: na_pe + - ia: + implemented: false + variable: na_pe - il: implemented: true variable: state_base_income @@ -460,13 +463,48 @@ policyengine_to_taxsim: group_order: 4 full_text_group: "State Tax Calculation" group_column: 1 + pre_simulation: + - ms: + implemented: true + pre_variable: ms_files_separately + variables: + - ms_itemized_deductions_indiv + - ms_itemized_deductions_joint + - ar: + implemented: true + pre_variable: ar_files_separately + variables: + - ar_itemized_deductions_indiv + - ar_itemized_deductions_joint + - mt: + implemented: true + pre_variable: mt_files_separately + variables: + - mt_itemized_deductions_indiv + - mt_itemized_deductions_joint + - ia: + implemented: true + pre_variable: ia_files_separately + variables: + - ia_itemized_deductions_indiv + - ia_itemized_deductions_joint + - ky: + implemented: true + pre_variable: ky_files_separately + variables: + - ky_itemized_deductions_indiv + - ky_itemized_deductions_joint special_cases: - il: implemented: false variable: na_pe - - ms: + - de: + implemented: false + variable: na_pe + - tx: implemented: false variable: na_pe + v36: variable: state_taxable_income implemented: true @@ -477,8 +515,39 @@ policyengine_to_taxsim: group_order: 4 full_text_group: "State Tax Calculation" group_column: 1 - special_cases: + pre_simulation: - ms: + implemented: true + pre_variable: ms_files_separately + variables: + - ms_taxable_income_indiv + - ms_taxable_income_joint + - ar: + implemented: true + pre_variable: ar_files_separately + variables: + - ar_taxable_income_indiv + - ar_taxable_income_joint + - mt: + implemented: true + pre_variable: mt_files_separately + variables: + - mt_taxable_income_indiv + - mt_taxable_income_joint + - ia: + implemented: true + pre_variable: ia_files_separately + variables: + - ia_taxable_income_indiv + - ia_taxable_income_joint + - ky: + implemented: true + pre_variable: ky_files_separately + variables: + - ky_taxable_income_indiv + - ky_taxable_income_joint + special_cases: + - de: implemented: false variable: na_pe tax_before_credits: @@ -490,6 +559,35 @@ policyengine_to_taxsim: group_order: 4 full_text_group: "State Tax Calculation" group_column: 1 + pre_simulation: + - ar: + implemented: true + pre_variable: ar_files_separately + variables: + - ar_income_tax_before_non_refundable_credits_indiv + - ar_income_tax_before_non_refundable_credits_joint + - mt: + implemented: true + pre_variable: mt_files_separately + variables: + - mt_income_tax_before_non_refundable_credits_indiv + - mt_income_tax_before_non_refundable_credits_joint + - ky: + implemented: true + pre_variable: ky_files_separately + variables: + - ky_income_tax_before_non_refundable_credits_indiv + - ky_income_tax_before_non_refundable_credits_joint + special_cases: + - ms: + implemented: false + variable: na_pe + - de: + implemented: false + variable: na_pe + - ia: + implemented: false + variable: na_pe v41: variable: na_pe implemented: false @@ -516,6 +614,9 @@ policyengine_to_taxsim: - ms: implemented: false variable: na_pe + - ia: + implemented: false + variable: na_pe rent_credit: variable: na_pe implemented: false @@ -896,67 +997,3 @@ taxsim_to_policyengine: - stcg - social_security_retirement: - gssi - -taxsim_input_definition: - - taxsimid: - name: "1. Record ID" - - year: - name: "2. Tax Year" - - state: - name: "3. State Code" - - mstat: - name: "4. Marital Status" - type: - - single: 1 - - joint: 2 - - page: - name: "5. Age (Txpyr/Spouse)" - pair: sage - - dependent_exemption: - name: "6. Dependent Exemptions" - - depx: - name: "8. #deps for CCC/CTC/EIC" - - pwages: - name: "9. Wages (Txpyr/Spouse)" - pair: swages - - psemp: - name: "10. Self-employment income" - pair: ssemp - - dividends: - name: "11. Dividend Income" - - intrec: - name: "12. Interest Received" - - stcg: - name: "13. Short Term Gains" - - ltcg: - name: "14. Long Term Gains" - - otherprop: - name: "15. Other Property" - - nonprop: - name: "16. Other Non-Property" - - pensions: - name: "17. Taxable Pensions" - - gssi: - name: "18. Gross Social Security" - - pui: - name: "19. Tot/Txpy/Spouse UI" - pair: sui - - transfers: - name: "20. Non-taxable Transfers" - - rentpaid: - name: "21. Rent Paid" - - proptax: - name: "22. Property Taxes Paid" - - otheritem: - name: "23. Other Itemized Deds" - - childcare: - name: "24. Child Care Expenses" - - mortgage: - name: "25. Mortgage Interest" - - scorp: - name: "26. S-Corp profits" - - pbusinc: - name: "27. Txpy/Spouse QBI w/o PO" - - pprofinc: - name: "28. Txpy/Spouse SSTB w PO" - diff --git a/policyengine_taxsim/core/output_mapper.py b/policyengine_taxsim/core/output_mapper.py index 0587035..882ce58 100644 --- a/policyengine_taxsim/core/output_mapper.py +++ b/policyengine_taxsim/core/output_mapper.py @@ -62,8 +62,9 @@ def generate_non_description_output(taxsim_output, mappings, year, state_name, s taxsim_output[key] = simulate(simulation, pe_variable, year) outputs.append({'variable': pe_variable, 'value': taxsim_output[key]}) + continue - elif 'pre_simulation' in each_item: + if 'pre_simulation' in each_item: found_state = next((each for each in each_item['pre_simulation'] if state_initial in each), None) if found_state and found_state[state_initial]['implemented']: @@ -183,8 +184,9 @@ def generate_text_description_output(taxsim_input, mappings, year, state_name, s value = simulate(simulation, variable, year) outputs.append({'variable': variable, 'value': value}) + continue - elif 'pre_simulation' in each_item: + if 'pre_simulation' in each_item: found_state = next((each for each in each_item['pre_simulation'] if state_initial in each), None) if found_state and found_state[state_initial]['implemented']: @@ -224,7 +226,8 @@ def generate_text_description_output(taxsim_input, mappings, year, state_name, s state_initial][ 'variable'] else \ found_state[state_initial]['variable'] - second_value = simulate(simulation_1dollar_more, variable, year) + second_value = simulate(simulation_1dollar_more, variable, year) + continue if isinstance(second_value, (int, float)): formatted_second_value = f"{second_value:>8.1f}" @@ -411,7 +414,7 @@ def simulate_to_decide(simulation, variable, year) -> bool: def simulate_multiple(simulation, variables, year, state): try: - total = to_roundedup_number( + return to_roundedup_number( sum( sum(simulation.calculate(variable.replace("state", state), period=year)) for variable in variables @@ -419,5 +422,4 @@ def simulate_multiple(simulation, variables, year, state): ) except Exception as error: print(error) - total = 0.00 - return to_roundedup_number(total) + return 0.00 From 83ec1d93b5183a607d6ebaf944e1308d1bfb6f3e Mon Sep 17 00:00:00 2001 From: noman404 Date: Fri, 27 Dec 2024 08:44:15 +0800 Subject: [PATCH 4/9] - variable adjustments - code cleanup --- .../config/variable_mappings.yaml | 34 +++++++++++-------- policyengine_taxsim/core/output_mapper.py | 3 -- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/policyengine_taxsim/config/variable_mappings.yaml b/policyengine_taxsim/config/variable_mappings.yaml index 19f8a27..6b75005 100644 --- a/policyengine_taxsim/config/variable_mappings.yaml +++ b/policyengine_taxsim/config/variable_mappings.yaml @@ -439,7 +439,7 @@ policyengine_to_taxsim: implemented: true pre_variable: de_files_separately variables: - - de_standard_deduction_indiv + - de_standard_deduction_indv - de_standard_deduction_joint - ia: implemented: true @@ -494,13 +494,16 @@ policyengine_to_taxsim: variables: - ky_itemized_deductions_indiv - ky_itemized_deductions_joint + - de: + implemented: true + pre_variable: de_files_separately + variables: + - de_itemized_deductions_indv + - de_itemized_deductions_joint special_cases: - il: implemented: false variable: na_pe - - de: - implemented: false - variable: na_pe - tx: implemented: false variable: na_pe @@ -546,10 +549,12 @@ policyengine_to_taxsim: variables: - ky_taxable_income_indiv - ky_taxable_income_joint - special_cases: - de: - implemented: false - variable: na_pe + implemented: true + pre_variable: de_files_separately + variables: + - de_taxable_income_indv + - de_taxable_income_joint tax_before_credits: variable: state_income_tax_before_non_refundable_credits implemented: true @@ -578,13 +583,16 @@ policyengine_to_taxsim: variables: - ky_income_tax_before_non_refundable_credits_indiv - ky_income_tax_before_non_refundable_credits_joint + - de: + implemented: true + pre_variable: de_files_separately + variables: + - de_income_tax_before_non_refundable_credits_indv + - de_income_tax_before_non_refundable_credits_joint special_cases: - ms: implemented: false variable: na_pe - - de: - implemented: false - variable: na_pe - ia: implemented: false variable: na_pe @@ -688,12 +696,8 @@ policyengine_to_taxsim: full_text_group: "State Tax Calculation" group_column: 1 variables: - - state_non_refundable_credit + - state_non_refundable_credits - state_refundable_credits - special_cases: - - ms: - implemented: false - variable: na_pe energy_fuel_credit2: variable: na_pe implemented: false diff --git a/policyengine_taxsim/core/output_mapper.py b/policyengine_taxsim/core/output_mapper.py index 882ce58..8d109cf 100644 --- a/policyengine_taxsim/core/output_mapper.py +++ b/policyengine_taxsim/core/output_mapper.py @@ -78,12 +78,10 @@ def generate_non_description_output(taxsim_output, mappings, year, state_name, s pe_variable = variables[1] taxsim_output[key] = simulate(simulation, pe_variable, year) - outputs.append({'variable': pe_variable, 'value': taxsim_output[key]}) else: taxsim_output[key] = simulate(simulation, pe_variable, year) - outputs.append({'variable': pe_variable, 'value': taxsim_output[key]}) file_name = f"{taxsim_output['taxsimid']}-{state_name}.yaml" @@ -193,7 +191,6 @@ def generate_text_description_output(taxsim_input, mappings, year, state_name, s pre_simulation_variable = found_state[state_initial]['pre_variable'] use_indiv = simulate_to_decide(simulation, pre_simulation_variable, year) variables = found_state[state_initial]['variables'] - print('use indiv', use_indiv) if use_indiv: value = simulate(simulation, variables[0], year) else: From e0a9329f0ea9984c0b97f87d4e8cc5ae7563ca73 Mon Sep 17 00:00:00 2001 From: noman404 Date: Mon, 30 Dec 2024 00:00:23 +0800 Subject: [PATCH 5/9] remove tx from this PR to move into #166 --- policyengine_taxsim/config/variable_mappings.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/policyengine_taxsim/config/variable_mappings.yaml b/policyengine_taxsim/config/variable_mappings.yaml index 6b75005..7e7c2a5 100644 --- a/policyengine_taxsim/config/variable_mappings.yaml +++ b/policyengine_taxsim/config/variable_mappings.yaml @@ -504,10 +504,6 @@ policyengine_to_taxsim: - il: implemented: false variable: na_pe - - tx: - implemented: false - variable: na_pe - v36: variable: state_taxable_income implemented: true From f2b29612df2c95e2cc9be318811cb98ca72981e4 Mon Sep 17 00:00:00 2001 From: noman404 Date: Thu, 2 Jan 2025 10:46:26 +0800 Subject: [PATCH 6/9] resolve merge conflicts --- policyengine_taxsim/config/variable_mappings.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/policyengine_taxsim/config/variable_mappings.yaml b/policyengine_taxsim/config/variable_mappings.yaml index 00da756..3560419 100644 --- a/policyengine_taxsim/config/variable_mappings.yaml +++ b/policyengine_taxsim/config/variable_mappings.yaml @@ -1061,5 +1061,4 @@ taxsim_input_definition: - pbusinc: name: "27. Txpy/Spouse QBI w/o PO" - pprofinc: - name: "28. Txpy/Spouse SSTB w PO" - + name: "28. Txpy/Spouse SSTB w PO" \ No newline at end of file From 75d00ae5f5dbf63eacd06f387b3baa221e94c43b Mon Sep 17 00:00:00 2001 From: noman404 Date: Thu, 2 Jan 2025 20:17:17 +0800 Subject: [PATCH 7/9] added states that does not have income tax and set them 0.0 --- .../config/variable_mappings.yaml | 22 +++++++++++++++++++ policyengine_taxsim/core/output_mapper.py | 10 ++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/policyengine_taxsim/config/variable_mappings.yaml b/policyengine_taxsim/config/variable_mappings.yaml index 3560419..7529066 100644 --- a/policyengine_taxsim/config/variable_mappings.yaml +++ b/policyengine_taxsim/config/variable_mappings.yaml @@ -54,6 +54,28 @@ policyengine_to_taxsim: group_order: 1 full_text_group: "Basic Output" group_column: 1 + special_cases: + - ak: + implemented: false + variable: na_pe + - fl: + implemented: false + variable: na_pe + - nv: + implemented: false + variable: na_pe + - sd: + implemented: false + variable: na_pe + - tn: + implemented: false + variable: na_pe + - tx: + implemented: false + variable: na_pe + - wy: + implemented: false + variable: na_pe fica: variable: multiple_variable implemented: true diff --git a/policyengine_taxsim/core/output_mapper.py b/policyengine_taxsim/core/output_mapper.py index 8d109cf..922268d 100644 --- a/policyengine_taxsim/core/output_mapper.py +++ b/policyengine_taxsim/core/output_mapper.py @@ -32,8 +32,11 @@ def generate_non_description_output(taxsim_output, mappings, year, state_name, s 'variable'] else \ found_state[state_initial]['variable'] taxsim_output[key] = simulate(simulation, pe_variable, year) - outputs.append({'variable': pe_variable, 'value': taxsim_output[key]}) + else: + taxsim_output[key] = 0.0 + outputs.append({'variable': 'n/a', 'value': taxsim_output[key]}) + else: taxsim_output[key] = simulate_multiple(simulation, pe_variables, year, state_initial) @@ -60,9 +63,10 @@ def generate_non_description_output(taxsim_output, mappings, year, state_name, s 'variable'] else \ found_state[state_initial]['variable'] taxsim_output[key] = simulate(simulation, pe_variable, year) - outputs.append({'variable': pe_variable, 'value': taxsim_output[key]}) - continue + else: + taxsim_output[key] = 0.0 + outputs.append({'variable': 'n/a', 'value': taxsim_output[key]}) if 'pre_simulation' in each_item: found_state = next((each for each in each_item['pre_simulation'] if state_initial in each), From e9a78e5729c773b6ec9e70d3c72dca7eb43eae8c Mon Sep 17 00:00:00 2001 From: noman404 Date: Sat, 4 Jan 2025 08:43:34 +0800 Subject: [PATCH 8/9] bug fix on normal variable calls after pre-simulation and special cases --- .../config/variable_mappings.yaml | 52 +++---------------- policyengine_taxsim/core/output_mapper.py | 10 ++-- 2 files changed, 13 insertions(+), 49 deletions(-) diff --git a/policyengine_taxsim/config/variable_mappings.yaml b/policyengine_taxsim/config/variable_mappings.yaml index 7529066..572fb26 100644 --- a/policyengine_taxsim/config/variable_mappings.yaml +++ b/policyengine_taxsim/config/variable_mappings.yaml @@ -58,9 +58,6 @@ policyengine_to_taxsim: - ak: implemented: false variable: na_pe - - fl: - implemented: false - variable: na_pe - nv: implemented: false variable: na_pe @@ -73,9 +70,15 @@ policyengine_to_taxsim: - tx: implemented: false variable: na_pe + - fl: + implemented: false + variable: na_pe - wy: implemented: false variable: na_pe + - wa: + implemented: false + variable: na_pe fica: variable: multiple_variable implemented: true @@ -408,16 +411,6 @@ policyengine_to_taxsim: group_order: 4 full_text_group: "State Tax Calculation" group_column: 1 - special_cases: - - mn: - implemented: false - variable: na_pe - - ia: - implemented: false - variable: na_pe - - il: - implemented: true - variable: state_base_income v33: variable: state_exemptions implemented: false @@ -522,10 +515,6 @@ policyengine_to_taxsim: variables: - de_itemized_deductions_indv - de_itemized_deductions_joint - special_cases: - - il: - implemented: false - variable: na_pe v36: variable: state_taxable_income implemented: true @@ -607,13 +596,6 @@ policyengine_to_taxsim: variables: - de_income_tax_before_non_refundable_credits_indv - de_income_tax_before_non_refundable_credits_joint - special_cases: - - ms: - implemented: false - variable: na_pe - - ia: - implemented: false - variable: na_pe v41: variable: na_pe implemented: false @@ -633,16 +615,6 @@ policyengine_to_taxsim: group_order: 4 full_text_group: "State Tax Calculation" group_column: 1 - special_cases: - - mn: - implemented: false - variable: na_pe - - ms: - implemented: false - variable: na_pe - - ia: - implemented: false - variable: na_pe rent_credit: variable: na_pe implemented: false @@ -663,10 +635,6 @@ policyengine_to_taxsim: group_order: 4 full_text_group: "State Tax Calculation" group_column: 1 - special_cases: - - il: - implemented: false - variable: na_pe v39: variable: state_eitc implemented: true @@ -677,10 +645,6 @@ policyengine_to_taxsim: group_order: 4 full_text_group: "State Tax Calculation" group_column: 1 - special_cases: - - ms: - implemented: false - variable: na_pe energy_fuel_credit: variable: na_pe implemented: false @@ -699,10 +663,6 @@ policyengine_to_taxsim: group_order: 4 full_text_group: "State Tax Calculation" group_column: 1 - special_cases: - - mn: - implemented: false - variable: na_pe v40: variable: multiple_variables implemented: true diff --git a/policyengine_taxsim/core/output_mapper.py b/policyengine_taxsim/core/output_mapper.py index 922268d..f9f3c21 100644 --- a/policyengine_taxsim/core/output_mapper.py +++ b/policyengine_taxsim/core/output_mapper.py @@ -51,20 +51,23 @@ def generate_non_description_output(taxsim_output, mappings, year, state_name, s for entry in each_item['idtl']: if output_type in entry.values(): + state_found = False if 'special_cases' in each_item: found_state = next((each for each in each_item['special_cases'] if state_initial in each), None) if found_state and found_state[state_initial]['implemented']: + state_found = True pe_variable = found_state[state_initial]['variable'].replace("state", state_initial) if "state" in \ found_state[ state_initial][ 'variable'] else \ - found_state[state_initial]['variable'] + found_state[state_initial]['variable'] taxsim_output[key] = simulate(simulation, pe_variable, year) outputs.append({'variable': pe_variable, 'value': taxsim_output[key]}) - else: + elif found_state and not found_state[state_initial]['implemented']: + state_found = True taxsim_output[key] = 0.0 outputs.append({'variable': 'n/a', 'value': taxsim_output[key]}) @@ -72,6 +75,7 @@ def generate_non_description_output(taxsim_output, mappings, year, state_name, s found_state = next((each for each in each_item['pre_simulation'] if state_initial in each), None) if found_state and found_state[state_initial]['implemented']: + state_found = True pre_simulation_variable = found_state[state_initial]['pre_variable'] use_indiv = simulate_to_decide(simulation, pre_simulation_variable, year) variables = found_state[state_initial]['variables'] @@ -84,7 +88,7 @@ def generate_non_description_output(taxsim_output, mappings, year, state_name, s taxsim_output[key] = simulate(simulation, pe_variable, year) outputs.append({'variable': pe_variable, 'value': taxsim_output[key]}) - else: + if not state_found: taxsim_output[key] = simulate(simulation, pe_variable, year) outputs.append({'variable': pe_variable, 'value': taxsim_output[key]}) From 05754f63122fcb279089067142d27dda47add6dd Mon Sep 17 00:00:00 2001 From: noman404 Date: Mon, 6 Jan 2025 20:16:38 +0800 Subject: [PATCH 9/9] added special cases for state_agi --- policyengine_taxsim/config/variable_mappings.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/policyengine_taxsim/config/variable_mappings.yaml b/policyengine_taxsim/config/variable_mappings.yaml index 572fb26..2915303 100644 --- a/policyengine_taxsim/config/variable_mappings.yaml +++ b/policyengine_taxsim/config/variable_mappings.yaml @@ -411,6 +411,13 @@ policyengine_to_taxsim: group_order: 4 full_text_group: "State Tax Calculation" group_column: 1 + special_cases: + - il: + implemented: true + variable: il_base_income + - ia: + implemented: true + variable: ia_gross_income v33: variable: state_exemptions implemented: false