def test_multiyear_diagnostic_table(records_2009): behv = Behavior() calc = Calculator(policy=Policy(), records=records_2009, behavior=behv) with pytest.raises(ValueError): adt = multiyear_diagnostic_table(calc, 0) with pytest.raises(ValueError): adt = multiyear_diagnostic_table(calc, 20) adt = multiyear_diagnostic_table(calc, 3) assert isinstance(adt, pd.DataFrame) behv.update_behavior({2013: {'_BE_sub': [0.3]}}) assert calc.behavior.has_response() adt = multiyear_diagnostic_table(calc, 3) assert isinstance(adt, pd.DataFrame)
def test_myr_diag_table_wo_behv(records_2009): pol = Policy() reform = { 2013: { '_II_rt7': [0.33], '_PT_rt7': [0.33], } } pol.implement_reform(reform) calc = Calculator(policy=pol, records=records_2009) calc.calc_all() liabilities_x = (calc.records.combined * calc.records.s006).sum() adt = multiyear_diagnostic_table(calc, 1) # extract combined liabilities as a float and # adopt units of the raw calculator data in liabilities_x liabilities_y = adt.iloc[19].tolist()[0] * 1000000000 assert_almost_equal(liabilities_x, liabilities_y, 2)
def test_myr_diag_table_wo_behv(cps_subsample): reform = { 2013: { '_II_rt7': [0.33], '_PT_rt7': [0.33], } } pol = Policy() pol.implement_reform(reform) calc = Calculator(policy=pol, records=Records.cps_constructor(data=cps_subsample)) calc.calc_all() liabilities_x = (calc.records.combined * calc.records.s006).sum() adt = multiyear_diagnostic_table(calc, 1) # extract combined liabilities as a float and # adopt units of the raw calculator data in liabilities_x liabilities_y = adt.iloc[19].tolist()[0] * 1e9 assert np.allclose(liabilities_x, liabilities_y, atol=0.01, rtol=0.0)
def test_myr_diag_table_w_behv(cps_subsample): pol = Policy() rec = Records.cps_constructor(data=cps_subsample) year = rec.current_year beh = Behavior() calc = Calculator(policy=pol, records=rec, behavior=beh) assert calc.current_year == year reform = {year: {'_II_rt7': [0.33], '_PT_rt7': [0.33]}} pol.implement_reform(reform) reform_behav = {year: {'_BE_sub': [0.4], '_BE_cg': [-3.67]}} beh.update_behavior(reform_behav) calc_clp = calc.current_law_version() calc_beh = Behavior.response(calc_clp, calc) calc_beh.calc_all() liabilities_x = (calc_beh.records.combined * calc_beh.records.s006).sum() adt = multiyear_diagnostic_table(calc_beh, 1) # extract combined liabilities as a float and # adopt units of the raw calculator data in liabilities_x liabilities_y = adt.iloc[19].tolist()[0] * 1e9 assert np.allclose(liabilities_x, liabilities_y, atol=0.01, rtol=0.0)
def test_multiyear_diagnostic_table(cps_subsample): rec = Records.cps_constructor(data=cps_subsample) pol = Policy() beh = Behavior() calc = Calculator(policy=pol, records=rec, behavior=beh) with pytest.raises(ValueError): multiyear_diagnostic_table(calc, 0) with pytest.raises(ValueError): multiyear_diagnostic_table(calc, 20) adt = multiyear_diagnostic_table(calc, 3) assert isinstance(adt, pd.DataFrame) beh.update_behavior({2013: {'_BE_sub': [0.3]}}) calc = Calculator(policy=pol, records=rec, behavior=beh) assert calc.behavior.has_response() adt = multiyear_diagnostic_table(calc, 3) assert isinstance(adt, pd.DataFrame)
def test_myr_diag_table_w_behv(records_2009): pol = Policy() behv = Behavior() calc = Calculator(policy=pol, records=records_2009, behavior=behv) assert calc.current_year == 2013 reform = { 2013: { '_II_rt7': [0.33], '_PT_rt7': [0.33], } } pol.implement_reform(reform) reform_be = {2013: {'_BE_sub': [0.4], '_BE_cg': [-3.67]}} behv.update_behavior(reform_be) calc_clp = calc.current_law_version() calc_behv = Behavior.response(calc_clp, calc) calc_behv.calc_all() liabilities_x = (calc_behv.records.combined * calc_behv.records.s006).sum() adt = multiyear_diagnostic_table(calc_behv, 1) # extract combined liabilities as a float and # adopt units of the raw calculator data in liabilities_x liabilities_y = adt.iloc[19].tolist()[0] * 1000000000 assert_almost_equal(liabilities_x, liabilities_y, 2)