def test_inversion():
    survey_scenario = get_survey_scenario(year = 2012, reform_key = 'inversion_directe_salaires')
    survey_scenario.summarize_variable('salaire_de_base', force_compute = True)

    survey_scenario.summarize_variable('salaire_imposable', force_compute = True)
    survey_scenario.summarize_variable('salaire_de_base', force_compute = True)

    survey_scenario.summarize_variable('csg_imposable_salaire')
    data_frame_by_entity = survey_scenario.create_data_frame_by_entity(
        variables = [
            'salaire_de_base',
            'salaire_imposable',
            # 'csg_imposable_salaire',
            'categorie_salarie',
            'salaire_imposable_pour_inversion',
            # 'weight_individus',
            # 'wprm',
            ],
        )
    print data_frame_by_entity

    #famille = data_frame_by_entity['famille']
    individu = data_frame_by_entity['individu']
    menage = data_frame_by_entity['menage']

    individu.categorie_salarie.value_counts()
    prive = individu.query('categorie_salarie in [0, 1]')
    (prive.salaire_imposable - prive.salaire_imposable_pour_inversion).abs().max()
    survey_scenario.summarize_variable('salaire_imposable_pour_inversion')
    survey_scenario.summarize_variable('csg_deductible_salaire')
    survey_scenario.summarize_variable('chomage_brut')
def test_inflation():
    period = year = 2012
    survey_scenario = get_survey_scenario(year = year, tax_benefit_system = base_survey.france_data_tax_benefit_system)
    target_by_variable = dict(
        salaire_imposable = 1.2e08,
        )
    survey_scenario.inflate(target_by_variable = target_by_variable, period = period)
    assert abs(survey_scenario.compute_aggregate('salaire_imposable', period = period) - 1.2e08) / 1.2e08 < 1e-6, \
        "{} != {}".format(survey_scenario.compute_aggregate('salaire_imposable', period = period), 1.2e08)
def test_inflation():
    period = year = 2012
    survey_scenario = get_survey_scenario(
        year=year,
        tax_benefit_system=base_survey.france_data_tax_benefit_system)
    target_by_variable = dict(salaire_imposable=1.2e08, )
    survey_scenario.inflate(target_by_variable=target_by_variable,
                            period=period)
    assert abs(survey_scenario.compute_aggregate('salaire_imposable', period = period) - 1.2e08) / 1.2e08 < 1e-6, \
        "{} != {}".format(survey_scenario.compute_aggregate('salaire_imposable', period = period), 1.2e08)
def test_erfs_fpr_survey_simulation_aggregates(year = 2012, rebuild_input_data = False):
    np.seterr(all = 'raise')
    tax_benefit_system = base_survey.france_data_tax_benefit_system

    survey_scenario = get_survey_scenario(
        tax_benefit_system = tax_benefit_system,
        baseline_tax_benefit_system = tax_benefit_system,
        year = year,
        rebuild_input_data = rebuild_input_data,
        )
    return survey_scenario
Exemple #5
0
def test_rebuild_input_data(year = 2014):

    tax_benefit_system = base_survey.france_data_tax_benefit_system

    survey_scenario = get_survey_scenario(
        tax_benefit_system = tax_benefit_system,
        baseline_tax_benefit_system = tax_benefit_system,
        year = year,
        rebuild_input_data = True,
        )
    return survey_scenario
def test_rebuild_input_data(year = 2012):

    tax_benefit_system = base_survey.france_data_tax_benefit_system

    survey_scenario = get_survey_scenario(
        tax_benefit_system = tax_benefit_system,
        baseline_tax_benefit_system = tax_benefit_system,
        year = year,
        rebuild_input_data = True,
        )
    return survey_scenario
Exemple #7
0
def test_erfs_fpr_survey_simulation_aggregates(year = 2014, rebuild_input_data = False):
    np.seterr(all = 'raise')
    tax_benefit_system = france_data_tax_benefit_system

    survey_scenario = get_survey_scenario(
        tax_benefit_system = tax_benefit_system,
        year = year,
        rebuild_input_data = rebuild_input_data,
        )
    aggregates = Aggregates(survey_scenario = survey_scenario)

    return survey_scenario, aggregates
def test_erfs_fpr_survey_simulation(year=2012, rebuild_input_data=False):
    tax_benefit_system = base_survey.get_cached_reform(
        reform_key='inversion_directe_salaires',
        tax_benefit_system=base_survey.france_data_tax_benefit_system,
    )
    survey_scenario = get_survey_scenario(
        tax_benefit_system=tax_benefit_system,
        baseline_tax_benefit_system=tax_benefit_system,
        year=year,
        rebuild_input_data=rebuild_input_data,
    )
    data_frame_by_entity = None
    #    data_frame_by_entity = survey_scenario.create_data_frame_by_entity(
    #        variables = variables,
    #        )
    #    loose_check(data_frame_by_entity)
    return survey_scenario, data_frame_by_entity
