Using non-current law baseline policy in Tax-Brain API

Tax-Brain API users and developers – has anyone tried to specify a non-current law baseline policy using the API? When I try to use a reform dictionary as base_policy I get ValueError: ERROR: KEY policy YEAR II_rt1 is not an integer year (even though the same dictionary works for the reform argument) with the following traceback:

cc: @hdoupe and Anderson (does he have a Discourse?)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-37-056141409006> in <module>
      1 rates_df = run_tb(None, itax_rates, 'Rates')
----> 2 amt_df = run_tb(itax_rates, itax_amt, 'AMT')
      3 std_df = run_tb(itax_amt, itax_std, 'Standard Deduction')
      4 em_df = run_tb(itax_std, itax_em, 'Personal Exemption')

<ipython-input-36-b971f5e04a4b> in run_tb(base, reform, provision, behavior)
      1 def run_tb(base, reform, provision, behavior={'sub':0.25}):
      2     tb = TaxBrain(2019, 2028, base_policy=base, microdata='puf.csv', reform=reform)
----> 3     tb.run()
      4     df = tb.weighted_totals('combined')
      5     df_diff = df.loc[['Difference']]

~/Tax-Brain/taxbrain/taxbrain.py in run(self, varlist)
    104         None
    105         """
--> 106         base_calc, reform_calc = self._make_calculators()
    107         if not isinstance(varlist, list):
    108             msg = f"'varlist' is of type {type(varlist)}. Must be a list."

~/Tax-Brain/taxbrain/taxbrain.py in _make_calculators(self)
    361         policy = tc.Policy(gf_base)
    362         if self.params["base_policy"]:
--> 363             policy.implement_reform(self.params["base_policy"])
    364         base_calc = tc.Calculator(policy=policy,
    365                                   records=records,

~/anaconda3/envs/taxbrain-dev/lib/python3.7/site-packages/taxcalc/policy.py in implement_reform(self, reform, print_warnings, raise_errors)
    126         the expected structure of the reform dictionary.
    127         """
--> 128         self._update(reform, print_warnings, raise_errors)
    129 
    130     @staticmethod

~/anaconda3/envs/taxbrain-dev/lib/python3.7/site-packages/taxcalc/parameters.py in _update(self, revision_, print_warnings, raise_errors)
    307                 if not isinstance(year, int):
    308                     msg = 'ERROR: KEY {} YEAR {} is not an integer year'
--> 309                     raise ValueError(msg.format(name, year))
    310                 if year not in revision:
    311                     revision[year] = dict()

ValueError: ERROR: KEY policy YEAR II_rt1 is not an integer year

@Peter-Metz could you post a code snippet that reproduces the bug?

Yep, here it is:

def run_tb(base, reform, provision, behavior={'sub':0.25}):
    tb = TaxBrain(2019, 2028, base_policy=base, microdata='puf.csv', reform=reform)
    tb.run()
    df = tb.weighted_totals('combined')
    df_diff = df.loc[['Difference']]
    df_diff.rename(index={'Difference':provision}, inplace=True)
    return df_diff * 1e-9

# this doesn't throw an error because no base_policy is specified
rates_df = run_tb(None, itax_rates, 'Rates')
# this throws an error because itax_rates is a reform dictionary
amt_df = run_tb(itax_rates, itax_amt, 'AMT')

Thanks @Peter-Metz. This is a bug. I just opened a PR in Tax-Brain: https://github.com/PSLmodels/Tax-Brain/pull/93

If you are interested, would you mind confirming that the changes proposed in the PR resolve the problem?

1 Like

Looks great to me! Thanks for the quick fix.

Great, thanks for the review. I’ll merge tomorrow.