Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests #82

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
f7f6b13
Add coicop option to TBS
benjello Jan 31, 2020
dc66562
Fix tests
benjello Feb 11, 2020
7135ca9
Fix import
benjello Feb 12, 2020
70c3a4b
Fix ceq deps
benjello Feb 12, 2020
abc0236
Clean
benjello Feb 21, 2020
aec797d
add parameters
nirirazaka Mar 5, 2020
6108e01
add variables
nirirazaka Mar 5, 2020
bf76d86
add test
nirirazaka Mar 5, 2020
4a14a9b
WIP (missing cadre)
benjello Mar 5, 2020
160728a
flake8
benjello Mar 6, 2020
c73f0ac
add retraite cadres
nirirazaka Mar 6, 2020
ccb5e22
lil correction
nirirazaka Mar 6, 2020
205f1e3
WIP
benjello Mar 6, 2020
a3c8e20
WIP (missing retraite complémentaire)
benjello Mar 6, 2020
a83e3bb
WIP prelevements sociaux et inverion
benjello Mar 21, 2020
c36576e
Improve bareme
benjello Mar 21, 2020
a5abacb
Rename categorie droit douane
benjello Mar 27, 2020
d46b6ab
WIP salaire_brut.yaml
benjello Mar 27, 2020
32521ba
droit progressif avant reforme
nirirazaka Mar 27, 2020
8098af6
add droit proportionnel params
nirirazaka Mar 27, 2020
ab5fcd3
droit proportionnel variables & little correction
nirirazaka Mar 30, 2020
39b3b60
Fix bareme and add taxes
benjello Apr 1, 2020
e5cab60
correction impot_proportionnel
nirirazaka Apr 2, 2020
6ee3f5c
WIP droit proportionnel
benjello Apr 3, 2020
28f9b41
Merge branch 'wip_impot_avant_reforme_bis' of https://github.com/open…
nirirazaka Apr 3, 2020
82ca289
add parameters CGU
nirirazaka Apr 3, 2020
9a10a90
correct dates
nirirazaka Apr 3, 2020
d89908a
Fix droit_progressif avant 2013
benjello Apr 4, 2020
b70125e
Clean escaping parameters
benjello Apr 4, 2020
4d1b294
add cgf parameters
nirirazaka Apr 7, 2020
b6f9e82
Introduce impot_revenu
benjello Apr 7, 2020
c5a569f
Inversion salaire to improve
benjello Apr 10, 2020
bc07f12
abattement to parameters droit_progressif
nirirazaka Apr 14, 2020
7a54daa
fix tva test
benjello Apr 15, 2020
09aa52e
Omprove inversion and add taxes_specifiques
benjello Apr 15, 2020
c3c0d0b
flake8
benjello Apr 15, 2020
0b680ec
flake8
benjello Apr 15, 2020
7332f5c
flake8
benjello Apr 15, 2020
28f1032
Remove unused test
benjello Apr 15, 2020
e5521d6
Fix inversion
benjello Apr 22, 2020
05fbb47
Inversion of pension_retraite
benjello Apr 30, 2020
b22a313
Complete gross income
benjello May 7, 2020
3aadbdd
Various cleaning
benjello Jun 10, 2020
ca8c60d
CFCE and other corrections
benjello Jun 25, 2020
7c9b696
Change est_* variables to *
benjello Jul 10, 2020
573a9ab
Bump autopep8 from 1.5 to 1.5.4
dependabot-preview[bot] Aug 2, 2020
cb5f8af
Update yamllint requirement from <1.21,>=1.11.1 to >=1.11.1,<1.25
dependabot-preview[bot] Jul 15, 2020
f65b905
Fix tests
benjello Dec 1, 2020
144159b
Fix deps
benjello Dec 2, 2020
a524676
Fix flake8
benjello Dec 2, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions notebooks/Fake-data-Senegal.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@
},
"outputs": [],
"source": [
"est_marie = np.random.binomial(1, .66, size = size)\n",
"est_celibataire = np.logical_not(est_marie)\n",
"marie = np.random.binomial(1, .66, size = size)\n",
"est_celibataire = np.logical_not(marie)\n",
"nombre_enfants = np.maximum(\n",
" est_marie * np.round(np.random.normal(5, scale = 3, size = size)),\n",
" marie * np.round(np.random.normal(5, scale = 3, size = size)),\n",
" 0,\n",
" )"
]
Expand Down Expand Up @@ -172,11 +172,11 @@
"outputs": [],
"source": [
"input_data_frame = pd.DataFrame({\n",
" 'est_marie': est_marie,\n",
" 'marie': marie,\n",
" 'est_celibataire': est_celibataire,\n",
" 'nombre_enfants': nombre_enfants,\n",
" 'pension_retraite': pension_retraite,\n",
" 'salaire': salaire,\n",
" 'salaire_imposable': salaire,\n",
" 'id_menage': range(size),\n",
" 'role_menage': 0,\n",
" })"
Expand Down Expand Up @@ -542,9 +542,9 @@
" senegal_tax_benefit_system = SenegalTaxBenefitSystem()\n",
" class impot_revenus(Variable):\n",
" def formula(individu, period):\n",
" impot_avant_reduction_famille = individu('impot_avant_reduction_famille', period)\n",
" droit_progressif = individu('droit_progressif', period)\n",
" reduction_impots_pour_charge_famille = individu('reduction_impots_pour_charge_famille', period)\n",
" impot_apres_reduction_famille = impot_avant_reduction_famille - reduction_impots_pour_charge_famille\n",
" impot_apres_reduction_famille = droit_progressif - reduction_impots_pour_charge_famille\n",
" impot_revenus = max_(0, impot_apres_reduction_famille)\n",
" return impot_revenus * (impot_revenus > seuil) \n",
"\n",
Expand Down
62 changes: 31 additions & 31 deletions notebooks/Senegalese tax and benefit system from scratch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,14 @@
},
"outputs": [],
"source": [
"class est_marie(Variable):\n",
"class marie(Variable):\n",
" value_type = bool\n",
" definition_period = YEAR\n",
" entity = Person\n",
" label = u\"Est marié\"\n",
" set_input = set_input_dispatch_by_period\n",
"\n",
"tax_benefit_system.update_variable(est_marie)\n",
"tax_benefit_system.update_variable(marie)\n",
"\n",
"\n",
"class conjoint_a_des_revenus(Variable):\n",
Expand Down Expand Up @@ -304,8 +304,8 @@
" nombre_de_parts_enfants = individu('nombre_enfants', period) * 0.5\n",
"\n",
" conjoint_a_des_revenus = individu('conjoint_a_des_revenus', period)\n",
" est_marie = individu('est_marie', period)\n",
" nombre_de_parts_conjoint = est_marie * 0.5 + (1 - conjoint_a_des_revenus) * 0.5\n",
" marie = individu('marie', period)\n",
" nombre_de_parts_conjoint = marie * 0.5 + (1 - conjoint_a_des_revenus) * 0.5\n",
"\n",
" nombre_de_parts = 1 + nombre_de_parts_conjoint + nombre_de_parts_enfants\n",
"\n",
Expand All @@ -315,17 +315,17 @@
"tax_benefit_system.update_variable(nombre_de_parts)\n",
"\n",
"\n",
"class impot_avant_reduction_famille(Variable):\n",
"class droit_progressif(Variable):\n",
" value_type = float\n",
" definition_period = YEAR\n",
" entity = Person\n",
"\n",
" def formula(individu, period, legislation):\n",
" salaire = individu('salaire', period, options = [ADD])\n",
" bareme_impot_progressif = legislation(period).bareme_impot_progressif\n",
" salaire = individu('salaire_imposable', period, options = [ADD])\n",
" bareme_impot_progressif = parameters(period).bareme_impot_progressif\n",
" return bareme_impot_progressif.calc(salaire)\n",
"\n",
"tax_benefit_system.update_variable(impot_avant_reduction_famille)\n",
"tax_benefit_system.update_variable(droit_progressif)\n",
"\n",
"\n",
"class reduction_impots_pour_charge_famille(Variable):\n",
Expand All @@ -334,10 +334,10 @@
" entity = Person\n",
"\n",
" def formula(individu, period, legislation):\n",
" impot_avant_reduction_famille = individu('impot_avant_reduction_famille', period)\n",
" droit_progressif = individu('droit_progressif', period)\n",
" \n",
" nombre_de_parts = individu('nombre_de_parts', period)\n",
" reductions_pour_charge_de_famille = legislation(period).reductions_pour_charge_de_famille\n",
" reductions_pour_charge_de_famille = parameters(period).reductions_pour_charge_de_famille\n",
" taux = (nombre_de_parts == 1) * reductions_pour_charge_de_famille.taux_1 + \\\n",
" (nombre_de_parts == 1.5) * reductions_pour_charge_de_famille.taux_2 + \\\n",
" (nombre_de_parts == 2) * reductions_pour_charge_de_famille.taux_3 + \\\n",
Expand Down Expand Up @@ -365,7 +365,7 @@
" (nombre_de_parts == 4) * reductions_pour_charge_de_famille.max_7 + \\\n",
" (nombre_de_parts == 4.5) * reductions_pour_charge_de_famille.max_8 + \\\n",
" (nombre_de_parts == 5) * reductions_pour_charge_de_famille.max_9\n",
" reduction_impot = np.clip(impot_avant_reduction_famille * taux, a_min=minimum, a_max=maximum)\n",
" reduction_impot = np.clip(droit_progressif * taux, a_min=minimum, a_max=maximum)\n",
" return reduction_impot\n",
"\n",
"tax_benefit_system.update_variable(reduction_impots_pour_charge_famille)\n",
Expand All @@ -377,9 +377,9 @@
" entity = Person\n",
"\n",
" def formula(individu, period):\n",
" impot_avant_reduction_famille = individu('impot_avant_reduction_famille', period)\n",
" droit_progressif = individu('droit_progressif', period)\n",
" reduction_impots_pour_charge_famille = individu('reduction_impots_pour_charge_famille', period)\n",
" impot_apres_reduction_famille = impot_avant_reduction_famille - reduction_impots_pour_charge_famille\n",
" impot_apres_reduction_famille = droit_progressif - reduction_impots_pour_charge_famille\n",
" return np.maximum(0, impot_apres_reduction_famille)\n",
"\n",
"tax_benefit_system.update_variable(impot_revenus)"
Expand All @@ -406,8 +406,8 @@
"source": [
"scenario.init_single_entity(\n",
" parent1={\n",
" 'salaire': 1800000,\n",
" 'est_marie': True,\n",
" 'salaire_imposable': 1800000,\n",
" 'marie': True,\n",
" 'conjoint_a_des_revenus': False,\n",
" 'nombre_enfants': 2,\n",
" },\n",
Expand All @@ -434,7 +434,7 @@
},
"outputs": [],
"source": [
"simulation.individu('salaire', period='2015')"
"simulation.individu('salaire_imposable', period='2015')"
]
},
{
Expand All @@ -445,7 +445,7 @@
},
"outputs": [],
"source": [
"simulation.individu('impot_avant_reduction_famille', period='2015')"
"simulation.individu('droit_progressif', period='2015')"
]
},
{
Expand Down Expand Up @@ -523,7 +523,7 @@
"scenario1 = tax_benefit_system.new_scenario()\n",
"scenario1.init_single_entity(\n",
" parent1={\n",
" 'est_marie': True,\n",
" 'marie': True,\n",
" 'conjoint_a_des_revenus': False,\n",
" 'nombre_enfants': 0,\n",
" },\n",
Expand All @@ -533,15 +533,15 @@
" 'count': 100,\n",
" 'min': 0,\n",
" 'max': 15e6,\n",
" 'name': 'salaire',\n",
" 'name': 'salaire_imposable',\n",
" }\n",
" ],\n",
")\n",
"simulation1 = scenario1.new_simulation()\n",
"\n",
"salaire1 = simulation1.individu('salaire', period='2015')\n",
"salaire1 = simulation1.individu('salaire_imposable', period='2015')\n",
"reduction_impots_pour_charge_famille1 = simulation1.individu('reduction_impots_pour_charge_famille', period='2015')\n",
"impot_avant_reduction_famille1 = simulation1.individu('impot_avant_reduction_famille', period='2015')\n",
"droit_progressif1 = simulation1.individu('droit_progressif', period='2015')\n",
"impot_revenus1 = simulation1.individu('impot_revenus', period='2015')"
]
},
Expand All @@ -555,10 +555,10 @@
"outputs": [],
"source": [
"plt.figure(figsize=(12, 8))\n",
"plt.plot(salaire1, impot_avant_reduction_famille1, label=u'avant réduction famille')\n",
"plt.plot(salaire1, droit_progressif1, label=u'avant réduction famille')\n",
"plt.plot(salaire1, reduction_impots_pour_charge_famille1, label=u'réduction famille')\n",
"plt.plot(salaire1, impot_revenus1, label=u'impôt revenus')\n",
"plt.xlabel(u'Salaire')\n",
"plt.xlabel(u'salaire_imposable')\n",
"plt.legend()\n",
"plt.title(u'0 enfants', fontsize=20)"
]
Expand All @@ -574,7 +574,7 @@
"scenario2 = tax_benefit_system.new_scenario()\n",
"scenario2.init_single_entity(\n",
" parent1={\n",
" 'est_marie': True,\n",
" 'marie': True,\n",
" 'conjoint_a_des_revenus': False,\n",
" 'nombre_enfants': 1,\n",
" },\n",
Expand All @@ -584,15 +584,15 @@
" 'count': 100,\n",
" 'min': 0,\n",
" 'max': 15e6,\n",
" 'name': 'salaire',\n",
" 'name': 'salaire_imposable',\n",
" }\n",
" ],\n",
")\n",
"simulation2 = scenario2.new_simulation()\n",
"\n",
"salaire2 = simulation2.individu('salaire', period='2015')\n",
"salaire2 = simulation2.individu('salaire_imposable', period='2015')\n",
"reduction_impots_pour_charge_famille2 = simulation2.individu('reduction_impots_pour_charge_famille', period='2015')\n",
"impot_avant_reduction_famille2 = simulation2.individu('impot_avant_reduction_famille', period='2015')\n",
"droit_progressif2 = simulation2.individu('droit_progressif', period='2015')\n",
"impot_revenus2 = simulation2.individu('impot_revenus', period='2015')"
]
},
Expand All @@ -606,10 +606,10 @@
"outputs": [],
"source": [
"plt.figure(figsize=(12, 8))\n",
"plt.plot(salaire2, impot_avant_reduction_famille2, label=u'avant réduction famille')\n",
"plt.plot(salaire2, droit_progressif2, label=u'avant réduction famille')\n",
"plt.plot(salaire2, reduction_impots_pour_charge_famille2, label=u'réduction famille')\n",
"plt.plot(salaire2, impot_revenus2, label=u'impôt revenus')\n",
"plt.xlabel(u'Salaire')\n",
"plt.xlabel(u'salaire_imposable')\n",
"plt.legend()\n",
"plt.title(u'1 enfant', fontsize=20)"
]
Expand All @@ -625,7 +625,7 @@
"impot_revenus_diff = np.abs(impot_revenus2 - impot_revenus1)\n",
"plt.figure(figsize=(12, 8))\n",
"plt.plot(salaire1, impot_revenus_diff, label=u'Différence d\\'impôt revenus')\n",
"plt.xlabel(u'Salaire')\n",
"plt.xlabel(u'salaire_imposable')\n",
"plt.legend()\n",
"plt.title(u'Gain fiscal du 1er enfant', fontsize=20)\n",
"\n",
Expand Down Expand Up @@ -663,7 +663,7 @@
"fig, ax1 = plt.subplots(figsize=(12, 8))\n",
"\n",
"ax1.plot(salaire1, impot_revenus1)\n",
"ax1.set_xlabel(u'Salaire')\n",
"ax1.set_xlabel(u'salaire_imposable')\n",
"ax1.set_ylabel(u'Impôt sur les revenus')\n",
"\n",
"ax2 = ax1.twinx()\n",
Expand Down
16 changes: 8 additions & 8 deletions notebooks/hackathon_ogp_paris.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
" 'count': count,\n",
" 'min': min_salaire,\n",
" 'max': max_salaire,\n",
" 'name': 'salaire',\n",
" 'name': 'salaire_imposable',\n",
" },\n",
" {\n",
" 'count': 9,\n",
Expand Down Expand Up @@ -110,7 +110,7 @@
}
],
"source": [
"salaire = simulation.calculate('salaire', period = year)\n",
"salaire = simulation.calculate('salaire_imposable', period = year)\n",
"nombre_de_parts = simulation.calculate('nombre_de_parts', period = year)\n",
"impot_revenus = simulation.calculate('impot_revenus', period = year)\n",
"print salaire[:10]"
Expand All @@ -125,7 +125,7 @@
"outputs": [],
"source": [
"result = pd.DataFrame({\n",
" 'salaire': salaire,\n",
" 'salaire_imposable': salaire,\n",
" 'nombre_de_parts': nombre_de_parts,\n",
" 'impots_revenus': impot_revenus,\n",
" })"
Expand Down Expand Up @@ -1064,7 +1064,7 @@
}
],
"source": [
"result_reshaped = result.set_index(['nombre_de_parts', 'salaire']).unstack('nombre_de_parts')\n",
"result_reshaped = result.set_index(['nombre_de_parts', 'salaire_imposable']).unstack('nombre_de_parts')\n",
"result_reshaped"
]
},
Expand Down Expand Up @@ -2448,7 +2448,7 @@
" 'count': count,\n",
" 'min': min_salaire,\n",
" 'max': max_salaire,\n",
" 'name': 'salaire',\n",
" 'name': 'salaire_imposable',\n",
" },\n",
" {\n",
" 'count': 9,\n",
Expand All @@ -2459,16 +2459,16 @@
" ],\n",
")\n",
"simulation = scenario.new_simulation()\n",
"salaire = simulation.calculate('salaire', period = year)\n",
"salaire = simulation.calculate('salaire_imposable', period = year)\n",
"nombre_de_parts = simulation.calculate('nombre_de_parts', period = year)\n",
"impot_revenus = simulation.calculate('impot_revenus', period = year)\n",
"result = pd.DataFrame({\n",
" 'salaire': salaire,\n",
" 'salaire_imposable': salaire,\n",
" 'nombre_de_parts': nombre_de_parts,\n",
" 'impots_revenus': impot_revenus,\n",
" })\n",
"result.salaire = result.salaire.astype(int)\n",
"result_reshaped_step_1000 = result.set_index(['nombre_de_parts', 'salaire']).unstack('nombre_de_parts')\n",
"result_reshaped_step_1000 = result.set_index(['nombre_de_parts', 'salaire_imposable']).unstack('nombre_de_parts')\n",
"result_reshaped_step_1000"
]
},
Expand Down
42 changes: 25 additions & 17 deletions openfisca_senegal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os


