def test_parameters_get_default_start_year(): paramdata = Policy.default_data(metadata=True, start_year=2015) # 1D data, has 2015 values meta_II_em = paramdata['_II_em'] assert meta_II_em['start_year'] == 2015 assert meta_II_em['row_label'] == ['2015', '2016'] assert meta_II_em['value'] == [4000, 4050] # 2D data, has 2015 values meta_std_aged = paramdata['_STD_Aged'] assert meta_std_aged['start_year'] == 2015 assert meta_std_aged['row_label'] == ['2015', '2016'] assert meta_std_aged['value'] == [[1550, 1250, 1250, 1550, 1550, 1250], [1550, 1250, 1250, 1550, 1550, 1250]] # 1D data, doesn't have 2015 values, is CPI inflated meta_amt_thd_marrieds = paramdata['_AMT_thd_MarriedS'] assert meta_amt_thd_marrieds['start_year'] == 2015 assert meta_amt_thd_marrieds['row_label'] == ['2015'] # Take the 2014 parameter value and multiply by inflation for that year should_be = 41050 * (1.0 + Policy.default_inflation_rates()[2014]) meta_amt_thd_marrieds['value'] == should_be # 1D data, doesn't have 2015 values, is not CPI inflated meta_kt_c_age = paramdata['_KT_c_Age'] assert meta_kt_c_age['start_year'] == 2015 assert meta_kt_c_age['row_label'] == ['2015'] assert meta_kt_c_age['value'] == [24]
def test_parameters_get_default_start_year(): paramdata = Policy.default_data(metadata=True, start_year=2015) # 1D data, has 2015 values meta_II_em = paramdata['_II_em'] assert meta_II_em['start_year'] == 2015 assert meta_II_em['row_label'] == ['2015', '2016'] assert meta_II_em['value'] == [4000, 4050] # 2D data, has 2015 values meta_std_aged = paramdata['_STD_Aged'] assert meta_std_aged['start_year'] == 2015 assert meta_std_aged['row_label'] == ['2015', '2016'] assert meta_std_aged['value'] == [[1550, 1250, 1250, 1550, 1550, 1250], [1550, 1250, 1250, 1550, 1550, 1250]] # 1D data, doesn't have 2015 values, is CPI inflated meta_amt_thd_marrieds = paramdata['_AMT_thd_MarriedS'] assert meta_amt_thd_marrieds['start_year'] == 2015 assert meta_amt_thd_marrieds['row_label'] == ['2015'] # Take the 2014 parameter value and multiply by inflation for that year should_be = 41050 * (1.0 + Policy.default_inflation_rates()[2014]) meta_amt_thd_marrieds['value'] == should_be # 1D data, doesn't have 2015 values, is not CPI inflated meta_kt_c_age = paramdata['_KT_c_Age'] assert meta_kt_c_age['start_year'] == 2015 assert meta_kt_c_age['row_label'] == ['2015'] assert meta_kt_c_age['value'] == [24]
def test_create_parameters_from_file(policyfile): with open(policyfile.name) as pfile: policy = json.load(pfile) ppo = Policy(parameter_dict=policy) irates = Policy.default_inflation_rates() inf_rates = [irates[ppo.start_year + i] for i in range(0, ppo.num_years)] assert_allclose(ppo._almdep, Policy.expand_array(np.array([7150, 7250, 7400]), inflate=True, inflation_rates=inf_rates, num_years=ppo.num_years), atol=0.01, rtol=0.0) assert_allclose(ppo._almsep, Policy.expand_array(np.array([40400, 41050]), inflate=True, inflation_rates=inf_rates, num_years=ppo.num_years), atol=0.01, rtol=0.0) assert_allclose(ppo._rt5, Policy.expand_array(np.array([0.33]), inflate=False, inflation_rates=inf_rates, num_years=ppo.num_years), atol=0.01, rtol=0.0) assert_allclose(ppo._rt7, Policy.expand_array(np.array([0.396]), inflate=False, inflation_rates=inf_rates, num_years=ppo.num_years), atol=0.01, rtol=0.0)
def test_create_parameters_from_file(policyfile): with open(policyfile.name) as pfile: policy = json.load(pfile) ppo = Policy(parameter_dict=policy) irates = Policy.default_inflation_rates() inf_rates = [irates[ppo.start_year + i] for i in range(0, ppo.num_years)] assert_allclose(ppo._almdep, Policy.expand_array(np.array([7150, 7250, 7400]), inflate=True, inflation_rates=inf_rates, num_years=ppo.num_years), atol=0.01, rtol=0.0) assert_allclose(ppo._almsep, Policy.expand_array(np.array([40400, 41050]), inflate=True, inflation_rates=inf_rates, num_years=ppo.num_years), atol=0.01, rtol=0.0) assert_allclose(ppo._rt5, Policy.expand_array(np.array([0.33]), inflate=False, inflation_rates=inf_rates, num_years=ppo.num_years), atol=0.01, rtol=0.0) assert_allclose(ppo._rt7, Policy.expand_array(np.array([0.396]), inflate=False, inflation_rates=inf_rates, num_years=ppo.num_years), atol=0.01, rtol=0.0)
def test_expand_2D_accept_None(): _II_brk2 = [[36000, 72250, 36500, 48600, 72500, 36250], [38000, 74000, 36900, 49400, 73800, 36900], [40000, 74900, 37450, 50200, 74900, 37450], [41000, None, None, None, None, None]] exp1 = 74900 * 1.02 exp2 = 37450 * 1.02 exp3 = 50200 * 1.02 exp4 = 74900 * 1.02 exp5 = 37450 * 1.02 exp = [[36000, 72250, 36500, 48600, 72500, 36250], [38000, 74000, 36900, 49400, 73800, 36900], [40000, 74900, 37450, 50200, 74900, 37450], [41000, exp1, exp2, exp3, exp4, exp5]] exp = np.array(exp).astype('i4', casting='unsafe') res = Policy.expand_array(_II_brk2, inflate=True, inflation_rates=[0.02] * 5, num_years=4) npt.assert_array_equal(res, exp) user_mods = {2016: {u'_II_brk2': _II_brk2}} pol = Policy(start_year=2013) pol.implement_reform(user_mods) pol.set_year(2019) irates = Policy.default_inflation_rates() # The 2019 policy should be the combination of the user-defined # value and CPI-inflated values from 2018 exp_2019 = [41000.] + [(1 + irates[2018]) * i for i in _II_brk2[2][1:]] exp_2019 = np.array(exp_2019) npt.assert_array_equal(pol.II_brk2, exp_2019)
def test_expand_2D_accept_None(): _II_brk2 = [[36000, 72250, 36500, 48600, 72500, 36250], [38000, 74000, 36900, 49400, 73800, 36900], [40000, 74900, 37450, 50200, 74900, 37450], [41000, None, None, None, None, None]] exp1 = 74900 * 1.02 exp2 = 37450 * 1.02 exp3 = 50200 * 1.02 exp4 = 74900 * 1.02 exp5 = 37450 * 1.02 exp = [[36000, 72250, 36500, 48600, 72500, 36250], [38000, 74000, 36900, 49400, 73800, 36900], [40000, 74900, 37450, 50200, 74900, 37450], [41000, exp1, exp2, exp3, exp4, exp5]] exp = np.array(exp).astype('i4', casting='unsafe') res = Policy.expand_array(_II_brk2, inflate=True, inflation_rates=[0.02] * 5, num_years=4) npt.assert_array_equal(res, exp) user_mods = {2016: {u'_II_brk2': _II_brk2}} pol = Policy(start_year=2013) pol.implement_reform(user_mods) pol.set_year(2019) irates = Policy.default_inflation_rates() # The 2019 policy should be the combination of the user-defined # value and CPI-inflated values from 2018 exp_2019 = [41000.] + [(1 + irates[2018]) * i for i in _II_brk2[2][1:]] exp_2019 = np.array(exp_2019) npt.assert_array_equal(pol.II_brk2, exp_2019)
def test_expand_2D_accept_None_additional_row(): _II_brk2 = [[36000, 72250, 36500, 48600, 72500, 36250], [38000, 74000, 36900, 49400, 73800, 36900], [40000, 74900, 37450, 50200, 74900, 37450], [41000, None, None, None, None, None], [43000, None, None, None, None, None]] exp1 = 74900 * 1.02 exp2 = 37450 * 1.02 exp3 = 50200 * 1.02 exp4 = 74900 * 1.02 exp5 = 37450 * 1.02 exp6 = exp1 * 1.03 exp7 = exp2 * 1.03 exp8 = exp3 * 1.03 exp9 = exp4 * 1.03 exp10 = exp5 * 1.03 exp = [[36000, 72250, 36500, 48600, 72500, 36250], [38000, 74000, 36900, 49400, 73800, 36900], [40000, 74900, 37450, 50200, 74900, 37450], [41000, exp1, exp2, exp3, exp4, exp5], [43000, exp6, exp7, exp8, exp9, exp10]] inflation_rates = [0.015, 0.02, 0.02, 0.03] res = Policy.expand_array(_II_brk2, inflate=True, inflation_rates=inflation_rates, num_years=5) npt.assert_array_equal(res, exp) user_mods = {2016: {u'_II_brk2': _II_brk2}} pol = Policy(start_year=2013) pol.implement_reform(user_mods) pol.set_year(2020) irates = Policy.default_inflation_rates() # The 2020 policy should be the combination of the user-defined # value and CPI-inflated values from 2018 exp_2020 = [43000.] + [(1 + irates[2019]) * (1 + irates[2018]) * i for i in _II_brk2[2][1:]] exp_2020 = np.array(exp_2020) npt.assert_allclose(pol.II_brk2, exp_2020)
def test_expand_2D_accept_None_additional_row(): _II_brk2 = [ [36000, 72250, 36500, 48600, 72500, 36250], [38000, 74000, 36900, 49400, 73800, 36900], [40000, 74900, 37450, 50200, 74900, 37450], [41000, None, None, None, None, None], [43000, None, None, None, None, None], ] exp1 = 74900 * 1.02 exp2 = 37450 * 1.02 exp3 = 50200 * 1.02 exp4 = 74900 * 1.02 exp5 = 37450 * 1.02 exp6 = exp1 * 1.03 exp7 = exp2 * 1.03 exp8 = exp3 * 1.03 exp9 = exp4 * 1.03 exp10 = exp5 * 1.03 exp = [ [36000, 72250, 36500, 48600, 72500, 36250], [38000, 74000, 36900, 49400, 73800, 36900], [40000, 74900, 37450, 50200, 74900, 37450], [41000, exp1, exp2, exp3, exp4, exp5], [43000, exp6, exp7, exp8, exp9, exp10], ] inflation_rates = [0.015, 0.02, 0.02, 0.03] res = Policy.expand_array(_II_brk2, inflate=True, inflation_rates=inflation_rates, num_years=5) npt.assert_array_equal(res, exp) user_mods = {2016: {u"_II_brk2": _II_brk2}} pol = Policy(start_year=2013) pol.implement_reform(user_mods) pol.set_year(2020) irates = Policy.default_inflation_rates() # The 2020 policy should be the combination of the user-defined # value and CPI-inflated values from 2018 exp_2020 = [43000.0] + [(1 + irates[2019]) * (1 + irates[2018]) * i for i in _II_brk2[2][1:]] exp_2020 = np.array(exp_2020) npt.assert_allclose(pol.II_brk2, exp_2020)