def test_erfs_fpr_survey_simulation(year = 2012, rebuild_input_data = False):
    tax_benefit_system = base_survey.get_cached_reform(
        reform_key = 'inversion_directe_salaires',
        tax_benefit_system = base_survey.france_data_tax_benefit_system,
        )
    survey_scenario = get_survey_scenario(
        tax_benefit_system = tax_benefit_system,
        baseline_tax_benefit_system = tax_benefit_system,
        year = year,
        rebuild_input_data = rebuild_input_data,
        )
    data_frame_by_entity = None
    #    data_frame_by_entity = survey_scenario.create_data_frame_by_entity(
#        variables = variables,
#        )
#    loose_check(data_frame_by_entity)
    return survey_scenario, data_frame_by_entity
def test_create_salaire_de_base(year, revenu_type = 'net'):
    """
    Test create_salaire_de_base avec données de l'enquête erfs_fpr
    """
    temporary_store = get_store(file_name = 'erfs_fpr')
    individu = temporary_store['individu_for_inversion_{}'.format(year)]

    if revenu_type == 'net':
        salaire_pour_inversion = individu.salaire_net.copy()
    elif revenu_type == 'imposable':
        salaire_pour_inversion = individu.salaire_imposable.copy()

    id_variables = ['idfoy', 'idmen', 'idfam']
    for id_variable in id_variables:
        individu[id_variable] = range(0, len(individu))

    position_variables = ['quifoy', 'quimen', 'quifam']
    for position_variable in position_variables:
        individu[position_variable] = 0

    data = dict(
        input_data_frame_by_entity = dict(
            individu = individu,
            )
        )
    survey_scenario = get_survey_scenario(
        year = year,
        data = data,
        )

    survey_scenario.tax_benefit_system.neutralize_variable('indemnite_residence')

    variables = set(
        variables_de_base
        + variables_nulles_hors_prive
        + variables_nulles_hors_fonction_publique
        )
    data_frame = survey_scenario.create_data_frame_by_entity(
        variables = variables, period = periods.period(year)
        )['individu']
    data_frame['salaire_pour_inversion'] = salaire_pour_inversion
    data_frame.rename(columns = {'salaire_{}'.format(revenu_type): 'salaire'}, inplace = True)

    return survey_scenario, data_frame
Exemple #11
0
def test_erfs_fpr_aggregates_reform():
    '''
    test aggregates value with data
    :param year: year of data and simulation to test agregates
    :param reform: optional argument, put an openfisca_france.refoms object, default None
    '''
    tax_benefit_system = france_data_tax_benefit_system
    year = 2014
    survey_scenario = get_survey_scenario(
        reform = 'plf2015',
        baseline_tax_benefit_system = tax_benefit_system,
        year = year,
        rebuild_input_data = False,
        )
    aggregates = Aggregates(survey_scenario = survey_scenario)
    base_data_frame = aggregates.compute_aggregates()
    difference_data_frame = aggregates.compute_difference()

    return aggregates, base_data_frame, difference_data_frame
def test_erfs_fpr_aggregates_reform():
    '''
    test aggregates value with data
    :param year: year of data and simulation to test agregates
    :param reform: optional argument, put an openfisca_france.refoms object, default None
    '''
    tax_benefit_system = base_survey.france_data_tax_benefit_system
    year = 2012
    survey_scenario = get_survey_scenario(
        reform_key = 'plf2015',
        baseline_tax_benefit_system = tax_benefit_system,
        year = year,
        rebuild_input_data = False,
        )
    aggregates = Aggregates(survey_scenario = survey_scenario)
    base_data_frame = aggregates.compute_aggregates()
    difference_data_frame = aggregates.compute_difference()

    return aggregates, base_data_frame, difference_data_frame
def test_erfs_survey_simulation(year=2009):
    tax_benefit_system = base_survey.get_cached_reform(
        reform_key='inversion_directe_salaires',
        tax_benefit_system=base_survey.france_data_tax_benefit_system,
    )
    survey_scenario = get_survey_scenario(
        tax_benefit_system=tax_benefit_system,
        baseline_tax_benefit_system=tax_benefit_system,
        year=year,
    )

    data_frame_by_entity = survey_scenario.create_data_frame_by_entity(
        variables=variables,
        period=year,
    )
    loose_check(data_frame_by_entity)
    assert (data_frame_by_entity['familles'].weight_familles *
            data_frame_by_entity['familles'].af).sum() / 1e9 > 10

    return survey_scenario, data_frame_by_entity
