Skip to content

Commit

Permalink
streamline taxcalc policy specification
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter-Metz committed Jul 15, 2019
1 parent 80ebbd6 commit 412cf9e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
12 changes: 3 additions & 9 deletions taxcrunch/cruncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ def choose_baseline(self):
exists = os.path.isfile(os.path.join(CURRENT_PATH, self.baseline))
if exists:
baseline_file = os.path.join(CURRENT_PATH, self.baseline)
# baseline = tc.Calculator.read_json_param_objects(baseline_file, None)
self.pol = tc.Policy()
self.pol.implement_reform(
tc.Policy.read_json_reform(baseline_file))
Expand All @@ -307,10 +306,8 @@ def choose_baseline(self):
try:
baseline_file = self.baseline
baseline_url = REFORMS_URL + baseline_file
baseline = tc.Calculator.read_json_param_objects(
baseline_url, None)
self.pol = tc.Policy()
self.pol.implement_reform(baseline["policy"])
self.pol.implement_reform(tc.Policy.read_json_reform(baseline_url))
except:
print("Baseline file does not exist")

Expand All @@ -334,19 +331,16 @@ def choose_reform(self):
if self.reform_options != "None" and self.custom_reform is None:
reform_name = self.reform_options
reform_url = REFORMS_URL + reform_name
reform = tc.Calculator.read_json_param_objects(reform_url, None)
self.pol2 = tc.Policy()
self.pol2.implement_reform(reform["policy"])
self.pol2.implement_reform(tc.Policy.read_json_reform(reform_url))
# otherwise, look for user-provided json reform file
# first as file path
elif self.reform_options == "None" and isinstance(self.custom_reform, str):
try:
reform_filename = os.path.join(
CURRENT_PATH, self.custom_reform)
reform = tc.Calculator.read_json_param_objects(
reform_filename, None)
self.pol2 = tc.Policy()
self.pol2.implement_reform(reform["policy"])
self.pol2.implement_reform(tc.Policy.read_json_reform(reform_filename))
except:
print("Reform file path does not exist")
# then as dictionary
Expand Down
10 changes: 4 additions & 6 deletions taxcrunch/multi_cruncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ def create_table(self, reform_file=None):
else:
# check to see if file path to reform_file exists
if isinstance(reform_file, str) and os.path.isfile(os.path.join(CURRENT_PATH, reform_file)):
reform = tc.Calculator.read_json_param_objects(
reform_file, None)
reform_path = os.path.join(CURRENT_PATH, reform_file)
pol = tc.Policy()
pol.implement_reform(reform["policy"])
pol.implement_reform(tc.Policy.read_json_reform(reform_path))
# try reform_file as dictionary
elif isinstance(reform_file, dict):
reform = reform_file
Expand All @@ -128,17 +127,16 @@ def create_table(self, reform_file=None):
else:
try:
reform_url = REFORMS_URL + reform_file
reform = tc.Calculator.read_json_param_objects(
reform_url, None)
pol = tc.Policy()
pol.implement_reform(reform["policy"])
pol.implement_reform(tc.Policy.read_json_reform(reform_url))
except:
raise 'Reform file does not exist'

year = self.invar['FLPDYR'][0]
year = year.item()
recs = tc.Records(data=self.invar, start_year=year)
calc = tc.Calculator(policy=pol, records=recs)
calc.advance_to_year(year)
calc.calc_all()
calcs = calc.dataframe(self.tc_vars)
mtr = calc.mtr(wrt_full_compensation=False)
Expand Down
4 changes: 0 additions & 4 deletions taxcrunch/tests/test_cruncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ def create_data():
def test_baseline_choice():
c = cr.Cruncher(baseline="tests/test_reform.json")
assert isinstance(c, cr.Cruncher)
with pytest.raises(AttributeError):
cr.Cruncher(baseline="tests/fake_file.json")


def test_reform_choice():
Expand All @@ -30,8 +28,6 @@ def test_reform_choice():
cr.Cruncher(
inputs="tests/test_adjustment.json", custom_reform="tests/test_reform.json"
)
with pytest.raises(AttributeError):
cr.Cruncher(custom_reform="tests/fake_file.json")


def test_basic_table():
Expand Down

0 comments on commit 412cf9e

Please sign in to comment.