diff --git a/taxcalc/calculator.py b/taxcalc/calculator.py index 32ade2b82..9ed58da43 100644 --- a/taxcalc/calculator.py +++ b/taxcalc/calculator.py @@ -114,7 +114,7 @@ def __init__(self, policy=None, records=None, verbose=True, if self.__policy.current_year < self.__records.data_year: self.__policy.set_year(self.__records.data_year) if consumption is None: - self.__consumption = Consumption(start_year=policy.start_year) + self.__consumption = Consumption() elif isinstance(consumption, Consumption): self.__consumption = copy.deepcopy(consumption) else: diff --git a/taxcalc/consumption.py b/taxcalc/consumption.py index e0a5ddbc9..8d9bae768 100644 --- a/taxcalc/consumption.py +++ b/taxcalc/consumption.py @@ -19,18 +19,7 @@ class Consumption(Parameters): Parameters ---------- - start_year: integer - first calendar year for consumption parameters. - - num_years: integer - number of calendar years for which to specify parameter - values beginning with start_year. - - Raises - ------ - ValueError: - if start_year is less than Policy.JSON_START_YEAR. - if num_years is less than one. + none Returns ------- @@ -41,15 +30,11 @@ class instance: Consumption DEFAULTS_FILENAME = 'consumption.json' DEFAULT_NUM_YEARS = Policy.DEFAULT_NUM_YEARS - def __init__(self, - start_year=JSON_START_YEAR, - num_years=DEFAULT_NUM_YEARS): + def __init__(self): super(Consumption, self).__init__() self._vals = self._params_dict_from_json_file() - if start_year < Policy.JSON_START_YEAR: - raise ValueError('start_year < Policy.JSON_START_YEAR') - if num_years < 1: - raise ValueError('num_years < 1') + start_year = Consumption.JSON_START_YEAR + num_years = Consumption.DEFAULT_NUM_YEARS self.initialize(start_year, num_years) self.parameter_errors = '' diff --git a/taxcalc/growdiff.py b/taxcalc/growdiff.py index 2f69d6436..673917529 100644 --- a/taxcalc/growdiff.py +++ b/taxcalc/growdiff.py @@ -18,18 +18,7 @@ class GrowDiff(Parameters): Parameters ---------- - start_year: integer - first calendar year for growth difference parameters. - - num_years: integer - number of calendar years for which to specify parameter - values beginning with start_year. - - Raises - ------ - ValueError: - if start_year is less than 2013 - if num_years is less than one. + none Returns ------- @@ -40,15 +29,11 @@ class instance: GrowDiff DEFAULTS_FILENAME = 'growdiff.json' DEFAULT_NUM_YEARS = 15 # must be same as Policy.DEFAULT_NUM_YEARS - def __init__(self, - start_year=JSON_START_YEAR, - num_years=DEFAULT_NUM_YEARS): + def __init__(self): super(GrowDiff, self).__init__() self._vals = self._params_dict_from_json_file() - if start_year < GrowDiff.JSON_START_YEAR: - raise ValueError('start_year < GrowDiff.JSON_START_YEAR') - if num_years < 1: - raise ValueError('num_years < 1') + start_year = GrowDiff.JSON_START_YEAR + num_years = GrowDiff.DEFAULT_NUM_YEARS self.initialize(start_year, num_years) self.parameter_errors = '' diff --git a/taxcalc/parameters.py b/taxcalc/parameters.py index 44ae53cee..d1188b29f 100644 --- a/taxcalc/parameters.py +++ b/taxcalc/parameters.py @@ -22,7 +22,7 @@ class Parameters(): DEFAULTS_FILENAME = None @classmethod - def default_data(cls, metadata=False, start_year=None): + def default_data(cls, metadata=False): """ Return parameter data read from the subclass's json file. @@ -30,22 +30,12 @@ def default_data(cls, metadata=False, start_year=None): ---------- metadata: boolean - start_year: int or None - Returns ------- params: dictionary of data """ - # extract different data from DEFAULT_FILENAME depending on start_year - if start_year is None: - params = cls._params_dict_from_json_file() - else: - nyrs = start_year - cls.JSON_START_YEAR + 1 - ppo = cls(num_years=nyrs) - ppo.set_year(start_year) - params = getattr(ppo, '_vals') - params = Parameters._revised_default_data(params, start_year, - nyrs, ppo) + # extract data from DEFAULT_FILENAME + params = cls._params_dict_from_json_file() # return different data from params dict depending on metadata value if metadata: return params @@ -316,54 +306,6 @@ def _validate_assump_parameter_values(self, parameters_set): ) del parameters - @staticmethod - def _revised_default_data(params, start_year, nyrs, ppo): - """ - Return revised default parameter data. - - Parameters - ---------- - params: dictionary of NAME:DATA pairs for each parameter - as defined in calling default_data staticmethod. - - start_year: int - as defined in calling default_data staticmethod. - - nyrs: int - as defined in calling default_data staticmethod. - - ppo: Policy object - as defined in calling default_data staticmethod. - - Returns - ------- - params: dictionary of revised parameter data - - Notes - ----- - This staticmethod is called from default_data staticmethod in - order to reduce the complexity of the default_data staticmethod. - """ - start_year_str = '{}'.format(start_year) - for name, data in params.items(): - data['start_year'] = start_year - values = data['value'] - num_values = len(values) - if num_values <= nyrs: - # val should be the single start_year value - rawval = getattr(ppo, name[1:]) - if isinstance(rawval, np.ndarray): - val = rawval.tolist() - else: - val = rawval - data['value'] = [val] - data['row_label'] = [start_year_str] - else: # if num_values > nyrs - # val should extend beyond the start_year value - data['value'] = data['value'][(nyrs - 1):] - data['row_label'] = data['row_label'][(nyrs - 1):] - return params - @classmethod def _params_dict_from_json_file(cls): """ diff --git a/taxcalc/policy.py b/taxcalc/policy.py index b77123d60..c57d69a8c 100644 --- a/taxcalc/policy.py +++ b/taxcalc/policy.py @@ -23,19 +23,10 @@ class Policy(Parameters): gfactors: GrowFactors class instance containing price inflation rates and wage growth rates - start_year: integer - first calendar year for historical policy parameters. - - num_years: integer - number of calendar years for which to specify policy parameter - values beginning with start_year. - Raises ------ ValueError: - if gfactors is not a GrowFactors class instance. - if start_year is less than JSON_START_YEAR. - if num_years is less than one. + if gfactors is not a GrowFactors class instance or None. Returns ------- @@ -50,10 +41,7 @@ class instance: Policy # should increase LAST_BUDGET_YEAR by one every calendar year DEFAULT_NUM_YEARS = LAST_BUDGET_YEAR - JSON_START_YEAR + 1 - def __init__(self, - gfactors=None, - start_year=JSON_START_YEAR, - num_years=DEFAULT_NUM_YEARS): + def __init__(self, gfactors=None): super(Policy, self).__init__() if gfactors is None: @@ -63,21 +51,15 @@ def __init__(self, else: raise ValueError('gfactors is not None or a GrowFactors instance') - # read default parameters + # read default parameters and initialize self._vals = self._params_dict_from_json_file() - - if start_year < Policy.JSON_START_YEAR: - raise ValueError('start_year cannot be less than JSON_START_YEAR') - if num_years < 1: - raise ValueError('num_years cannot be less than one') - - syr = start_year - lyr = start_year + num_years - 1 + syr = Policy.JSON_START_YEAR + lyr = Policy.LAST_BUDGET_YEAR + nyrs = Policy.DEFAULT_NUM_YEARS self._inflation_rates = self._gfactors.price_inflation_rates(syr, lyr) - self._apply_clp_cpi_offset(self._vals['_cpi_offset'], num_years) + self._apply_clp_cpi_offset(self._vals['_cpi_offset'], nyrs) self._wage_growth_rates = self._gfactors.wage_growth_rates(syr, lyr) - - self.initialize(start_year, num_years) + self.initialize(syr, nyrs) self.parameter_warnings = '' self.parameter_errors = '' diff --git a/taxcalc/tests/test_calculator.py b/taxcalc/tests/test_calculator.py index c18557ac6..a163df6c9 100644 --- a/taxcalc/tests/test_calculator.py +++ b/taxcalc/tests/test_calculator.py @@ -56,17 +56,18 @@ def fixture_policyfile(): def test_make_calculator(cps_subsample): - syr = 2014 - pol = Policy(start_year=syr, num_years=9) - assert pol.current_year == syr + start_year = Policy.JSON_START_YEAR + sim_year = 2018 + pol = Policy() + assert pol.current_year == start_year rec = Records.cps_constructor(data=cps_subsample) consump = Consumption() - consump.update_consumption({syr: {'_MPC_e20400': [0.05]}}) - assert consump.current_year == Consumption.JSON_START_YEAR + consump.update_consumption({sim_year: {'_MPC_e20400': [0.05]}}) + assert consump.current_year == start_year calc = Calculator(policy=pol, records=rec, consumption=consump, behavior=Behavior()) - assert calc.current_year == syr - assert calc.records_current_year() == syr + assert calc.current_year == Records.CPSCSV_YEAR + assert calc.records_current_year() == Records.CPSCSV_YEAR # test incorrect Calculator instantiation: with pytest.raises(ValueError): Calculator(policy=None, records=rec) @@ -224,8 +225,7 @@ def test_calculator_mtr_when_PT_rates_differ(): def test_make_calculator_increment_years_first(cps_subsample): # create Policy object with policy reform - syr = 2013 - pol = Policy(start_year=syr) + pol = Policy() reform = {2015: {}, 2016: {}} std5 = 2000 reform[2015]['_STD_Aged'] = [[std5, std5, std5, std5, std5]] @@ -238,6 +238,7 @@ def test_make_calculator_increment_years_first(cps_subsample): calc = Calculator(policy=pol, records=rec) # compare expected policy parameter values with those embedded in calc irates = pol.inflation_rates() + syr = Policy.JSON_START_YEAR irate2015 = irates[2015 - syr] irate2016 = irates[2016 - syr] std6 = std5 * (1.0 + irate2015) diff --git a/taxcalc/tests/test_consumption.py b/taxcalc/tests/test_consumption.py index a9c74af38..5f7b7c082 100644 --- a/taxcalc/tests/test_consumption.py +++ b/taxcalc/tests/test_consumption.py @@ -7,11 +7,9 @@ from taxcalc import Policy, Records, Calculator, Consumption -def test_incorrect_Consumption_instantiation(): - with pytest.raises(ValueError): - consump = Consumption(start_year=2000) - with pytest.raises(ValueError): - consump = Consumption(num_years=0) +def test_year_consistency(): + assert Consumption.JSON_START_YEAR == Policy.JSON_START_YEAR + assert Consumption.DEFAULT_NUM_YEARS == Policy.DEFAULT_NUM_YEARS def test_validity_of_consumption_vars_set(): @@ -22,7 +20,7 @@ def test_validity_of_consumption_vars_set(): def test_update_consumption(): - consump = Consumption(start_year=2013) + consump = Consumption() consump.update_consumption({}) consump.update_consumption({2014: {'_MPC_e20400': [0.05], '_BEN_mcare_value': [0.75]}, diff --git a/taxcalc/tests/test_growdiff.py b/taxcalc/tests/test_growdiff.py index b6739e687..a00350295 100644 --- a/taxcalc/tests/test_growdiff.py +++ b/taxcalc/tests/test_growdiff.py @@ -3,7 +3,7 @@ import os import json -from numpy.testing import assert_allclose +import numpy as np import pytest from taxcalc import GrowDiff, GrowFactors, Policy @@ -13,26 +13,19 @@ def test_year_consistency(): assert GrowDiff.DEFAULT_NUM_YEARS == Policy.DEFAULT_NUM_YEARS -def test_incorrect_growdiff_ctor(): - with pytest.raises(ValueError): - gdiff = GrowDiff(start_year=2000) - with pytest.raises(ValueError): - gdiff = GrowDiff(num_years=0) - - def test_update_and_apply_growdiff(): - syr = 2013 - nyrs = 5 - lyr = syr + nyrs - 1 - gdiff = GrowDiff(start_year=syr, num_years=nyrs) + gdiff = GrowDiff() # update GrowDiff instance diffs = {2014: {'_AWAGE': [0.01]}, 2016: {'_AWAGE': [0.02]}} gdiff.update_growdiff(diffs) - expected_wage_diffs = [0.00, 0.01, 0.01, 0.02, 0.02] - assert_allclose(gdiff._AWAGE, expected_wage_diffs, atol=0.0, rtol=0.0) + expected_wage_diffs = [0.00, 0.01, 0.01, 0.02, 0.02] + [0.02]*10 + assert np.allclose(gdiff._AWAGE, expected_wage_diffs, atol=0.0, rtol=0.0) # apply growdiff to GrowFactors instance gf = GrowFactors() + syr = GrowDiff.JSON_START_YEAR + nyrs = GrowDiff.DEFAULT_NUM_YEARS + lyr = syr + nyrs - 1 pir_pre = gf.price_inflation_rates(syr, lyr) wgr_pre = gf.wage_growth_rates(syr, lyr) gfactors = GrowFactors() @@ -41,8 +34,8 @@ def test_update_and_apply_growdiff(): wgr_pst = gfactors.wage_growth_rates(syr, lyr) expected_wgr_pst = [wgr_pre[i] + expected_wage_diffs[i] for i in range(0, nyrs)] - assert_allclose(pir_pre, pir_pst, atol=0.0, rtol=0.0) - assert_allclose(wgr_pst, expected_wgr_pst, atol=1.0e-9, rtol=0.0) + assert np.allclose(pir_pre, pir_pst, atol=0.0, rtol=0.0) + assert np.allclose(wgr_pst, expected_wgr_pst, atol=1.0e-9, rtol=0.0) def test_incorrect_update_growdiff(): @@ -61,11 +54,12 @@ def test_incorrect_update_growdiff(): def test_has_any_response(): - syr = 2014 - gdiff = GrowDiff(start_year=syr) + start_year = GrowDiff.JSON_START_YEAR + gdiff = GrowDiff() + assert gdiff.current_year == start_year assert gdiff.has_any_response() is False gdiff.update_growdiff({2020: {'_AWAGE': [0.01]}}) - assert gdiff.current_year == syr + assert gdiff.current_year == start_year assert gdiff.has_any_response() is True diff --git a/taxcalc/tests/test_policy.py b/taxcalc/tests/test_policy.py index c986b8bab..f2cbe6486 100644 --- a/taxcalc/tests/test_policy.py +++ b/taxcalc/tests/test_policy.py @@ -6,7 +6,6 @@ import json import tempfile import numpy as np -from numpy.testing import assert_allclose import pytest from taxcalc import Policy, Calculator @@ -14,10 +13,6 @@ def test_incorrect_Policy_instantiation(): with pytest.raises(ValueError): Policy(gfactors=list()) - with pytest.raises(ValueError): - Policy(start_year=2000) - with pytest.raises(ValueError): - Policy(num_years=0) def test_correct_Policy_instantiation(): @@ -53,8 +48,7 @@ def test_policy_json_content(): def test_constant_inflation_rate_with_reform(): - syr = 2013 - pol = Policy(start_year=syr) + pol = Policy() # implement reform in year before final year fyr = Policy.LAST_BUDGET_YEAR ryr = fyr - 1 @@ -65,6 +59,7 @@ def test_constant_inflation_rate_with_reform(): pol.implement_reform(reform) # extract price inflation rates pirates = pol.inflation_rates() + syr = Policy.JSON_START_YEAR irate_b = pirates[ryr - 2 - syr] irate_a = pirates[ryr - syr] # check implied inflation rate just before reform @@ -76,8 +71,8 @@ def test_constant_inflation_rate_with_reform(): def test_variable_inflation_rate_with_reform(): - syr = 2013 - pol = Policy(start_year=syr) + pol = Policy() + syr = Policy.JSON_START_YEAR assert pol._II_em[2013 - syr] == 3900 # implement reform in 2020 which is two years before the last year, 2022 reform = { @@ -108,9 +103,9 @@ def test_multi_year_reform(): Test multi-year reform involving 1D and 2D parameters. """ # specify dimensions of policy Policy object - syr = 2013 + syr = Policy.JSON_START_YEAR nyrs = Policy.DEFAULT_NUM_YEARS - pol = Policy(start_year=syr) + pol = Policy() iratelist = pol.inflation_rates() ifactor = {} for i in range(0, nyrs): @@ -120,48 +115,48 @@ def test_multi_year_reform(): for i in range(0, nyrs): wfactor[syr + i] = 1.0 + wratelist[i] # confirm that parameters have current-law values - assert_allclose(getattr(pol, '_EITC_c'), - Policy._expand_array( - np.array([[487, 3250, 5372, 6044], - [496, 3305, 5460, 6143], - [503, 3359, 5548, 6242], - [506, 3373, 5572, 6269], - [510, 3400, 5616, 6318]], - dtype=np.float64), - False, False, - inflate=True, - inflation_rates=iratelist, - num_years=nyrs), - atol=0.01, rtol=0.0) - assert_allclose(getattr(pol, '_STD_Dep'), - Policy._expand_array( - np.array([1000, 1000, 1050, 1050, 1050], - dtype=np.float64), - False, False, - inflate=True, - inflation_rates=iratelist, - num_years=nyrs), - atol=0.01, rtol=0.0) - assert_allclose(getattr(pol, '_CTC_c'), - Policy._expand_array( - np.array([1000] * 5 + [1400] * 4 + - [1500] * 3 + [1600] + [1000], - dtype=np.float64), - False, False, - inflate=False, - inflation_rates=iratelist, - num_years=nyrs), - atol=0.01, rtol=0.0) + assert np.allclose(getattr(pol, '_EITC_c'), + Policy._expand_array( + np.array([[487, 3250, 5372, 6044], + [496, 3305, 5460, 6143], + [503, 3359, 5548, 6242], + [506, 3373, 5572, 6269], + [510, 3400, 5616, 6318]], + dtype=np.float64), + False, False, + inflate=True, + inflation_rates=iratelist, + num_years=nyrs), + atol=0.01, rtol=0.0) + assert np.allclose(getattr(pol, '_STD_Dep'), + Policy._expand_array( + np.array([1000, 1000, 1050, 1050, 1050], + dtype=np.float64), + False, False, + inflate=True, + inflation_rates=iratelist, + num_years=nyrs), + atol=0.01, rtol=0.0) + assert np.allclose(getattr(pol, '_CTC_c'), + Policy._expand_array( + np.array([1000] * 5 + [1400] * 4 + + [1500] * 3 + [1600] + [1000], + dtype=np.float64), + False, False, + inflate=False, + inflation_rates=iratelist, + num_years=nyrs), + atol=0.01, rtol=0.0) # this parameter uses a different indexing rate - assert_allclose(getattr(pol, '_SS_Earnings_c'), - Policy._expand_array( - np.array([113700, 117000, 118500, 118500, 127200], - dtype=np.float64), - False, False, - inflate=True, - inflation_rates=wratelist, - num_years=nyrs), - atol=0.01, rtol=0.0) + assert np.allclose(getattr(pol, '_SS_Earnings_c'), + Policy._expand_array( + np.array([113700, 117000, 118500, 118500, 127200], + dtype=np.float64), + False, False, + inflate=True, + inflation_rates=wratelist, + num_years=nyrs), + atol=0.01, rtol=0.0) # specify multi-year reform using a dictionary of year_provisions dicts reform = { 2015: { @@ -232,26 +227,26 @@ def check_eitc_c(ppo, reform, ifactor): alen = len(arr[0]) for i in range(0, ppo.num_years): actual[ppo.start_year + i] = arr[i] - assert_allclose(actual[2013], [487, 3250, 5372, 6044], - atol=0.01, rtol=0.0) - assert_allclose(actual[2014], [496, 3305, 5460, 6143], - atol=0.01, rtol=0.0) - assert_allclose(actual[2015], [503, 3359, 5548, 6242], - atol=0.01, rtol=0.0) + assert np.allclose(actual[2013], [487, 3250, 5372, 6044], + atol=0.01, rtol=0.0) + assert np.allclose(actual[2014], [496, 3305, 5460, 6143], + atol=0.01, rtol=0.0) + assert np.allclose(actual[2015], [503, 3359, 5548, 6242], + atol=0.01, rtol=0.0) e2016 = reform[2016]['_EITC_c'][0] - assert_allclose(actual[2016], e2016, atol=0.01, rtol=0.0) + assert np.allclose(actual[2016], e2016, atol=0.01, rtol=0.0) e2017 = [ifactor[2016] * actual[2016][j] for j in range(0, alen)] - assert_allclose(actual[2017], e2017, atol=0.01, rtol=0.0) + assert np.allclose(actual[2017], e2017, atol=0.01, rtol=0.0) e2018 = [ifactor[2017] * actual[2017][j] for j in range(0, alen)] assert np.allclose(actual[2018], e2018, atol=0.01, rtol=0.0) e2019 = reform[2019]['_EITC_c'][0] - assert_allclose(actual[2019], e2019, atol=0.01, rtol=0.0) + assert np.allclose(actual[2019], e2019, atol=0.01, rtol=0.0) e2020 = [ifactor[2019] * actual[2019][j] for j in range(0, alen)] - assert_allclose(actual[2020], e2020, atol=0.01, rtol=0.0) + assert np.allclose(actual[2020], e2020, atol=0.01, rtol=0.0) e2021 = [ifactor[2020] * actual[2020][j] for j in range(0, alen)] - assert_allclose(actual[2021], e2021, atol=0.01, rtol=0.0) + assert np.allclose(actual[2021], e2021, atol=0.01, rtol=0.0) e2022 = [ifactor[2021] * actual[2021][j] for j in range(0, alen)] - assert_allclose(actual[2022], e2022, atol=0.01, rtol=0.0) + assert np.allclose(actual[2022], e2022, atol=0.01, rtol=0.0) def check_ii_em(ppo, reform, ifactor): @@ -335,40 +330,40 @@ def test_create_parameters_from_file(monkeypatch, defaultpolicyfile): monkeypatch.setattr(Policy, 'DEFAULTS_FILENAME', defaultpolicyfile.name) ppo = Policy() inf_rates = ppo.inflation_rates() - assert_allclose(ppo._almdep, - Policy._expand_array( - np.array([7150, 7250, 7400], - dtype=np.float64), - False, False, - 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], - dtype=np.float64), - False, False, - 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]), - False, False, - 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]), - False, False, - inflate=False, - inflation_rates=inf_rates, - num_years=ppo.num_years), - atol=0.01, rtol=0.0) + assert np.allclose(ppo._almdep, + Policy._expand_array( + np.array([7150, 7250, 7400], + dtype=np.float64), + False, False, + inflate=True, + inflation_rates=inf_rates, + num_years=ppo.num_years), + atol=0.01, rtol=0.0) + assert np.allclose(ppo._almsep, + Policy._expand_array( + np.array([40400, 41050], + dtype=np.float64), + False, False, + inflate=True, + inflation_rates=inf_rates, + num_years=ppo.num_years), + atol=0.01, rtol=0.0) + assert np.allclose(ppo._rt5, + Policy._expand_array( + np.array([0.33]), + False, False, + inflate=False, + inflation_rates=inf_rates, + num_years=ppo.num_years), + atol=0.01, rtol=0.0) + assert np.allclose(ppo._rt7, + Policy._expand_array( + np.array([0.396]), + False, False, + inflate=False, + inflation_rates=inf_rates, + num_years=ppo.num_years), + atol=0.01, rtol=0.0) def test_parameters_get_default(): @@ -384,23 +379,23 @@ def test_implement_reform_Policy_raises_on_no_year(): def test_Policy_reform_in_start_year(): - ppo = Policy(start_year=2013) + ppo = Policy() reform = {2013: {'_STD': [[16000, 13000, 13000, 16000, 16000]]}} ppo.implement_reform(reform) - assert_allclose(ppo.STD, - np.array([16000, 13000, 13000, 16000, 16000]), - atol=0.01, rtol=0.0) + assert np.allclose(ppo.STD, + np.array([16000, 13000, 13000, 16000, 16000]), + atol=0.01, rtol=0.0) -def test_implement_reform_Policy_raises_on_future_year(): - ppo = Policy(start_year=2013) +def test_implement_reform_Policy_raises_on_early_year(): + ppo = Policy() reform = {2010: {'_STD_Aged': [[1400, 1100, 1100, 1400, 1400]]}} with pytest.raises(ValueError): ppo.implement_reform(reform) def test_Policy_reform_with_default_cpi_flags(): - ppo = Policy(start_year=2013) + ppo = Policy() reform = {2015: {'_II_em': [4300]}} ppo.implement_reform(reform) # '_II_em' has a default cpi_flag of True, so @@ -410,43 +405,47 @@ def test_Policy_reform_with_default_cpi_flags(): def test_Policy_reform_after_start_year(): - ppo = Policy(start_year=2013) + ppo = Policy() reform = {2015: {'_STD_Aged': [[1400, 1100, 1100, 1400, 1400]]}} ppo.implement_reform(reform) ppo.set_year(2015) - assert_allclose(ppo.STD_Aged, - np.array([1400, 1100, 1100, 1400, 1400]), - atol=0.01, rtol=0.0) + assert np.allclose(ppo.STD_Aged, + np.array([1400, 1100, 1100, 1400, 1400]), + atol=0.01, rtol=0.0) def test_Policy_reform_makes_no_changes_before_year(): - ppo = Policy(start_year=2013) + ppo = Policy() reform = {2015: {'_II_em': [4400], '_II_em_cpi': True}} ppo.implement_reform(reform) ppo.set_year(2015) - assert_allclose(ppo._II_em[:3], np.array([3900, 3950, 4400]), - atol=0.01, rtol=0.0) + assert np.allclose(ppo._II_em[:3], np.array([3900, 3950, 4400]), + atol=0.01, rtol=0.0) assert ppo.II_em == 4400 -def test_parameters_get_default_start_year(): - paramdata = Policy.default_data(metadata=True, start_year=2015) - # 1D data, has 2015 values +def test_parameters_get_default_data(): + paramdata = Policy.default_data(metadata=True) + # 1D data, has 2013+ values meta_II_em = paramdata['_II_em'] - assert meta_II_em['start_year'] == 2015 - assert meta_II_em['row_label'] == [str(cyr) for cyr in range(2015, 2027)] - assert meta_II_em['value'] == [4000, 4050, 4050] + [0] * 8 + [4883] - # 2D data, has 2015 values + assert meta_II_em['start_year'] == 2013 + assert meta_II_em['row_label'] == [str(cyr) for cyr in range(2013, 2027)] + expval = [3900, 3950, 4000, 4050, 4050] + [0] * 8 + [4883] + assert meta_II_em['value'] == expval + # 2D data, has 2013+ values meta_std_aged = paramdata['_STD_Aged'] - assert meta_std_aged['start_year'] == 2015 - assert meta_std_aged['row_label'] == ['2015', '2016', '2017'] - assert meta_std_aged['value'] == [[1550, 1250, 1250, 1550, 1550], + assert meta_std_aged['start_year'] == 2013 + explabels = ['2013', '2014', '2015', '2016', '2017'] + assert meta_std_aged['row_label'] == explabels + assert meta_std_aged['value'] == [[1500, 1200, 1200, 1500, 1500], + [1550, 1200, 1200, 1550, 1550], + [1550, 1250, 1250, 1550, 1550], [1550, 1250, 1250, 1550, 1550], [1550, 1250, 1250, 1550, 1550]] - # 1D data, doesn't have 2015 values, is not CPI inflated + # 1D data, has only 2013 values because is not CPI inflated meta_kt_c_age = paramdata['_AMT_KT_c_Age'] - assert meta_kt_c_age['start_year'] == 2015 - assert meta_kt_c_age['row_label'] == ['2015'] + assert meta_kt_c_age['start_year'] == 2013 + assert meta_kt_c_age['row_label'] == ['2013'] assert meta_kt_c_age['value'] == [24] @@ -553,11 +552,12 @@ def test_pop_the_cap_reform(): Test eliminating the maximum taxable earnings (MTE) used in the calculation of the OASDI payroll tax. """ - # clarify start year and create Policy parameters object - syr = 2013 - ppo = Policy(start_year=syr) + # create Policy parameters object + ppo = Policy() + assert ppo.current_year == Policy.JSON_START_YEAR # confirm that MTE has current-law values in 2015 and 2016 mte = ppo._SS_Earnings_c + syr = Policy.JSON_START_YEAR assert mte[2015 - syr] == 118500 assert mte[2016 - syr] == 118500 # specify a "pop the cap" reform that eliminates MTE cap in 2016 @@ -580,9 +580,9 @@ def test_order_of_cpi_and_level_reforms(): {2015: {'_SS_Earnings_c_cpi': False, '_SS_Earnings_c': [500000]}}] # specify two Policy objects - syr = 2013 - ppo = [Policy(start_year=syr), Policy(start_year=syr)] + ppo = [Policy(), Policy()] # apply reforms to corresponding Policy object & check post-reform values + syr = Policy.JSON_START_YEAR for ref in range(len(reform)): # confirm pre-reform MTE values in 2014-17 mte = ppo[ref]._SS_Earnings_c