Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide simpler syntax to specify policy reforms and assumption updates #2292

Merged
merged 31 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
32378fe
Revise code & most tests to work with no-underscore param names
martinholmer Apr 6, 2019
d39222c
Strengthen testing of Policy.metadata method
martinholmer Apr 6, 2019
2616f29
Change parameter indexing suffix from _cps to _indexed
martinholmer Apr 6, 2019
ecb75b1
Require brackets for only vector-valued parameters
martinholmer Apr 6, 2019
ab3f0e9
Change _indexed suffix to -indexed
martinholmer Apr 7, 2019
0430812
Add tests of improper use of -indexed suffix
martinholmer Apr 7, 2019
dd6c224
Rename cpi_offset to CPI_offset; fix Calculator.reform_documentation
martinholmer Apr 7, 2019
bab76fe
Add tests to increase coverage
martinholmer Apr 7, 2019
84f6847
Generalize REMOVED_PARAMS to be dict in order to handle renames
martinholmer Apr 8, 2019
a695fd5
Update taxcalc/assumptions/economic_assumptions_template.json
martinholmer Apr 8, 2019
668db9f
Improved removed/renamed parameter error messages
martinholmer Apr 8, 2019
f749542
Fix PEP8 spacing problems
martinholmer Apr 8, 2019
22213bf
Fix another PEP8 spacing problem
martinholmer Apr 8, 2019
3aa9d42
Move attributes to Parameters class
martinholmer Apr 9, 2019
ef7d7d8
Use new Parameter attributes
martinholmer Apr 9, 2019
d74e990
Move CPI_offset logic to Parameters class
martinholmer Apr 9, 2019
edd4da6
Move most of Policy.implement_reform logic to Parameters._update method
martinholmer Apr 9, 2019
7aade04
Use new Parameters._update method in Consumption/GrowDiff classes
martinholmer Apr 9, 2019
eb3edac
Add test to increase code coverage
martinholmer Apr 9, 2019
9f52a13
No optional arguments in Parameters._update method
martinholmer Apr 9, 2019
89e2381
Revise Parameters._update to use param:year:value revision format
martinholmer Apr 9, 2019
46ca26b
Revise code in test_parameters.py
martinholmer Apr 10, 2019
b861244
Revise Calculator.read_json_* methods
martinholmer Apr 10, 2019
dd9db85
pytest-cps tests pass
martinholmer Apr 10, 2019
1913bcd
pytest tests all pass
martinholmer Apr 10, 2019
cd8a392
Expand scope of test_parameters.py tests
martinholmer Apr 11, 2019
18ff102
Streamline JSON files with parameter defaults
martinholmer Apr 11, 2019
92985a8
Make several JSON defaults fields optional
martinholmer Apr 11, 2019
fc6ebf5
Add tests to regain complete code coverage
martinholmer Apr 11, 2019
5c79fe6
Rename several JSON defaults fields
martinholmer Apr 11, 2019
257d9d4
Shorten the vector index names
martinholmer Apr 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/make_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def policy_param_text(pname, param):
else:
txt += '<br><i>Long Name:</i> {}'.format(param['long_name'])
txt += '<br><i>Description:</i> {}'.format(param['description'])
if len(param['notes']) > 0:
if len(param.get('notes', '')) > 0:
txt += '<br><i>Notes:</i> {}'.format(param['notes'])
txt += '<br><i>Has An Effect When Using:</i>'
txt += '&nbsp;&nbsp; <i>PUF data:</i> '
Expand Down Expand Up @@ -118,8 +118,8 @@ def policy_param_text(pname, param):
minval = param['valid_values']['min']
maxval = param['valid_values']['max']
txt += ' min = {} and max = {}'.format(minval, maxval)
txt += '<br><i>Out-of-Range Action:</i> {}'.format(
param['invalid_action'])
invalid_action = param.get('invalid_action', 'stop')
txt += '<br><i>Out-of-Range Action:</i> {}'.format(invalid_action)
txt += '</p>'
return txt

