Skip to content

Commit

Permalink
Revise Parameter-derived class constructors in taxcalcio.py
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholmer committed Dec 17, 2024
1 parent e4b629e commit 1392161
Showing 1 changed file with 35 additions and 25 deletions.
60 changes: 35 additions & 25 deletions taxcalc/taxcalcio.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,31 @@ def init(self, input_data, tax_year, baseline, reform, assump,
# pylint: disable=too-many-arguments,too-many-locals
# pylint: disable=too-many-statements,too-many-branches
self.errmsg = ''
# instantiate base and reform GrowFactors objects
if self.tmd_input_data:
gfactors_base = GrowFactors(self.tmd_gfactor) # pragma: no cover
gfactors_ref = GrowFactors(self.tmd_gfactor) # pragma: no cover
else:
gfactors_base = GrowFactors()
gfactors_ref = GrowFactors()
# check tax_year validity
max_tax_year = gfactors_base.last_year
if tax_year > max_tax_year:
msg = f'TAXYEAR={tax_year} is greater than {max_tax_year}'
self.errmsg += f'ERROR: {msg}\n'
min_tax_year = Policy.JSON_START_YEAR
if self.puf_input_data:
min_tax_year = max(Policy.JSON_START_YEAR, Records.PUFCSV_YEAR)

Check warning on line 266 in taxcalc/taxcalcio.py

View check run for this annotation

Codecov / codecov/patch

taxcalc/taxcalcio.py#L266

Added line #L266 was not covered by tests
if self.cps_input_data:
min_tax_year = max(Policy.JSON_START_YEAR, Records.CPSCSV_YEAR)
if self.tmd_input_data:
min_tax_year = max(Policy.JSON_START_YEAR, Records.TMDCSV_YEAR)

Check warning on line 270 in taxcalc/taxcalcio.py

View check run for this annotation

Codecov / codecov/patch

taxcalc/taxcalcio.py#L270

Added line #L270 was not covered by tests
if tax_year < min_tax_year:
msg = f'TAXYEAR={tax_year} is less than {min_tax_year}'
self.errmsg += f'ERROR: {msg}\n'
# tax_year out of range means cannot proceed with calculations
if self.errmsg:
return
# get policy parameter dictionary from --baseline file
basedict = Calculator.read_json_param_objects(baseline, None)
# get assumption sub-dictionaries
Expand All @@ -264,35 +289,29 @@ def init(self, input_data, tax_year, baseline, reform, assump,
# remember parameters for reform documentation
self.param_dict = paramdict
self.policy_dicts = policydicts
# set last_b_year
last_b_year = max(tax_year, Policy.LAST_BUDGET_YEAR)
# create gdiff_baseline object
gdiff_baseline = GrowDiff()
gdiff_baseline = GrowDiff(last_budget_year=last_b_year)
try:
gdiff_baseline.update_growdiff(paramdict['growdiff_baseline'])
except paramtools.ValidationError as valerr_msg:
self.errmsg += valerr_msg.__str__()
# create GrowFactors base object that incorporates gdiff_baseline
if self.tmd_input_data:
gfactors_base = GrowFactors(self.tmd_gfactor) # pragma: no cover
else:
gfactors_base = GrowFactors()
# apply gdiff_baseline to gfactor_base
gdiff_baseline.apply_to(gfactors_base)
# specify gdiff_response object
gdiff_response = GrowDiff()
gdiff_response = GrowDiff(last_budget_year=last_b_year)
try:
gdiff_response.update_growdiff(paramdict['growdiff_response'])
except paramtools.ValidationError as valerr_msg:
self.errmsg += valerr_msg.__str__()
# create GrowFactors ref object that has all gdiff objects applied
if self.tmd_input_data:
gfactors_ref = GrowFactors(self.tmd_gfactor) # pragma: no cover
else:
gfactors_ref = GrowFactors()
# apply gdiff_baseline and gdiff_response to gfactor_ref
gdiff_baseline.apply_to(gfactors_ref)
gdiff_response.apply_to(gfactors_ref)
self.gf_reform = copy.deepcopy(gfactors_ref)
# create Policy objects:
# ... the baseline Policy object
base = Policy(gfactors=gfactors_base)
base = Policy(gfactors=gfactors_base, last_budget_year=last_b_year)
try:
base.implement_reform(basedict['policy'],
print_warnings=True,
Expand All @@ -303,7 +322,7 @@ def init(self, input_data, tax_year, baseline, reform, assump,
self.errmsg += valerr_msg.__str__()
# ... the reform Policy object
if self.specified_reform:
pol = Policy(gfactors=gfactors_ref)
pol = Policy(gfactors=gfactors_ref, last_budget_year=last_b_year)
for poldict in policydicts:
try:
pol.implement_reform(poldict,
Expand All @@ -316,22 +335,13 @@ def init(self, input_data, tax_year, baseline, reform, assump,
except paramtools.ValidationError as valerr_msg:
self.errmsg += valerr_msg.__str__()
else:
pol = Policy(gfactors=gfactors_base)
pol = Policy(gfactors=gfactors_base, last_budget_year=last_b_year)
# create Consumption object
con = Consumption()
con = Consumption(last_budget_year=last_b_year)
try:
con.update_consumption(paramdict['consumption'])
except paramtools.ValidationError as valerr_msg:
self.errmsg += valerr_msg.__str__()
# check for valid tax_year value
if tax_year < pol.start_year:
msg = 'tax_year {} less than policy.start_year {}'
msg = msg.format(tax_year, pol.start_year)
self.errmsg += 'ERROR: {}\n'.format(msg)
if tax_year > pol.end_year:
msg = 'tax_year {} greater than policy.end_year {}'
msg = msg.format(tax_year, pol.end_year)
self.errmsg += 'ERROR: {}\n'.format(msg)
# any errors imply cannot proceed with calculations
if self.errmsg:
return
Expand Down

0 comments on commit 1392161

Please sign in to comment.