def test_indexing_rates_for_update(): """ Check private _indexing_rates_for_update method. """ pol = Policy() wgrates = pol._indexing_rates_for_update('_SS_Earnings_c', 2017, 10) pirates = pol._indexing_rates_for_update('_II_em', 2017, 10) assert len(wgrates) == len(pirates)
def propagate_user_list(x, name, defaults, cpi, first_budget_year, multi_param_idx=-1): """ Dispatch to either expand_1D or expand2D depending on the dimension of x Parameters: ----------- x : list from user to propagate forward in time. The first value is for year 'first_budget_year'. The value at index i is the value for budget year first_budget_year + i. defaults: list of default values; our result must be at least this long name: the parameter name for looking up the indexing rate cpi: Bool first_budget_year: int multi_param_idx: int, optional. If this parameter is multi-valued, this is the index for which the values for 'x' apply. So, for exampe, if multi_param_idx=0, the values for x are typically for the 'single' filer status. -1 indidcates that this is not a multi-valued parameter Returns: -------- list of length 'num_years'. if 'cpi'==True, the values will be inflated based on the last value the user specified """ # x must have a real first value assert len(x) > 0 assert x[0] not in ("", None) num_years = max(len(defaults), len(x)) is_rate = any([i < 1.0 for i in x]) current_policy = Policy(start_year=2013) current_policy.set_year(first_budget_year) # irates are rates for 2015, 2016, and 2017 if cpi: irates = current_policy._indexing_rates_for_update( param_name=name, calyear=first_budget_year, num_years_to_expand=num_years) else: irates = [0.0] * num_years ans = [None] * num_years for i in range(num_years): if i < len(x): if is_wildcard(x[i]): if multi_param_idx > -1: ans[i] = defaults[i][multi_param_idx] else: ans[i] = defaults[i] else: ans[i] = x[i] if ans[i] is not None: continue else: newval = ans[i - 1] * (1.0 + irates[i - 1]) ans[i] = newval if is_rate else int(newval) return ans