Expand Down
70 changes: 70 additions & 0 deletions new_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
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())
124 changes: 62 additions & 62 deletions taxcalc/assumptions/economic_assumptions_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,71 +7,71 @@
// <http://PSLmodels.github.io/Tax-Calculator/#params>.
{
"consumption": {
"_MPC_e17500": {"2017": [0.0]},
"_MPC_e18400": {"2017": [0.0]},
"_MPC_e19800": {"2017": [0.0]},
"_MPC_e20400": {"2017": [0.0]},
"_BEN_housing_value": {"2017": [1.0]},
"_BEN_snap_value": {"2017": [1.0]},
"_BEN_tanf_value": {"2017": [1.0]},
"_BEN_vet_value": {"2017": [1.0]},
"_BEN_wic_value": {"2017": [1.0]},
"_BEN_mcare_value": {"2017": [1.0]},
"_BEN_mcaid_value": {"2017": [1.0]},
"_BEN_other_value": {"2017": [1.0]}
"MPC_e17500": {"2017": 0.0},
"MPC_e18400": {"2017": 0.0},
"MPC_e19800": {"2017": 0.0},
"MPC_e20400": {"2017": 0.0},
"BEN_housing_value": {"2017": 1.0},
"BEN_snap_value": {"2017": 1.0},
"BEN_tanf_value": {"2017": 1.0},
"BEN_vet_value": {"2017": 1.0},
"BEN_wic_value": {"2017": 1.0},
"BEN_mcare_value": {"2017": 1.0},
"BEN_mcaid_value": {"2017": 1.0},
"BEN_other_value": {"2017": 1.0}
},
"growdiff_baseline": {
"_ABOOK": {"2017": [0.0]},
"_ACGNS": {"2017": [0.0]},
"_ACPIM": {"2017": [0.0]},
"_ACPIU": {"2017": [0.0]},
"_ADIVS": {"2017": [0.0]},
"_AINTS": {"2017": [0.0]},
"_AIPD": {"2017": [0.0]},
"_ASCHCI": {"2017": [0.0]},
"_ASCHCL": {"2017": [0.0]},
"_ASCHEI": {"2017": [0.0]},
"_ASCHEL": {"2017": [0.0]},
"_ASCHF": {"2017": [0.0]},
"_ASOCSEC": {"2017": [0.0]},
"_ATXPY": {"2017": [0.0]},
"_AUCOMP": {"2017": [0.0]},
"_AWAGE": {"2017": [0.0]},
"_ABENOTHER": {"2017": [0.0]},
"_ABENMCARE": {"2017": [0.0]},
"_ABENMCAID": {"2017": [0.0]},
"_ABENSSI": {"2017": [0.0]},
"_ABENSNAP": {"2017": [0.0]},
"_ABENWIC": {"2017": [0.0]},
"_ABENHOUSING": {"2017": [0.0]},
"_ABENTANF": {"2017": [0.0]},
"_ABENVET": {"2017": [0.0]}
"ABOOK": {"2017": 0.0},
"ACGNS": {"2017": 0.0},
"ACPIM": {"2017": 0.0},
"ACPIU": {"2017": 0.0},
"ADIVS": {"2017": 0.0},
"AINTS": {"2017": 0.0},
"AIPD": {"2017": 0.0},
"ASCHCI": {"2017": 0.0},
"ASCHCL": {"2017": 0.0},
"ASCHEI": {"2017": 0.0},
"ASCHEL": {"2017": 0.0},
"ASCHF": {"2017": 0.0},
"ASOCSEC": {"2017": 0.0},
"ATXPY": {"2017": 0.0},
"AUCOMP": {"2017": 0.0},
"AWAGE": {"2017": 0.0},
"ABENOTHER": {"2017": 0.0},
"ABENMCARE": {"2017": 0.0},
"ABENMCAID": {"2017": 0.0},
"ABENSSI": {"2017": 0.0},
"ABENSNAP": {"2017": 0.0},
"ABENWIC": {"2017": 0.0},
"ABENHOUSING": {"2017": 0.0},
"ABENTANF": {"2017": 0.0},
"ABENVET": {"2017": 0.0}
},
"growdiff_response": {
"_ABOOK": {"2017": [0.0]},
"_ACGNS": {"2017": [0.0]},
"_ACPIM": {"2017": [0.0]},
"_ACPIU": {"2017": [0.0]},
"_ADIVS": {"2017": [0.0]},
"_AINTS": {"2017": [0.0]},
"_AIPD": {"2017": [0.0]},
"_ASCHCI": {"2017": [0.0]},
"_ASCHCL": {"2017": [0.0]},
"_ASCHEI": {"2017": [0.0]},
"_ASCHEL": {"2017": [0.0]},
"_ASCHF": {"2017": [0.0]},
"_ASOCSEC": {"2017": [0.0]},
"_ATXPY": {"2017": [0.0]},
"_AUCOMP": {"2017": [0.0]},
"_AWAGE": {"2017": [0.0]},
"_ABENOTHER": {"2017": [0.0]},
"_ABENMCARE": {"2017": [0.0]},
"_ABENMCAID": {"2017": [0.0]},
"_ABENSSI": {"2017": [0.0]},
"_ABENSNAP": {"2017": [0.0]},
"_ABENWIC": {"2017": [0.0]},
"_ABENHOUSING": {"2017": [0.0]},
"_ABENTANF": {"2017": [0.0]},
"_ABENVET": {"2017": [0.0]}
"ABOOK": {"2017": 0.0},
"ACGNS": {"2017": 0.0},
"ACPIM": {"2017": 0.0},
"ACPIU": {"2017": 0.0},
"ADIVS": {"2017": 0.0},
"AINTS": {"2017": 0.0},
"AIPD": {"2017": 0.0},
"ASCHCI": {"2017": 0.0},
"ASCHCL": {"2017": 0.0},
"ASCHEI": {"2017": 0.0},
"ASCHEL": {"2017": 0.0},
"ASCHF": {"2017": 0.0},
"ASOCSEC": {"2017": 0.0},
"ATXPY": {"2017": 0.0},
"AUCOMP": {"2017": 0.0},
"AWAGE": {"2017": 0.0},
"ABENOTHER": {"2017": 0.0},
"ABENMCARE": {"2017": 0.0},
"ABENMCAID": {"2017": 0.0},
"ABENSSI": {"2017": 0.0},
"ABENSNAP": {"2017": 0.0},
"ABENWIC": {"2017": 0.0},
"ABENHOUSING": {"2017": 0.0},
"ABENTANF": {"2017": 0.0},
"ABENVET": {"2017": 0.0}
}
}
10 changes: 0 additions & 10 deletions taxcalc/assumptions/simple_parameters_template.json

This file was deleted.

2 changes: 1 addition & 1 deletion taxcalc/calcfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

These functions are imported into the Calculator class.

Note: the cpi_offset policy parameter is the only policy parameter that
Note: the CPI_offset policy parameter is the only policy parameter that
does not appear here; it is used in the policy.py file to possibly adjust
the price inflation rate used to index policy parameters (as would be done
in a reform that introduces chained-CPI indexing).
Expand Down
Loading