from openfisca_core.taxbenefitsystems import TaxBenefitSystem
from openfisca_senegal import entities

Expand All @@ -12,25 +13,32 @@
COUNTRY_DIR = os.path.dirname(os.path.abspath(__file__))


# Our country tax and benefit class inherits from the general TaxBenefitSystem class.
# The name CountryTaxBenefitSystem must not be changed, as all tools of the OpenFisca ecosystem expect a
# CountryTaxBenefitSystem class to be exposed in the __init__ module of a country package.
class CountryTaxBenefitSystem(TaxBenefitSystem):
def __init__(self):
# We initialize our tax and benefit system with the general constructor
def __init__(self, coicop = True, inversion = True):
super(CountryTaxBenefitSystem, self).__init__(entities.entities)

# We add to our tax and benefit system all the variables
self.add_variables_from_directory(os.path.join(COUNTRY_DIR, 'variables'))

# We add to our tax and benefit system all the legislation parameters defined in the parameters files
param_path = os.path.join(COUNTRY_DIR, 'parameters')
self.load_parameters(param_path)
try:
from openfisca_ceq.tests.test_indirect_tax_variables_generator import add_coicop_item_to_tax_benefit_system
add_coicop_item_to_tax_benefit_system(self, country = "senegal")
except (configparser.NoSectionError, ModuleNotFoundError) as e:
log.info("No ceq baecause:")
log.info(e)
log.info("Passing")

if coicop:
try:
from openfisca_ceq.tests.test_indirect_tax_variables_generator import add_coicop_item_to_tax_benefit_system
add_coicop_item_to_tax_benefit_system(self, country = "senegal")
except (configparser.NoSectionError, ModuleNotFoundError) as e:
log.info("No coicop consumption variable: \n")
log.info(e)
log.info("Passing")
self.legislation_country = "senegal"
if inversion:
from openfisca_senegal.inversion import (
autres_revenus_du_capital_brut,
pension_retraite_brut,
revenu_foncier_brut,
revenu_non_salarie_brut,
salaire_brut,
)

self.update_variable(autres_revenus_du_capital_brut)
self.update_variable(pension_retraite_brut)
self.update_variable(revenu_foncier_brut)
self.update_variable(revenu_non_salarie_brut)
self.update_variable(salaire_brut)
Loading