def test_erfs_survey_simulation(year = 2009):
    tax_benefit_system = base_survey.get_cached_reform(
        reform_key = 'inversion_directe_salaires',
        tax_benefit_system = base_survey.france_data_tax_benefit_system,
        )
    survey_scenario = get_survey_scenario(
        tax_benefit_system = tax_benefit_system,
        baseline_tax_benefit_system = tax_benefit_system,
        year = year,
        )

    data_frame_by_entity = survey_scenario.create_data_frame_by_entity(
        variables = variables,
        period = year,
        )
    loose_check(data_frame_by_entity)
    assert (
        data_frame_by_entity['familles'].weight_familles * data_frame_by_entity['familles'].af
        ).sum() / 1e9 > 10

    return survey_scenario, data_frame_by_entity
def test_create_salaire_de_base(year, revenu_type='net'):
    """
    Test create_salaire_de_base avec données de l'enquête erfs_fpr
    """
    temporary_store = get_store(file_name='erfs_fpr')
    individu = temporary_store['individu_for_inversion_{}'.format(year)]

    if revenu_type == 'net':
        salaire_pour_inversion = individu.salaire_net.copy()
    elif revenu_type == 'imposable':
        salaire_pour_inversion = individu.salaire_imposable.copy()

    id_variables = ['idfoy', 'idmen', 'idfam']
    for id_variable in id_variables:
        individu[id_variable] = range(0, len(individu))

    position_variables = ['quifoy', 'quimen', 'quifam']
    for position_variable in position_variables:
        individu[position_variable] = 0

    data = dict(input_data_frame_by_entity=dict(individu=individu, ))
    survey_scenario = get_survey_scenario(
        year=year,
        data=data,
    )

    survey_scenario.tax_benefit_system.neutralize_variable(
        'indemnite_residence')

    variables = set(variables_de_base + variables_nulles_hors_prive +
                    variables_nulles_hors_fonction_publique)
    data_frame = survey_scenario.create_data_frame_by_entity(
        variables=variables, period=periods.period(year))['individu']
    data_frame['salaire_pour_inversion'] = salaire_pour_inversion
    data_frame.rename(columns={'salaire_{}'.format(revenu_type): 'salaire'},
                      inplace=True)

    return survey_scenario, data_frame
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#%%

from __future__ import division


from openfisca_france_data.erfs_fpr.get_survey_scenario import get_survey_scenario


survey_scenario = get_survey_scenario(year = 2012, reform_key = 'inversion_directe_salaires')

#%%
data_frame_by_entity = survey_scenario.create_data_frame_by_entity(
    variables = [
        'af_base',
        'af_nbenf',
        'age_en_mois',
        'age',
        'autonomie_financiere',
        'af_eligibilite_base',
        'menage_ordinaire_familles',
        'est_enfant_dans_famille',
        'prestations_familiales_enfant_a_charge',
        'rempli_obligation_scolaire',
        'residence_dom',
        'weight_familles',
        'weight_individus',
        'wprm',
        ],
    )
Exemple #17
0
# -*- coding: utf-8 -*-

from openfisca_france_data.erfs_fpr.get_survey_scenario import get_survey_scenario
from openfisca_france_data.reforms.inversion_directe_salaires import inversion_directe_salaires

survey_scenario = get_survey_scenario(year=2014,
                                      reform=inversion_directe_salaires)

data_frame_by_entity = survey_scenario.create_data_frame_by_entity(variables=[
    'irpp',
    'maries_ou_pacses',
    'nbptr',
    'rfr',
    'revenu_assimile_salaire',
    'statut_marital',
    'weight_foyers',
    'weight_individus',
], )

famille = data_frame_by_entity['famille']
foyer_fiscal = data_frame_by_entity['foyer_fiscal']
individu = data_frame_by_entity['individu']
menage = data_frame_by_entity['menage']

# statut_occupation
statut_marital = individu.groupby('statut_marital')['weight_individus'].sum()
assert 22e6 < statut_marital[1] < 25e6
assert 30e6 < statut_marital[2] < 32e6

foyer_fiscal.groupby('maries_ou_pacses')['weight_foyers'].sum() / 1e6
foyer_fiscal.groupby('nbptr')['weight_foyers'].sum() / 1e6
# -*- coding: utf-8 -*-

import logging

from openfisca_france_data import france_data_tax_benefit_system
from openfisca_france_data.erfs_fpr.get_survey_scenario import get_survey_scenario

log = logging.getLogger(__name__)

year = 2014
tax_benefit_system = france_data_tax_benefit_system

survey_scenario = get_survey_scenario(
    tax_benefit_system=tax_benefit_system,
    baseline_tax_benefit_system=tax_benefit_system,
    year=year,
    rebuild_input_data=False,
)

checks_by_variable = {'salaire_de_base': {'min': 500e9}}

for variable in survey_scenario.used_as_input_variables:
    checks = checks_by_variable.get(variable)
    print(variable)
    minimum = checks.get('min') if checks is not None else None
    if minimum:
        assert survey_scenario.compute_aggregate(variable,
                                                 period=2014) >= minimum
    survey_scenario.summarize_variable(variable)