def test_fill_cohort(): population = create_empty_population_dataframe(2001, 2061) profiles = create_constant_profiles_dataframe(population, tax = -1, subsidies = 0.5) cohorts_test = DataCohorts(data = population, columns = ['pop']) cohorts_test._fill(profiles, year = None) test_value = cohorts_test.get_value((0,0,2060), 'tax') assert test_value == -1
def test_generation_extraction(): # Creating a fake cohort n = 0.00 r = 0.00 g = 0.05 population = create_testing_population_dataframe(year_start=2001, year_end=2061, rate=n) profile = create_constant_profiles_dataframe(population, tax=-1, sub=0.5) cohort = DataCohorts(population) # Applying projection methods year_length = 199 method = 'stable' cohort.population_project(year_length, method = method) cohort._fill(profile) typ = None cohort.proj_tax(g, r, typ, method = 'per_capita') cohort = AccountingCohorts(cohort) cohort._types = ['tax'] #Extracting generations start = 2030 age = 0 generation = cohort.extract_generation(start, typ = 'tax', age = age) count = age while count <= 100 & start + count <= array(list(generation.index_sets['year'])).max(): assert abs((1+g)**(count+(start-2001)) + generation.get_value((count, 1, start+count), 'tax')) == 0.0 count +=1
def test_fill_cohort(): population = create_empty_population_dataframe(2001, 2061) profiles = create_constant_profiles_dataframe(population, tax=-1, subsidies=0.5) cohorts_test = DataCohorts(data=population, columns=['pop']) cohorts_test._fill(profiles, year=None) test_value = cohorts_test.get_value((0, 0, 2060), 'tax') assert test_value == -1
def test_filter_value(): """ Testing the method to filter data from a given cohort """ #Generate a testing cohort with 5% population and economy growth n = 0.05 population = create_testing_population_dataframe(year_start=2001, year_end=2061, rate=n) profile = create_constant_profiles_dataframe(population, tax=-1, sub=0.5) cohort = DataCohorts(population) cohort._fill(profile) r = 0.0 g = 0.05 column = None cohort.proj_tax(g, r, column, method='per_capita') #Testing restrictions cohort_filtered = cohort.filter_value(age=list(range(0, 100, 1)), year=list(range(2001, 2060, 5)), typ='tax') count = 2001 while count <= 2060: assert abs( cohort_filtered.get_value((0, 1, count), 'tax') + (1 + g)**(count - 2001)) == 0.0 count += 5
def test_population_projection(): # Create cohorts start_data = 2001 end_data = 2061 population = create_empty_population_dataframe(start_data, end_data) cohorts = DataCohorts(data = population, columns = ['pop']) # Complete population projection year_length = 100 end_project = start_data + year_length method = 'exp_growth' growth_rate = n = 0.05 cohorts.population_project(year_length, method = method, growth_rate = n) year_control = 2082 control_value = (1+n)**(year_control - end_data - 1) test_value = cohorts.get_value((0,0,2081), "pop") assert test_value == control_value
def test_population_projection(): # Create cohorts start_data = 2001 end_data = 2061 population = create_empty_population_dataframe(start_data, end_data) cohorts = DataCohorts(data=population, columns=['pop']) # Complete population projection year_length = 100 end_project = start_data + year_length method = 'exp_growth' growth_rate = n = 0.05 cohorts.population_project(year_length, method=method, growth_rate=n) year_control = 2082 control_value = (1 + n)**(year_control - end_data - 1) test_value = cohorts.get_value((0, 0, 2081), "pop") assert test_value == control_value
def test_tax_projection(): population = create_empty_population_dataframe(2001, 2061) profile = create_constant_profiles_dataframe(population, tax=-1, sub=0.5) g = 0.05 r = 0 cohort = DataCohorts(population) year_length = 200 method = 'stable' cohort.population_project(year_length, method=method) cohort._fill(profile) typ = None cohort.proj_tax(g, r, typ, method='per_capita') # print cohort test_value = cohort.get_value((0, 1, 2002), 'tax') test_value2 = cohort.get_value((0, 1, 2002), 'sub') # print test_value, test_value2 # TODO: I don't understand the following <- Just wanted to check if the for loop works by changing the value of typ in the test assert test_value2 > 0.5 and test_value < -1
def test_create_age_class(): """ Testing the method to regroup age classes """ population = create_testing_population_dataframe(2001, 2003) profile = create_constant_profiles_dataframe(population, tax = 1.0, sub=-0.5) cohort = DataCohorts(population) cohort._fill(profile) cohort2 = cohort.per_capita_generation_present_value('tax', discount_rate=0) print cohort2.head() print cohort2.tail() step = 5.0 age_class = cohort2.create_age_class(step = step, typ='tax') print age_class.tail(10) count = 0 while count < 100: assert age_class.get_value((count, 1, 2001), 'tax') == 2, 'valeur obtenue %f' %(age_class.get_value((count, 1, 2001), 'tax')) count += step
def create_neutral_profiles_cohort(population): """ Utility function which generates a DataCohort with population and transfers. No projection is needed, the dataframe is delivered without "hole" Parameters ---------- population : Int The value of the constant population at each period and for each age Returns ------- cohort : a cohort dataframe such that : Anybody below 50 years old (excluded) pays -1 Anybody between 50 and 99 years old (included) recieve 1 Anybody over 100 years old (included) pays 0 As such, the total net transfer is zero for newborns """ n = 0 population_dataframe = create_testing_population_dataframe(year_start=2001, year_end=2201, rate=n, population=population) # print population.get_value((0,0,2011), 'pop') profile = create_constant_profiles_dataframe(population_dataframe, tax=-1) g = 0.0 r = 0.0 cohort = DataCohorts(population_dataframe) cohort._fill(profile) cohort.loc[cohort.index.get_level_values(0) >= 0,'tax'] = -1 cohort.loc[cohort.index.get_level_values(0) >= 50,'tax'] = 1 cohort.loc[cohort.index.get_level_values(0) == 100,'tax'] = 0 typ = 'tax' cohort.proj_tax(g, r, typ, method = 'per_capita') return cohort
def test_tax_projection_aggregated(): n = 1 population = create_testing_population_dataframe(year_start=2001, year_end=2061, rate=n) profile = create_constant_profiles_dataframe(population, tax=-1, sub=0.5) g = 0.5 r = 0.0 cohort = DataCohorts(population) cohort._fill(profile) typ = None cohort.proj_tax(g, r, typ, method='aggregate') test_value = cohort.get_value((0, 1, 2002), 'tax') test_value2 = cohort.get_value((0, 1, 2002), 'sub') assert test_value2 < 0.5 and test_value > -1
def test_tax_projection(): population = create_empty_population_dataframe(2001, 2061) profile = create_constant_profiles_dataframe(population, tax = -1, sub=0.5) g = 0.05 r = 0 cohort = DataCohorts(population) year_length = 200 method = 'stable' cohort.population_project(year_length, method = method) cohort._fill(profile) typ = None cohort.proj_tax(g, r, typ, method = 'per_capita') # print cohort test_value = cohort.get_value((0,1,2002), 'tax') test_value2 = cohort.get_value((0,1,2002), 'sub') # print test_value, test_value2 # TODO: I don't understand the following <- Just wanted to check if the for loop works by changing the value of typ in the test assert test_value2 > 0.5 and test_value < -1
def test_create_age_class(): """ Testing the method to regroup age classes """ population = create_testing_population_dataframe(2001, 2003) profile = create_constant_profiles_dataframe(population, tax=1.0, sub=-0.5) cohort = DataCohorts(population) cohort._fill(profile) cohort2 = cohort.per_capita_generation_present_value('tax', discount_rate=0) print cohort2.head() print cohort2.tail() step = 5.0 age_class = cohort2.create_age_class(step=step, typ='tax') print age_class.tail(10) count = 0 while count < 100: assert age_class.get_value( (count, 1, 2001), 'tax') == 2, 'valeur obtenue %f' % (age_class.get_value( (count, 1, 2001), 'tax')) count += step
def test_tax_projection_aggregated(): n = 1 population = create_testing_population_dataframe(year_start=2001, year_end=2061, rate=n) profile = create_constant_profiles_dataframe(population, tax=-1, sub=0.5) g = 0.5 r = 0.0 cohort = DataCohorts(population) cohort._fill(profile) typ = None cohort.proj_tax(g, r, typ, method = 'aggregate') test_value = cohort.get_value((0,1,2002), 'tax') test_value2 = cohort.get_value((0,1,2002), 'sub') assert test_value2 < 0.5 and test_value > -1
def test_compute_net_transfers(): population = create_empty_population_dataframe(2001, 2061) profiles = create_constant_profiles_dataframe(population, tax=1, subsidies=0.5) tax = ['tax'] subsidy = ['subsidies'] cohorts_test = DataCohorts(data=population, columns=['pop']) cohorts_test._fill(profiles, year=None) cohorts_test.compute_net_transfers(taxes_list=tax, payments_list=subsidy) test_value = cohorts_test.get_value((0, 0, 2060), 'net_transfers') assert test_value == 0.5 pass
def test_compute_net_transfers(): population = create_empty_population_dataframe(2001, 2061) profiles = create_constant_profiles_dataframe(population, tax = 1, subsidies = 0.5) tax = ['tax'] subsidy = ['subsidies'] cohorts_test = DataCohorts(data = population, columns = ['pop']) cohorts_test._fill(profiles, year = None) cohorts_test.compute_net_transfers(taxes_list = tax, payments_list = subsidy) test_value = cohorts_test.get_value((0,0,2060), 'net_transfers') assert test_value == 0.5 pass
def test_filter_value(): """ Testing the method to filter data from a given cohort """ # Generate a testing cohort with 5% population and economy growth n = 0.05 population = create_testing_population_dataframe(year_start=2001, year_end=2061, rate=n) profile = create_constant_profiles_dataframe(population, tax=-1, sub=0.5) cohort = DataCohorts(population) cohort._fill(profile) r = 0.0 g = 0.05 column = None cohort.proj_tax(g, r, column, method="per_capita") # Testing restrictions cohort_filtered = cohort.filter_value(age=list(range(0, 100, 1)), year=list(range(2001, 2060, 5)), typ="tax") count = 2001 while count <= 2060: assert abs(cohort_filtered.get_value((0, 1, count), "tax") + (1 + g) ** (count - 2001)) == 0.0 count += 5
def test_generation_extraction(): # Creating a fake cohort n = 0.00 r = 0.00 g = 0.05 population = create_testing_population_dataframe(year_start=2001, year_end=2061, rate=n) profile = create_constant_profiles_dataframe(population, tax=-1, sub=0.5) cohort = DataCohorts(population) # Applying projection methods year_length = 199 method = 'stable' cohort.population_project(year_length, method=method) cohort._fill(profile) typ = None cohort.proj_tax(g, r, typ, method='per_capita') cohort = AccountingCohorts(cohort) cohort._types = ['tax'] #Extracting generations start = 2030 age = 0 generation = cohort.extract_generation(start, typ='tax', age=age) count = age while count <= 100 & start + count <= array( list(generation.index_sets['year'])).max(): assert abs((1 + g)**(count + (start - 2001)) + generation.get_value((count, 1, start + count), 'tax')) == 0.0 count += 1