Skip to content

Commit

Permalink
Merge pull request #331 from hdoupe/check-reform-format2
Browse files Browse the repository at this point in the history
Check if reform is paramtools or tc style
  • Loading branch information
jdebacker committed Nov 30, 2020
2 parents 9e650da + f9b1234 commit 4a7911f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
34 changes: 33 additions & 1 deletion ccc/get_taxcalc_rates.py
Expand Up @@ -47,7 +47,7 @@ def get_calculator(baseline, calculator_start_year, reform=None,
assert not reform

if not baseline:
policy1.implement_reform(reform)
update_policy(policy1, reform)

# the default set up increments year to 2013
calc1 = Calculator(records=records1, policy=policy1)
Expand Down Expand Up @@ -152,3 +152,35 @@ def get_rates(baseline=False, start_year=DEFAULT_START_YEAR, reform={},

print(individual_rates)
return individual_rates


def update_policy(policy_obj, reform, **kwargs):
"""
Convenience method that updates the Policy object with the reform
dict using the appropriate method, given the reform format.
"""
if is_paramtools_format(reform):
policy_obj.adjust(reform, **kwargs)
else:
policy_obj.implement_reform(reform, **kwargs)


def is_paramtools_format(reform):
"""
Check first item in reform to determine if it is using the ParamTools
adjustment or the Tax-Calculator reform format.
If first item is a dict, then it is likely be a Tax-Calculator reform:
{
param: {2020: 1000}
}
Otherwise, it is likely to be a ParamTools format.
Returns:
format (bool): True if reform is likely to be in PT format.
"""
for _, data in reform.items():
if isinstance(data, dict):
return False # taxcalc reform
else:
# Not doing a specific check to see if the value is a list
# since it could be a list or just a scalar value.
return True
20 changes: 18 additions & 2 deletions cs-config/cs_config/tests/test_functions.py
Expand Up @@ -10,8 +10,24 @@ class TestFunctions1(CoreTestFunctions):
get_inputs = functions.get_inputs
validate_inputs = functions.validate_inputs
run_model = functions.run_model
ok_adjustment = {"Business Tax Parameters": {"CIT_rate": 0.21},
"Individual and Payroll Tax Parameters": {}}
ok_adjustment = {
"Business Tax Parameters": {
"CIT_rate": [
{
"year": 2021,
"value": 0.25
}
]
},
"Individual and Payroll Tax Parameters": {
"FICA_ss_trt": [
{
"year": 2021,
"value": 0.14
}
]
}
}
bad_adjustment = {"Business Tax Parameters": {"CIT_rate": -0.1},
"Individual and Payroll Tax Parameters": {"STD": -1}}

Expand Down

0 comments on commit 4a7911f

Please sign in to comment.