From 874fd38126f4629b4700123946a545443eb7e675 Mon Sep 17 00:00:00 2001 From: "martin.holmer@gmail.com" Date: Tue, 12 Mar 2024 09:32:36 -0400 Subject: [PATCH 1/6] Refactor ppp.py script so that it does not crash --- ppp.py | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) 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) From cb2a220b52d61aca2f4433b918d1405837ec2ff4 Mon Sep 17 00:00:00 2001 From: "martin.holmer@gmail.com" Date: Tue, 12 Mar 2024 09:36:43 -0400 Subject: [PATCH 2/6] Add decimals to values of new Capital_loss_limitation float parameter --- taxcalc/policy_current_law.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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": { From 62c8d33dcd9cbdfe8d011cf523df1829e26940e1 Mon Sep 17 00:00:00 2001 From: "martin.holmer@gmail.com" Date: Tue, 12 Mar 2024 11:31:47 -0400 Subject: [PATCH 3/6] Skip ppp.py for testing and code coverage --- pytest.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pytest.ini b/pytest.ini index ee526e3b5..9192090c1 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,6 +1,8 @@ [pytest] testpaths = taxcalc +omit = + ./ppp.py markers = requires_pufcsv pre_release From 7fed126db53b8972146bf60fac9159782af54ff7 Mon Sep 17 00:00:00 2001 From: "martin.holmer@gmail.com" Date: Tue, 12 Mar 2024 11:32:34 -0400 Subject: [PATCH 4/6] Remove obsolete ./new_json.py script. --- new_json.py | 70 ----------------------------------------------------- 1 file changed, 70 deletions(-) delete mode 100644 new_json.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()) From 5afe43d1945a3c601dfdcc574a4c083616a643eb Mon Sep 17 00:00:00 2001 From: "martin.holmer@gmail.com" Date: Tue, 12 Mar 2024 12:16:35 -0400 Subject: [PATCH 5/6] Ignore ppp.py in codecov.yml file --- codecov.yml | 2 +- pytest.ini | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/codecov.yml b/codecov.yml index 38c9a93de..460bf78e6 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" \ No newline at end of file diff --git a/pytest.ini b/pytest.ini index 9192090c1..ee526e3b5 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,8 +1,6 @@ [pytest] testpaths = taxcalc -omit = - ./ppp.py markers = requires_pufcsv pre_release From a8ac3d05273aaa7b44c2c3476d8d39270a4c6f6f Mon Sep 17 00:00:00 2001 From: "martin.holmer@gmail.com" Date: Tue, 12 Mar 2024 12:41:25 -0400 Subject: [PATCH 6/6] Add newline character at end of codecov.yml file --- codecov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codecov.yml b/codecov.yml index 460bf78e6..16a28e695 100644 --- a/codecov.yml +++ b/codecov.yml @@ -21,4 +21,4 @@ comment: ignore: - "setup.py" - - "ppp.py" \ No newline at end of file + - "ppp.py"