diff --git a/codecov.yml b/codecov.yml index 38c9a93de..16a28e695 100644 --- a/codecov.yml +++ b/codecov.yml @@ -21,4 +21,4 @@ comment: ignore: - "setup.py" - - "new_json.py" \ No newline at end of file + - "ppp.py" diff --git a/new_json.py b/new_json.py deleted file mode 100644 index 8c88942fe..000000000 --- a/new_json.py +++ /dev/null @@ -1,70 +0,0 @@ -""" -Command-line tool that converts Tax-Calculator JSON reform/assumption file -from the old (1.x) format to the new (2.0+) format. ------------------------------------------------------------------------- -WARNING: This program make certain assumptions about how the JSON file - is formatted, so it will not work correctly on a JSON file - that is not formatted in the assumed way. There is no risk - in trying it because a copy of the original JSON file is made. ------------------------------------------------------------------------- -""" -# CODING-STYLE CHECKS: -# pycodestyle new_json.py -# pylint --disable=locally-disabled new_json.py - -import os -import sys -import argparse -import shutil -import re - - -def main(): - """ - Contains high-level logic. - """ - # parse command-line argument: - usage_str = 'python new_json.py FILENAME [--help]' - parser = argparse.ArgumentParser( - prog='', - usage=usage_str, - description=('Converts old (1.x) JSON reform/assumption file ' - 'named FILENAME to new (2.0) format. The newly ' - 'formatted file is also called FILENAME, while ' - 'the old file is saved as FILENAME-old.') - ) - parser.add_argument('FILENAME', nargs='?', - help=('FILENAME is name of JSON-formatted file that ' - 'is to be converted.'), - default='') - args = parser.parse_args() - # check existence of FILENAME - if not os.path.isfile(args.FILENAME): - msg = 'ERROR: FILENAME={} does not exist'.format(args.FILENAME) - print(msg) - return 1 - # copy FILENAME to FILENAME-old - shutil.copyfile(args.FILENAME, '{}-old'.format(args.FILENAME)) - # read FILENAME into string - with open(args.FILENAME, 'r') as oldfile: - txt = oldfile.read() - # convert txt elements - defaults_file = (args.FILENAME == 'policy_current_law.json' or - args.FILENAME == 'consumption.json' or - args.FILENAME == 'growdiff.json') - if defaults_file: - txt = re.sub(r'(^\s*")_', r'\g<1>', txt, flags=re.MULTILINE) - else: - txt = re.sub(r'(\s*")_', r'\g<1>', txt, flags=re.MULTILINE) - txt = re.sub(r'\[([0-9tf\-])', r'\g<1>', txt, flags=re.MULTILINE) - txt = re.sub(r'([0-9e])\]', r'\g<1>', txt, flags=re.MULTILINE) - # write converted txt to FILENAME - with open(args.FILENAME, 'w') as newfile: - newfile.write(txt) - # normal return code - return 0 -# end of main function code - - -if __name__ == '__main__': - sys.exit(main()) diff --git a/ppp.py b/ppp.py index a54d0cb66..210bcefb5 100644 --- a/ppp.py +++ b/ppp.py @@ -7,10 +7,13 @@ USAGE: $ python ppp.py Note: running this script will write the new 2026 parameter values -directly to policy_current_law.json. +directly to policy_current_law.json. So, if you want to compare +the new 2026 parameter values with the old 2026 parameter values, +be sure to copy policy_current_law.json before running this script. """ -from taxcalc import * import json +import collections +from taxcalc import Policy params = Policy() @@ -27,29 +30,30 @@ # calculate the inflation factor used to calculate the # inflation-adjusted 2026 parameter values -final_ifactor = 1.0 -pyear = 2017 # prior year before TCJA first implemented -fyear = 2026 # final year in which parameter values revert to +FINAL_IFACTOR = 1.0 +PYEAR = 2017 # prior year before TCJA first implemented +FYEAR = 2026 # final year in which parameter values revert to # pre-TCJA values # construct final-year inflation factor from prior year # NOTE: pvalue[t+1] = pvalue[t] * ( 1 + irate[t] ) -for year in range(pyear, fyear): - final_ifactor *= 1 + \ - params._inflation_rates[year - params.start_year] +for year in range(PYEAR, FYEAR): + yindex = year - params.start_year + rate = params._inflation_rates[yindex] # pylint: disable=protected-access + FINAL_IFACTOR *= 1 + rate -long_param_vals = defaultdict(list) +long_param_vals = collections.defaultdict(list) for param in long_params: - vos = params.select_eq(param, year=pyear) - # use final_ifactor to inflate from 2017 to 2026 + vos = params.select_eq(param, year=PYEAR) + # use FINAL_IFACTOR to inflate from 2017 to 2026 for vo in vos: long_param_vals[param].append( - # Create new dict to avoid modifying the original + # create new dict to avoid modifying the original dict( vo, value=min(9e99, round( - vo["value"] * final_ifactor, 0)), - year=fyear, + vo["value"] * FINAL_IFACTOR, 0)), + year=FYEAR, ) ) @@ -60,13 +64,13 @@ meta_data=False, serializable=True, use_state=False, _auto=False) # read existing policy_current_law.json -with open('taxcalc/policy_current_law.json', 'r') as f: - pcl = json.load(f) +with open('taxcalc/policy_current_law.json', 'r', encoding='utf-8') as pcl_old: + pcl = json.load(pcl_old) -# replace 2026 values in policy_current_law.json +# replace 2026 values in the pcl dictionary for param in param_data: pcl[param]["value"] = param_data[param] -# write new policy_current_law.json -with open('taxcalc/policy_current_law.json', 'w') as pcl_old: - json.dump(pcl, pcl_old, indent=4) +# write new pcl dictionary to policy_current_law.json +with open('taxcalc/policy_current_law.json', 'w', encoding='utf-8') as pcl_new: + json.dump(pcl, pcl_new, indent=4) diff --git a/taxcalc/policy_current_law.json b/taxcalc/policy_current_law.json index cd8d8303e..e3ebe2522 100644 --- a/taxcalc/policy_current_law.json +++ b/taxcalc/policy_current_law.json @@ -7081,27 +7081,27 @@ { "year": 2013, "MARS": "single", - "value": 3000 + "value": 3000.0 }, { "year": 2013, "MARS": "mjoint", - "value": 3000 + "value": 3000.0 }, { "year": 2013, "MARS": "mseparate", - "value": 3000 + "value": 3000.0 }, { "year": 2013, "MARS": "headhh", - "value": 3000 + "value": 3000.0 }, { "year": 2013, "MARS": "widow", - "value": 3000 + "value": 3000.0 } ], "validators": {