diff --git a/.conda/README.md b/.conda/README.md index 67d38c9738..902237be9f 100644 --- a/.conda/README.md +++ b/.conda/README.md @@ -45,8 +45,17 @@ _Cela fonctionne aussi sous macOS et Linux, à condition d'adapter les chemins._ Docker peut être utilisé pour valider le bon fonctionnement +Pour tester le build : ``` -docker run -i -t continuumio/anaconda3 /bin/bash +docker run --volume $PWD:/openfisca -i -t continuumio/anaconda3 /bin/bash +cd /openfisca +conda build -c openfisca -c conda-forge .conda +``` + +Pour tester l'installation : +``` +docker run --volume $PWD:/openfisca -i -t continuumio/anaconda3 /bin/bash +cd /openfisca conda install -c openfisca -c conda-forge openfisca-france-dev openfisca test --country-package openfisca_france tests ``` \ No newline at end of file diff --git a/.conda/meta.yaml b/.conda/meta.yaml index 7dc68cb7a5..f8714a8427 100644 --- a/.conda/meta.yaml +++ b/.conda/meta.yaml @@ -1,11 +1,11 @@ ############################################################################### -## Fichier de description du package pour Anaconda.org -## Attention, les chaines PYPI_VERSION, PYPI_URL et PYPI_SHA256 sont remplacées -## par la CI, il faut les conserver. +## File for Anaconda.org +## It use Jinja2 templating code to retreive information from setup.py ############################################################################### {% set name = "OpenFisca-France" %} -{% set version = "PYPI_VERSION" %} +{% set data = load_setup_py_data() %} +{% set version = data.get('version') %} package: name: {{ name|lower }} @@ -24,8 +24,11 @@ requirements: - python - pip run: - - python >=3.6,<4.0 - - OpenFisca-Core >=35.8.0,<36.0 + {% for req in data.get('install_requires', []) %} + - {{ req }} + {% endfor %} + # - python >=3.9,<4.0 + # - OpenFisca-Core >=40,<41 test: @@ -46,7 +49,7 @@ outputs: host: - python run: - - scipy >=0.17 + - scipy >=1.10.1,<2.0 - {{ pin_subpackage('openfisca-france', exact=True) }} - name: openfisca-france-dev @@ -56,12 +59,10 @@ outputs: host: - python run: - - autopep8 ==1.5.7 - - flake8 >=3.8.0,<3.10.0 - - flake8-print - - pytest >=5.0.0, <7.0.0 - - requests >=2.8 - - yamllint >=1.11.1,<1.27 + - python >=3.9,<4.0 + {% for req in data.get('dev_requirements', []) %} + - {{ req }} + {% endfor %} - {{ pin_subpackage('openfisca-france-scipy', exact=True) }} about: diff --git a/.github/test-api.sh b/.github/test-api.sh index c8d8f9df46..a408e042e4 100755 --- a/.github/test-api.sh +++ b/.github/test-api.sh @@ -3,7 +3,7 @@ PORT=5000 ENDPOINT=spec -openfisca serve --country-package openfisca_france --port $PORT & +openfisca serve --country-package openfisca_france --port $PORT --workers 1 & server_pid=$! curl --retry-connrefused --retry 10 --retry-delay 5 --fail http://127.0.0.1:$PORT/$ENDPOINT | python -m json.tool > /dev/null diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 5d968875f2..e18a47303a 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -12,7 +12,7 @@ jobs: fail-fast: true matrix: os: ["ubuntu-20.04"] # On peut ajouter "macos-latest" si besoin - python-version: ["3.7.9", "3.8.9", "3.9.9"] + python-version: ["3.9.9", "3.10.6"] steps: - name: Checkout uses: actions/checkout@v3 @@ -48,7 +48,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: 3.7.9 + python-version: 3.9.9 - name: Cache build id: restore-build uses: actions/cache@v3 @@ -68,7 +68,7 @@ jobs: fail-fast: true matrix: os: [ "ubuntu-20.04" ] # On peut ajouter "macos-latest" si besoin - python-version: ["3.7.9", "3.8.9", "3.9.9"] + python-version: ["3.9.9", "3.10.6"] steps: - uses: actions/checkout@v3 - name: Set up Python @@ -92,7 +92,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: 3.7.9 + python-version: 3.9.9 - name: Test max path length run: make check-path-length @@ -112,7 +112,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: 3.7.9 + python-version: 3.9.9 - name: Cache build id: restore-build uses: actions/cache@v3 @@ -138,7 +138,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: 3.7.9 + python-version: 3.9.9 - name: Cache build id: restore-build uses: actions/cache@v3 @@ -158,7 +158,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: 3.7.9 + python-version: 3.9.9 - name: Check version number has been properly updated run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh" @@ -178,7 +178,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: 3.7.9 + python-version: 3.9.9 - id: stop-early run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi @@ -196,7 +196,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: 3.7.9 + python-version: 3.9.9 - name: Cache build id: restore-build uses: actions/cache@v3 @@ -223,9 +223,9 @@ jobs: - uses: conda-incubator/setup-miniconda@v2 with: auto-update-conda: true - python-version: "3.7.9" + python-version: "3.9.9" # Add conda-forge for OpenFisca-Core - channels: conda-forge + channels: openfisca,conda-forge activate-environment: true - uses: actions/checkout@v3 - name: Update meta.yaml @@ -239,7 +239,7 @@ jobs: conda install conda-build anaconda-client conda info - name: Build Conda package - run: conda build --croot /tmp/conda .conda + run: conda build -c openfisca -c conda-forge --croot /tmp/conda .conda - name: Upload Conda build uses: actions/upload-artifact@v3 with: @@ -256,7 +256,7 @@ jobs: auto-update-conda: true python-version: "3.9.9" # Add conda-forge for OpenFisca-Core - channels: conda-forge + channels: openfisca,conda-forge activate-environment: true - uses: actions/checkout@v3 - name: Test max path length @@ -284,7 +284,7 @@ jobs: - uses: conda-incubator/setup-miniconda@v2 with: auto-update-conda: true - python-version: "3.7.9" + python-version: "3.9.9" # Add conda-forge for OpenFisca-Core channels: conda-forge activate-environment: true diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile index 36481607f7..8ff1ca0598 100644 --- a/.gitpod.Dockerfile +++ b/.gitpod.Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7 +FROM python:3.9 USER gitpod diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fb80d91e7..6ff3672465 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,17 @@ # Changelog -### 148.0.0 [#2105](https://github.com/openfisca/openfisca-france/pull/2105) +# 149.0.0 [#2065](https://github.com/openfisca/openfisca-france/pull/2065) + +* Amélioration technique. +* Périodes concernées : toutes. +* Zones impactées : toutes. +* Détails : + - Met à jour toutes les dépendances afin d'utiliser leurs dernières versions : + * Migre la version minimal de Python de `3.7` à `3.9` + * Met à jour openfisca-core de la version `35` à la version `40` + * En particulier, migre la syntaxe des périodes introduite par [openfisca-core v37.0.0](https://github.com/openfisca/openfisca-core/blob/master/CHANGELOG.md#3700-1142). Les appels à la méthode `period()` sont remplacés par des instanciations de la classe `Period`. + +# 148.0.0 [#2105](https://github.com/openfisca/openfisca-france/pull/2105) * Amélioration technique. * Périodes concernées : Toutes. @@ -34,6 +45,7 @@ - Nettoyage et harmonisation avec les barèmes IPP ## 147.2.1 [#2097](https://github.com/openfisca/openfisca-france/pull/2097) + * Évolution du système socio-fiscal. * Périodes concernées : à partir du 01/01/2023. * Zones impactées : @@ -773,6 +785,7 @@ - `exo_maire_autres` - `foncier_deduc` - `deduc_invest_locatif` + # 134.0.0 [#1958](https://github.com/openfisca/openfisca-france/pull/1958) * Évolution du système socio-fiscal. | Amélioration technique. diff --git a/README.md b/README.md index d13ef06928..44b5e380a8 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,13 @@ [![Gitpod](https://camo.githubusercontent.com/1eb1ddfea6092593649f0117f7262ffa8fbd3017/68747470733a2f2f676974706f642e696f2f627574746f6e2f6f70656e2d696e2d676974706f642e737667)](https://gitpod-referer.now.sh/api/gitpod-referer-redirect) ## [EN] Introduction + OpenFisca is a versatile microsimulation free software. This repository contains the OpenFisca model of the French tax and benefit system. Therefore, the working language here is French. You can however check the [general OpenFisca documentation](https://openfisca.org/doc/) in English! > We host a public instance of of the [OpenFisca-France Web API](https://api.fr.openfisca.org/latest/). Learn more about its endpoint in the [Swagger documentation](https://legislation.fr.openfisca.org/swagger). > If you need to run large amount of calculations, or add extensions, you should [host your own instance](#servez-openfisca-france-avec-lapi-web-openfisca). ## [FR] Introduction + [OpenFisca](https://www.openfisca.fr/) est un logiciel libre de micro-simulation. Ce dépôt contient la modélisation du système social et fiscal français. Pour plus d'information sur les fonctionnalités et la manière d'utiliser OpenFisca, vous pouvez consulter la [documentation générale](https://openfisca.org/doc/). > Nous mettons à disposition une instance publique de [l'API Web OpenFisca-France](https://api.fr.openfisca.org/latest/). Découvrez ses capacité sur sa [documentation Swagger](https://legislation.fr.openfisca.org/swagger). > Si vous avez besoin de réaliser un grand nombre de calculs ou d'ajouter des extensions, vous pouvez [servir votre propre instance](#servez-openfisca-france-avec-lapi-web-openfisca). @@ -31,7 +33,7 @@ L'ensembles des endpoints sont décrits dans la [documentation Swagger](https:// ## Installation -Ce paquet requiert [Python 3.7](https://www.python.org/downloads/release/python-370/) et [pip](https://pip.pypa.io/en/stable/installing/) ou [conda](https://www.anaconda.com/products/individual). +Ce paquet requiert [Python 3.9](https://www.python.org/downloads/release/python-390/) et [pip](https://pip.pypa.io/en/stable/installing/) ou [conda](https://www.anaconda.com/products/individual). Plateformes supportées : - distributions GNU/Linux (en particulier Debian and Ubuntu) ; @@ -50,7 +52,7 @@ Nous recommandons l'utilisation d'un [environnement virtuel](https://virtualenv. Pour installer Pew, lancez une fenêtre de terminal et suivez ces instructions : ```sh -python --version # Python 3.7.0 ou plus récent devrait être installé sur votre ordinateur. +python --version # Python 3.9.0 ou plus récent devrait être installé sur votre ordinateur. # Si non, téléchargez-le sur http://www.python.org et téléchargez pip. ``` @@ -58,10 +60,10 @@ python --version # Python 3.7.0 ou plus récent devrait être installé sur votr pip install --upgrade pip pip install pew ``` -Créez un nouveau _virtualenv_ nommé **openfisca** et configurez-le avec python 3.7 : +Créez un nouveau _virtualenv_ nommé **openfisca** et configurez-le avec python 3.9 : ```sh -pew new openfisca --python=python3.7 +pew new openfisca --python=python3.9 # Si demandé, répondez "Y" à la question sur la modification du fichier de configuration de votre shell ``` Le  _virtualenv_  **openfisca** sera alors activé, c'est-à-dire que les commandes suivantes s'exécuteront directement dans l'environnement virtuel. Vous verrez dans votre terminal : @@ -94,8 +96,8 @@ Pour pouvoir modifier OpenFisca-France, consultez l'[Installation avancée](#b-i Dans votre _virtualenv_, vérifiez les pré-requis : ```sh -python --version # Devrait afficher "Python 3.7.xx". -#Si non, vérifiez que vous passez --python=python3.7 lors de la création de votre environnement virtuel. +python --version # Devrait afficher "Python 3.9.xx". +#Si non, vérifiez que vous passez --python=python3.9 lors de la création de votre environnement virtuel. ``` ```sh @@ -136,12 +138,12 @@ Dans votre _virtualenv_, assurez-vous que vous êtes dans le répertoire où vou Vérifiez les pré-requis : ```sh -python --version # Devrait afficher "Python 3.7.xx". -#Si non, vérifiez que vous passez --python=python3.7 lors de la création de votre environnement virtuel. +python --version # Devrait afficher "Python 3.9.xx". +#Si non, vérifiez que vous passez --python=python3.9 lors de la création de votre environnement virtuel. ``` ```sh -pip --version # Devrait afficher au moins 9.0. +pip --version # Devrait afficher au moins 23.0. #Si non, exécutez "pip install --upgrade pip". ``` @@ -175,7 +177,7 @@ Voici les étapes à suivre : - Depuis le menu démarrer, exécuter `Anaconda Powershell Prompt`. Ou utiliser votre shell préféré avec Miniconda, il vous faudra peut-être utiliser la commande `conda init`, mais conda vous le dira. - Exécuter les commandes suivantes dans le shell: - Ajouter `conda-forge` comme channel par défaut : `conda config --add channels conda-forge && conda config --set channel_priority strict ` - - Créer un environnement virtuel dédié : `conda create --name openfisca python=3.7` + - Créer un environnement virtuel dédié : `conda create --name openfisca python=3.9` - Activer l'environnement : `conda activate openfisca` - Installer OpenFisca : `conda install openfisca-france` diff --git a/openfisca_france/model/base.py b/openfisca_france/model/base.py index 56eabfc101..146824bdf5 100644 --- a/openfisca_france/model/base.py +++ b/openfisca_france/model/base.py @@ -1,6 +1,10 @@ from openfisca_core.model_api import * from openfisca_france.entities import Famille, FoyerFiscal, Individu, Menage # noqa F401 + +AGE_INT_MINIMUM = -9999 + + # Enums commonly used through the legislation diff --git a/openfisca_france/model/prelevements_obligatoires/impot_revenu/ir.py b/openfisca_france/model/prelevements_obligatoires/impot_revenu/ir.py index 19732b140a..533d37ed32 100644 --- a/openfisca_france/model/prelevements_obligatoires/impot_revenu/ir.py +++ b/openfisca_france/model/prelevements_obligatoires/impot_revenu/ir.py @@ -42,7 +42,7 @@ class jour_xyz(Variable): class age(Variable): unit = 'years' value_type = int - default_value = -9999 + default_value = AGE_INT_MINIMUM entity = Individu label = 'Âge (en années) au premier jour du mois' definition_period = MONTH @@ -81,7 +81,7 @@ def formula(individu, period, parameters): class age_en_mois(Variable): value_type = int - default_value = -9999 + default_value = AGE_INT_MINIMUM unit = 'months' entity = Individu label = 'Âge (en mois)' @@ -2566,7 +2566,7 @@ def abat_rpns(rev, P): return min_( f5ht + f5it + f5jt + f5kt + f5lt + f5mt, abat_rpns(mncn_impo, specialbnc.services) + mncn_pvct + cncn_aimp + (1 + cga) * cncn_bene - ) #  TODO check ! + ) # TODO check ! class defmeu(Variable): @@ -2968,7 +2968,7 @@ def formula(individu, period, parameters): aacc_defn = individu('aacc_defn', period) aacc_defs = individu('aacc_defs', period) aacc_timp = max_(0, aacc_impn - aacc_defn - aacc_defs) - return(aacc_timp) + return aacc_timp def formula_2009_01_01(individu, period, parameters): aacc_impn = individu('aacc_impn', period) @@ -2976,14 +2976,14 @@ def formula_2009_01_01(individu, period, parameters): aacc_defn = individu('aacc_defn', period) aacc_defs = individu('aacc_defs', period) aacc_timp = max_(0, aacc_impn + max_(0, - alnp_defs) - aacc_defn - aacc_defs) - return(aacc_timp) + return aacc_timp def formula_2010_01_01(individu, period, parameters): aacc_impn = individu('aacc_impn', period) alnp_defs = individu('alnp_defs', period) aacc_defn = individu('aacc_defn', period) aacc_timp = max_(0, aacc_impn + max_(0, - alnp_defs) - aacc_defn) - return(aacc_timp) + return aacc_timp def formula_2011_01_01(individu, period, parameters): aacc_impn = individu('aacc_impn', period) @@ -3006,7 +3006,7 @@ def formula_2011_01_01(individu, period, parameters): + max_(0, - alnp_defs) - aacc_defn ) ) - return(aacc_timp) + return aacc_timp def formula_2012_01_01(individu, period, parameters): aacc_impn = individu('aacc_impn', period) @@ -3035,7 +3035,7 @@ def formula_2012_01_01(individu, period, parameters): + max_(0, nacc_defs - alnp_defs) - aacc_defn ) ) - return(aacc_timp) + return aacc_timp def formula_2017_01_01(individu, period, parameters): aacc_impn = individu('aacc_impn', period) @@ -3069,7 +3069,7 @@ def formula_2017_01_01(individu, period, parameters): + max_(0, nacc_defs - alnp_defs) - aacc_defn ) ) - return(aacc_timp) + return aacc_timp class atimp(Variable): @@ -3094,7 +3094,7 @@ def formula(individu, period, parameters): abnc_timp = abnc_impo - abnc_defi # Total atimp = arag_impg + abic_timp + aacc_timp + abnc_timp - return(atimp) + return atimp def formula_2010_01_01(individu, period, parameters): abic_impn = individu('abic_impn', period) @@ -3110,7 +3110,7 @@ def formula_2010_01_01(individu, period, parameters): abnc_timp = abnc_impo - abnc_defi # Total atimp = arag_impg + abic_timp + aacc_timp + abnc_timp - return(atimp) + return atimp class nbnc_timp(Variable): @@ -3124,7 +3124,7 @@ def formula(individu, period, parameters): nbnc_defi = individu('nbnc_defi', period) # regime de la déclaration contrôlée ne bénéficiant pas de l'abattement association agréée nbnc_timp = nbnc_impo - nbnc_defi - return(nbnc_timp) + return nbnc_timp class nacc_timp(Variable): @@ -3138,7 +3138,7 @@ def formula(individu, period, parameters): nacc_defn = individu('nacc_defn', period) # Régime du bénéfice réel ne bénéficiant pas de l'abattement CGA nacc_timp = max_(0, nacc_impn - nacc_defn) - return(nacc_timp) + return nacc_timp class ntimp(Variable): @@ -3157,7 +3157,7 @@ def formula(individu, period, parameters): # Régime du bénéfice réel ne bénéficiant pas de l'abattement CGA nbic_timp = (nbic_impn + nbic_imps) - (nbic_defn + nbic_defs) ntimp = nacc_timp + nbnc_timp + nbic_timp - return(ntimp) + return ntimp def formula_2006_01_01(individu, period, parameters): nbic_impn = individu('nbic_impn', period) @@ -3172,7 +3172,7 @@ def formula_2006_01_01(individu, period, parameters): nbic_timp = (nbic_impn + nbic_imps) - (nbic_defn + nbic_defs) cncn_timp = max_(0, cncn_bene - cncn_defi) ntimp = nbic_timp + nacc_timp + nbnc_timp + cncn_timp - return(ntimp) + return ntimp def formula_2007_01_01(individu, period, parameters): # Moyenne triennale @@ -3189,7 +3189,7 @@ def formula_2007_01_01(individu, period, parameters): nbic_timp = (nbic_impn + nbic_imps) - (nbic_defn + nbic_defs) cncn_timp = max_(0, cncn_bene - cncn_defi) ntimp = nrag_impg + nbic_timp + nacc_timp + cncn_timp + nbnc_timp - return(ntimp) + return ntimp def formula_2010_01_01(individu, period, parameters): nrag_impg = individu('nrag_impg', period) @@ -3203,7 +3203,7 @@ def formula_2010_01_01(individu, period, parameters): nbic_timp = nbic_impn - nbic_defn cncn_timp = max_(0, cncn_bene - cncn_defi) ntimp = nrag_impg + nbic_timp + nacc_timp + cncn_timp + nbnc_timp - return(ntimp) + return ntimp class revenu_non_salarie(Variable): @@ -3224,7 +3224,7 @@ def formula(individu, period, parameters): majo_cga = max_(0, cga_taux2 * (ntimp + rpns_frag)) # Pour ne pas avoir à majorer les déficits def_agri = f5sq + arag_defi + (1 + cga_taux2) * nrag_defi revenus_non_salaries = rpns_frag + frag_fore + atimp + ntimp + majo_cga - def_agri - return(revenus_non_salaries) + return revenus_non_salaries def formula_2016_01_01(individu, period, parameters): rpns_mrag = individu('rpns_revenus_microBA_agricole', period) @@ -3238,7 +3238,7 @@ def formula_2016_01_01(individu, period, parameters): majo_cga = max_(0, cga_taux2 * ntimp) # Pour ne pas avoir à majorer les déficits def_agri = f5sq + arag_defi + (1 + cga_taux2) * nrag_defi revenus_non_salaries = rpns_mrag + coupe_bois + atimp + ntimp + majo_cga - def_agri - return(revenus_non_salaries) + return revenus_non_salaries class locations_pro(Variable): @@ -3251,11 +3251,11 @@ def formula_2009_01_01(individu, period, parameters): abic_impm = individu('abic_impm', period) abic_defm = individu('abic_defm', period) alnp_imps = individu('alnp_imps', period) - return(abic_impm - abic_defm + alnp_imps) + return abic_impm - abic_defm + alnp_imps def formula_2016_01_01(individu, period, parameters): alnp_imps = individu('alnp_imps', period) - return(alnp_imps) + return alnp_imps class rpns_imposables(Variable): diff --git a/openfisca_france/model/prelevements_obligatoires/prelevements_sociaux/cotisations_sociales/allegements.py b/openfisca_france/model/prelevements_obligatoires/prelevements_sociaux/cotisations_sociales/allegements.py index 99879ac121..b214b1cd5d 100644 --- a/openfisca_france/model/prelevements_obligatoires/prelevements_sociaux/cotisations_sociales/allegements.py +++ b/openfisca_france/model/prelevements_obligatoires/prelevements_sociaux/cotisations_sociales/allegements.py @@ -2,6 +2,8 @@ from numpy import busday_count, datetime64, logical_or as or_, logical_and as and_, timedelta64 +from openfisca_core.periods import Period + from openfisca_france.model.base import * log = logging.getLogger(__name__) @@ -537,7 +539,7 @@ def compute_allegement_anticipe(individu, period, parameters, variable_name, com if period.start.month == 12: cumul = individu( variable_name, - period.start.offset('first-of', 'year').period('month', 11), options = [ADD]) + Period(('month', period.start.offset('first-of', 'year'), 11)), options = [ADD]) return compute_function( individu, period.this_year, parameters ) - cumul @@ -548,8 +550,8 @@ def compute_allegement_progressif(individu, period, parameters, variable_name, c return compute_function(individu, period.first_month, parameters) if period.start.month > 1: - up_to_this_month = period.start.offset('first-of', 'year').period('month', period.start.month) - up_to_previous_month = period.start.offset('first-of', 'year').period('month', period.start.month - 1) + up_to_this_month = Period(('month', period.start.offset('first-of', 'year'), period.start.month)) + up_to_previous_month = Period(('month', period.start.offset('first-of', 'year'), period.start.month - 1)) cumul = individu(variable_name, up_to_previous_month, options = [ADD]) return compute_function(individu, up_to_this_month, parameters) - cumul diff --git a/openfisca_france/model/prelevements_obligatoires/prelevements_sociaux/cotisations_sociales/base.py b/openfisca_france/model/prelevements_obligatoires/prelevements_sociaux/cotisations_sociales/base.py index fbb9be833f..174c8045d3 100644 --- a/openfisca_france/model/prelevements_obligatoires/prelevements_sociaux/cotisations_sociales/base.py +++ b/openfisca_france/model/prelevements_obligatoires/prelevements_sociaux/cotisations_sociales/base.py @@ -1,3 +1,5 @@ +from openfisca_core.periods import Period + from openfisca_france.model.base import * @@ -271,7 +273,7 @@ def iter_cotisations(): # FIXME: dirty fix since public_titulaire_militaire does not exist if categorie_salarie_type.name == 'public_titulaire_militaire': continue - raise(e) + raise e if bareme_name in cotisations_by_categorie_salarie[categorie_salarie_type.name]: bareme = categorie_salarie_baremes[bareme_name] @@ -371,8 +373,10 @@ def compute_cotisation_anticipee(individu, period, parameters, cotisation_type = bareme_name = bareme_name, ) if period.start.month == 12: - cumul = individu(variable_name, period.start.offset('first-of', 'month').offset( - -11, 'month').period('month', 11), options = [ADD]) + cumul = individu( + variable_name, + Period(('month', period.start.offset('first-of', 'month').offset(-11, 'month'), 11)), + options = [ADD]) # December variable_name depends on variable_name in the past 11 months. # We need to explicitely allow this recursion. diff --git a/openfisca_france/model/prelevements_obligatoires/taxe_habitation/taxe_habitation.py b/openfisca_france/model/prelevements_obligatoires/taxe_habitation/taxe_habitation.py index bf0cadcde8..2f6e32c41d 100644 --- a/openfisca_france/model/prelevements_obligatoires/taxe_habitation/taxe_habitation.py +++ b/openfisca_france/model/prelevements_obligatoires/taxe_habitation/taxe_habitation.py @@ -1,3 +1,5 @@ +from openfisca_core.periods import Period + from openfisca_france.model.base import * @@ -333,7 +335,7 @@ def formula_2017_01_01(menage, period, parameters): taux_th_commune = menage('taux_th_commune', period) taux_th_epci = menage('taux_th_epci', period) ecart_avec_2000 = period.start.offset('first-of', 'year').year - 2000 - annee_2000 = period.start.offset('first-of', 'year').period('year').offset(-ecart_avec_2000) + annee_2000 = Period(('year', period.start.offset('first-of', 'year'), 1)).offset(-ecart_avec_2000) taux_th_commune_2000 = menage('taux_th_commune', annee_2000) taux_th_epci_2000 = menage('taux_th_epci', annee_2000) diff --git a/openfisca_france/model/prestations/agepi.py b/openfisca_france/model/prestations/agepi.py index aea93b0287..ef3a1ac84b 100644 --- a/openfisca_france/model/prestations/agepi.py +++ b/openfisca_france/model/prestations/agepi.py @@ -1,5 +1,7 @@ from numpy import fabs, timedelta64 +from openfisca_core.periods import Period + from openfisca_france.model.base import Famille, Individu, Variable, Enum, MONTH, ADD,\ set_input_dispatch_by_period, set_input_divide_by_period, date, min_, not_ from openfisca_france.model.revenus.activite.salarie import TypesContrat, TypesLieuEmploiFormation,\ @@ -83,7 +85,7 @@ def formula_2014_01_20(individu, period, parameters): condition_nb_enfants = individu.famille('agepi_nbenf', period) > 0 # L'individu n'a pas touché l'AGEPI dans les 12 derniers mois (condition de durée entre faits générateurs) - annee_glissante = period.start.period('year').offset(-1).offset(-1, 'month') + annee_glissante = Period(('year', period.start, 1)).offset(-1).offset(-1, 'month') agepi_non_percues = not_(individu('agepi', annee_glissante, options=[ADD])) # L'individu est inscrit en catégorie 1, 2, 3, 4 "stagiaire de la formation professionnelle" ou 5 "contrat aidé" diff --git a/openfisca_france/model/prestations/aide_mobilite.py b/openfisca_france/model/prestations/aide_mobilite.py index a7772c2ffe..63f0e6f671 100644 --- a/openfisca_france/model/prestations/aide_mobilite.py +++ b/openfisca_france/model/prestations/aide_mobilite.py @@ -1,4 +1,7 @@ from numpy import fabs, timedelta64 + +from openfisca_core.periods import Period + from openfisca_france.model.base import Individu, Variable, MONTH, Enum, not_, ADD,\ set_input_dispatch_by_period, set_input_divide_by_period, min_, date from openfisca_france.model.caracteristiques_socio_demographiques.logement import TypesLieuResidence @@ -326,7 +329,7 @@ def formula_2021_06_09(individu, period, parameters): eligibilite_amob = individu('aide_mobilite_eligible', period) parametres_amob = parameters(period).prestations_sociales.aide_mobilite - annee_glissante = period.start.period('year').offset(-1) + annee_glissante = Period(('year', period.start, 1)).offset(-1) aide_mobilite_12_derniers_mois = individu('aide_mobilite', annee_glissante, options=[ADD]) diff --git a/openfisca_france/model/prestations/aides_exceptionnelles/indemnite_inflation.py b/openfisca_france/model/prestations/aides_exceptionnelles/indemnite_inflation.py index 799808991b..29508eb2e9 100644 --- a/openfisca_france/model/prestations/aides_exceptionnelles/indemnite_inflation.py +++ b/openfisca_france/model/prestations/aides_exceptionnelles/indemnite_inflation.py @@ -1,5 +1,7 @@ -from openfisca_france.model.base import * from openfisca_core import periods + +from openfisca_france.model.base import * + from numpy import logical_or as or_, logical_and as and_ # Les éligibilités séparées de l'indemnité inflation diff --git a/openfisca_france/model/prestations/aides_logement.py b/openfisca_france/model/prestations/aides_logement.py index 8154196b8e..a357421a11 100644 --- a/openfisca_france/model/prestations/aides_logement.py +++ b/openfisca_france/model/prestations/aides_logement.py @@ -7,9 +7,9 @@ from numpy import ceil, datetime64, fromiter, int16, logical_or as or_, logical_and as and_, logical_not as not_ -import openfisca_france -from openfisca_core.periods import Instant +from openfisca_core.periods import Instant, Period +import openfisca_france from openfisca_france.model.base import * from openfisca_france.model.revenus.activite.salarie import TypesConges from openfisca_france.model.prestations.prestations_familiales.base_ressource import nb_enf @@ -566,7 +566,7 @@ class aide_logement_base_ressources_individu(Variable): def formula_2021_01_01(individu, period, parameters): period_frais = period.last_year - annee_glissante = period.start.period('year').offset(-1).offset(-1, 'month') + annee_glissante = Period(('year', period.start, 1)).offset(-1).offset(-1, 'month') salaire_imposable = individu('salaire_imposable', annee_glissante, options=[ADD]) chomage_imposable = individu('chomage_imposable', annee_glissante, options=[ADD]) diff --git a/openfisca_france/model/prestations/autonomie.py b/openfisca_france/model/prestations/autonomie.py index 50e7ac90f8..c5833d397b 100644 --- a/openfisca_france/model/prestations/autonomie.py +++ b/openfisca_france/model/prestations/autonomie.py @@ -1,3 +1,5 @@ +from openfisca_core.periods import Period + from openfisca_france.model.base import * @@ -133,7 +135,7 @@ class apa_eligibilite(Variable): set_input = set_input_dispatch_by_period def formula_2002(individu, period, parameters): - period = period.start.offset('first-of', 'month').period('month') + period = Period(('month', period.start.offset('first-of', 'month'), 1)) parameters = parameters(period).prestations_sociales.prestations_etat_de_sante.perte_autonomie_personnes_agees age = individu('age', period) apa_age_min = parameters.apa_domicile.condition_age @@ -172,7 +174,7 @@ class apa_domicile(Variable): set_input = set_input_divide_by_period def formula_2002(individu, period, parameters): - period = period.start.offset('first-of', 'month').period('month') + period = Period(('month', period.start.offset('first-of', 'month'), 1)) apa_domicile = parameters(period).prestations_sociales.prestations_etat_de_sante.perte_autonomie_personnes_agees.apa_domicile apa_eligibilite = individu('apa_eligibilite', period) smic_brut_horaire = parameters(period).marche_travail.salaire_minimum.smic.smic_b_horaire @@ -193,7 +195,7 @@ class apa_etablissement(Variable): set_input = set_input_divide_by_period def formula_2002(individu, period, parameters): - period = period.start.offset('first-of', 'month').period('month') + period = Period(('month', period.start.offset('first-of', 'month'), 1)) perte_autonomie_personnes_agees = parameters(period).prestations_sociales.prestations_etat_de_sante.perte_autonomie_personnes_agees smic_brut_horaire = parameters(period).marche_travail.salaire_minimum.smic.smic_b_horaire seuil_non_versement = perte_autonomie_personnes_agees.apa_institution.seuil_versement_en_part_smic_brut_horaire * smic_brut_horaire @@ -350,7 +352,7 @@ class apa_urgence_institution(Variable): set_input = set_input_divide_by_period def formula_2002(individu, period, parameters): - period = period.start.offset('first-of', 'month').period('month') + period = Period(('month', period.start.offset('first-of', 'month'), 1)) dependance_tarif_etablissement_gir_1_2 = individu('dependance_tarif_etablissement_gir_1_2', period) part_urgence_institution = parameters(period).prestations_sociales.prestations_etat_de_sante.perte_autonomie_personnes_agees.apa_institution.part_tarif_dependance apa_urgence_institution = part_urgence_institution * dependance_tarif_etablissement_gir_1_2 diff --git a/openfisca_france/model/prestations/jeunes/contrat_engagement_jeune.py b/openfisca_france/model/prestations/jeunes/contrat_engagement_jeune.py index d70afec1aa..bff8be3f8c 100644 --- a/openfisca_france/model/prestations/jeunes/contrat_engagement_jeune.py +++ b/openfisca_france/model/prestations/jeunes/contrat_engagement_jeune.py @@ -1,3 +1,5 @@ +from openfisca_core.periods import Period + from openfisca_france.model.base import * # noqa analysis:ignore from numpy import ( logical_not as not_, @@ -19,7 +21,7 @@ class contrat_engagement_jeune_montant_forfaitaire(Variable): def formula_2022_03_01(individu, period, parameters): parameters_montants = parameters(period).prestations_sociales.aides_jeunes.contrat_engagement_jeune.montants majeur = individu('majeur', period) - previous_year = period.start.period('year').offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) tranche = individu.foyer_fiscal('ir_tranche', previous_year) montant_forfaitaire = ( @@ -50,7 +52,7 @@ def formula_2022_03_01(individu, period, parameters): eligibilite_statut = activite != TypesActivite.etudiant # En fonction de l'imposition du foyer fiscal - previous_year = period.start.period('year').offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) tranche = individu.foyer_fiscal('ir_tranche', previous_year) eligibilite_ir = (tranche <= 1) diff --git a/openfisca_france/model/prestations/logement_social.py b/openfisca_france/model/prestations/logement_social.py index 84fa73fd9e..6b04c9293a 100644 --- a/openfisca_france/model/prestations/logement_social.py +++ b/openfisca_france/model/prestations/logement_social.py @@ -1,7 +1,7 @@ from numpy import isin, logical_not as not_, select from openfisca_core.indexed_enums import Enum -from openfisca_core.periods import MONTH +from openfisca_core.periods import MONTH, Period from openfisca_core.variables import Variable from openfisca_france.entities import Famille, Menage @@ -172,7 +172,7 @@ class logement_social_eligible(Variable): def formula_2017(famille, period, parameters): parent_majeur = famille.any(famille.members('majeur', period), role = Famille.PARENT) logement_social_plafond_ressources = famille('logement_social_plafond_ressources', period) - rfr_n0 = famille.demandeur.foyer_fiscal('rfr', period.start.offset('first-of', 'year').period('year')) + rfr_n0 = famille.demandeur.foyer_fiscal('rfr', Period(('year', period.start.offset('first-of', 'year'), 1))) rfr_n1 = famille.demandeur.foyer_fiscal('rfr', period.last_year) rfr_n2 = famille.demandeur.foyer_fiscal('rfr', period.n_2) diff --git a/openfisca_france/model/prestations/minima_sociaux/aah.py b/openfisca_france/model/prestations/minima_sociaux/aah.py index f4c02d6e32..3c3ec5376c 100644 --- a/openfisca_france/model/prestations/minima_sociaux/aah.py +++ b/openfisca_france/model/prestations/minima_sociaux/aah.py @@ -1,3 +1,5 @@ +from openfisca_core.periods import Period + from openfisca_france.model.base import * from numpy import datetime64 @@ -105,7 +107,7 @@ def assiette_revenu_activite_demandeur(revenus_demandeur): return (1 - aah.travail_ordinaire.abattement_30) * total_tranche1 + (1 - aah.travail_ordinaire.abattement_sup) * total_tranche2 def base_ressource_eval_trim(): - three_previous_months = period.first_month.start.period('month', 3).offset(-3) + three_previous_months = Period(('month', period.first_month.start, 3)).offset(-3) base_ressource_activite = individu('aah_base_ressources_activite_eval_trimestrielle', period) - individu('aah_base_ressources_activite_milieu_protege', three_previous_months, options = [ADD]) base_ressource_hors_activite = individu('aah_base_ressources_hors_activite_eval_trimestrielle', period) + individu('aah_base_ressources_activite_milieu_protege', three_previous_months, options = [ADD]) @@ -151,7 +153,7 @@ def assiette_revenu_activite_demandeur(revenus_demandeur): return (1 - aah.travail_ordinaire.abattement_30) * total_tranche1 + (1 - aah.travail_ordinaire.abattement_sup) * total_tranche2 def base_ressource_eval_trim(): - three_previous_months = period.first_month.start.period('month', 3).offset(-3) + three_previous_months = Period(('month', period.first_month.start, 3)).offset(-3) base_ressource_activite = individu('aah_base_ressources_activite_eval_trimestrielle', period) - individu('aah_base_ressources_activite_milieu_protege', three_previous_months, options = [ADD]) base_ressource_hors_activite = individu('aah_base_ressources_hors_activite_eval_trimestrielle', period) + individu('aah_base_ressources_activite_milieu_protege', three_previous_months, options = [ADD]) @@ -192,7 +194,7 @@ def assiette_revenu_activite_demandeur(revenus_demandeur): return (1 - aah.travail_ordinaire.abattement_30) * total_tranche1 + (1 - aah.travail_ordinaire.abattement_sup) * total_tranche2 def base_ressource_eval_trim(): - three_previous_months = period.first_month.start.period('month', 3).offset(-3) + three_previous_months = Period(('month', period.first_month.start, 3)).offset(-3) base_ressource_activite = individu('aah_base_ressources_activite_eval_trimestrielle', period) - individu('aah_base_ressources_activite_milieu_protege', three_previous_months, options = [ADD]) base_ressource_hors_activite = individu('aah_base_ressources_hors_activite_eval_trimestrielle', period) + individu('aah_base_ressources_activite_milieu_protege', three_previous_months, options = [ADD]) @@ -239,7 +241,7 @@ class aah_base_ressources_activite_eval_trimestrielle(Variable): def formula(individu, period): period = period.first_month - three_previous_months = period.start.period('month', 3).offset(-3) + three_previous_months = Period(('month', period.start, 3)).offset(-3) last_year = period.last_year ressources_a_inclure = [ @@ -299,7 +301,7 @@ class aah_base_ressources_hors_activite_eval_trimestrielle(Variable): def formula(individu, period): period = period.first_month - three_previous_months = period.start.period('month', 3).offset(-3) + three_previous_months = Period(('month', period.start, 3)).offset(-3) ressources_a_inclure = [ 'asi', @@ -564,7 +566,7 @@ class eligibilite_caah(Variable): set_input = set_input_dispatch_by_period def formula_2015_07_01(individu, period, parameters): - annee_precedente = period.start.period('year').offset(-1) + annee_precedente = Period(('year', period.start, 1)).offset(-1) prestations = parameters(period).prestations_sociales taux_incapacite_min = prestations.prestations_etat_de_sante.invalidite.aah.taux_capacite.taux_incapacite aah = individu('aah', period) @@ -606,7 +608,7 @@ def formula_2015_07_01(individu, period, parameters): def formula_2005_07_01(individu, period, parameters): invalidite = parameters(period).prestations_sociales.prestations_etat_de_sante.invalidite - annee_precedente = period.start.period('year').offset(-1) + annee_precedente = Period(('year', period.start, 1)).offset(-1) activite_12_mois = individu('salaire_imposable', annee_precedente, options = [ADD]) + individu('rpns_imposables', annee_precedente) garantie_ressources = invalidite.caah.garantie_ressources diff --git a/openfisca_france/model/prestations/minima_sociaux/asi_aspa.py b/openfisca_france/model/prestations/minima_sociaux/asi_aspa.py index 5a691c3ca5..44f675b56e 100644 --- a/openfisca_france/model/prestations/minima_sociaux/asi_aspa.py +++ b/openfisca_france/model/prestations/minima_sociaux/asi_aspa.py @@ -1,5 +1,7 @@ from numpy import abs as abs_, logical_or as or_ +from openfisca_core.periods import Period + from openfisca_france.model.base import * @@ -147,7 +149,7 @@ class asi_eligibilite(Variable): set_input = set_input_dispatch_by_period def formula(individu, period): - last_month = period.start.period('month').offset(-1) + last_month = Period(('month', period.start, 1)).offset(-1) non_eligible_aspa = not_(individu('aspa_eligibilite', period)) touche_pension_invalidite = individu('pensions_invalidite', period) > 0 diff --git a/openfisca_france/model/prestations/minima_sociaux/ass.py b/openfisca_france/model/prestations/minima_sociaux/ass.py index 78201cc4b5..faa8b74ae1 100644 --- a/openfisca_france/model/prestations/minima_sociaux/ass.py +++ b/openfisca_france/model/prestations/minima_sociaux/ass.py @@ -1,5 +1,7 @@ from numpy import absolute as abs_, logical_and as and_ +from openfisca_core.periods import Period + from openfisca_france.model.base import * @@ -79,7 +81,7 @@ class ass_base_ressources_individu(Variable): def formula(individu, period, parameters): # Rolling year - previous_year = period.start.period('year').offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) # N-1 last_year = period.last_year @@ -130,9 +132,9 @@ class ass_base_ressources_conjoint(Variable): def formula(individu, period, parameters): # Rolling year - previous_year = period.start.period('year').offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) - last_month = period.start.period('month').offset(-1) + last_month = Period(('month', period.start, 1)).offset(-1) ass_base_ressources_individu = individu('ass_base_ressources_individu', period) chomage_net_interrompue = individu('chomage_net', last_month) == 0 @@ -147,14 +149,14 @@ def formula(individu, period, parameters): def calculateWithAbatement(individu, parameters, period, ressourceName): - last_month = period.start.period('month').offset(-1) + last_month = Period(('month', period.start, 1)).offset(-1) has_ressources_substitution = ( individu('chomage_net', last_month) + individu('indemnites_journalieres', last_month) + individu('retraite_nette', last_month) ) > 0 # Rolling year - previous_year = period.start.period('year').offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) ressource_year = individu(ressourceName, previous_year, options=[ADD]) ressource_last_month = individu(ressourceName, last_month) diff --git a/openfisca_france/model/prestations/minima_sociaux/cs/eligibilite.py b/openfisca_france/model/prestations/minima_sociaux/cs/eligibilite.py index 4875139548..6903afb120 100644 --- a/openfisca_france/model/prestations/minima_sociaux/cs/eligibilite.py +++ b/openfisca_france/model/prestations/minima_sociaux/cs/eligibilite.py @@ -1,4 +1,7 @@ from numpy import logical_not as not_ + +from openfisca_core.periods import Period + from openfisca_france.model.base import Variable, Famille, MONTH, ADD, set_input_dispatch_by_period @@ -10,7 +13,7 @@ class css_cmu_acs_eligibilite(Variable): set_input = set_input_dispatch_by_period def formula(famille, period, parameters): - previous_year = period.start.period('year').offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) this_year = period.this_year age_min = parameters(period).prestations_sociales.solidarite_insertion.minima_sociaux.cs.cmu.age_limite_pac nb_enfants = famille('cmu_nb_pac', period) diff --git a/openfisca_france/model/prestations/minima_sociaux/cs/ressources.py b/openfisca_france/model/prestations/minima_sociaux/cs/ressources.py index cb50472c65..6699e6ead0 100644 --- a/openfisca_france/model/prestations/minima_sociaux/cs/ressources.py +++ b/openfisca_france/model/prestations/minima_sociaux/cs/ressources.py @@ -1,5 +1,7 @@ from numpy import absolute as abs_, logical_or as or_, logical_not as not_ +from openfisca_core.periods import Period + from openfisca_france.model.base import ( Variable, Individu, @@ -29,7 +31,7 @@ class css_cmu_base_ressources_individu(Variable): def formula(individu, period, parameters): # Rolling year - previous_year = period.start.period('year').offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) # N-1 last_year = period.last_year last_month = period.last_month @@ -93,7 +95,7 @@ class css_cmu_base_ressources(Variable): set_input = set_input_divide_by_period def formula(famille, period, parameters): - previous_year = period.start.period('year').offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) ressources_famille_a_inclure = [ 'af', diff --git a/openfisca_france/model/prestations/minima_sociaux/rsa.py b/openfisca_france/model/prestations/minima_sociaux/rsa.py index 75f09d3590..f8a2617e86 100644 --- a/openfisca_france/model/prestations/minima_sociaux/rsa.py +++ b/openfisca_france/model/prestations/minima_sociaux/rsa.py @@ -1,6 +1,8 @@ from numpy import datetime64, logical_and as and_, logical_or as or_ from openfisca_core import periods +from openfisca_core.periods import Period + from openfisca_france.model.base import * from openfisca_france.model.prestations.prestations_familiales.base_ressource import nb_enf @@ -960,7 +962,7 @@ class rsa_non_calculable_tns_individu(Variable): # En fait l'évaluation par le PCD est plutôt l'exception que la règle. En général on retient plutôt le bénéfice déclaré au FISC (après abattement forfaitaire ou réel). def formula(individu, period): - this_year_and_last_year = period.start.offset('first-of', 'year').period('year', 2).offset(-1) + this_year_and_last_year = Period(('year', period.start.offset('first-of', 'year'), 2)).offset(-1) rpns_benefice_exploitant_agricole = individu('rpns_benefice_exploitant_agricole', this_year_and_last_year, options = [ADD]) rpns_micro_entreprise_chiffre_affaires = individu('rpns_micro_entreprise_chiffre_affaires', this_year_and_last_year, options = [ADD]) rpns_autres_revenus = individu('rpns_autres_revenus', this_year_and_last_year, options = [ADD]) diff --git a/openfisca_france/model/prestations/prestations_familiales/af.py b/openfisca_france/model/prestations/prestations_familiales/af.py index b469c9ae95..9f969c2e76 100644 --- a/openfisca_france/model/prestations/prestations_familiales/af.py +++ b/openfisca_france/model/prestations/prestations_familiales/af.py @@ -152,7 +152,7 @@ def formula_2015_07_01(famille, period, parameters): class af_age_aine(Variable): value_type = int - default_value = -9999 + default_value = AGE_INT_MINIMUM entity = Famille label = "Allocations familiales - Âge de l'aîné des enfants éligibles" definition_period = MONTH @@ -161,14 +161,11 @@ class af_age_aine(Variable): def formula(famille, period, parameters): af = parameters(period).prestations_sociales.prestations_familiales.prestations_generales.af - age = famille.members('age', period) pfam_enfant_a_charge = famille.members('prestations_familiales_enfant_a_charge', period) - condition_eligibilite = pfam_enfant_a_charge * (age <= af.af_cm.age2) age_enfants_eligiles = age * condition_eligibilite - - return famille.max(age_enfants_eligiles, role = Famille.ENFANT) + return max_(famille.max(age_enfants_eligiles, role = Famille.ENFANT), AGE_INT_MINIMUM) # max_ may return -inf, so negative caping by AGE_INT_MINIMUM is needed class af_majoration_enfant(Variable): diff --git a/openfisca_france/model/prestations/prestations_familiales/ars.py b/openfisca_france/model/prestations/prestations_familiales/ars.py index 27552b7a6a..4cd2943b70 100644 --- a/openfisca_france/model/prestations/prestations_familiales/ars.py +++ b/openfisca_france/model/prestations/prestations_familiales/ars.py @@ -1,4 +1,7 @@ from numpy import logical_not as not_ + +from openfisca_core.periods import Period + from openfisca_france.model.base import * from openfisca_france.model.prestations.prestations_familiales.base_ressource import nb_enf @@ -15,8 +18,8 @@ def formula(famille, period, parameters): Allocation de rentrée scolaire brute de CRDS ''' janvier = period.first_month - octobre = period.start.offset('first-of', 'year').offset(9, 'month').period('month') - decembre = period.start.offset('first-of', 'year').offset(11, 'month').period('month') + octobre = Period(('month', period.start.offset('first-of', 'year').offset(9, 'month'), 1)) + decembre = Period(('month', period.start.offset('first-of', 'year').offset(11, 'month'), 1)) af_nbenf = famille('af_nbenf', octobre) base_ressources = famille('prestations_familiales_base_ressources', janvier) ars = parameters(octobre).prestations_sociales.prestations_familiales.education_presence_parentale.ars diff --git a/openfisca_france/model/prestations/prestations_familiales/base_ressource.py b/openfisca_france/model/prestations/prestations_familiales/base_ressource.py index 63527b5871..3722dcea4b 100644 --- a/openfisca_france/model/prestations/prestations_familiales/base_ressource.py +++ b/openfisca_france/model/prestations/prestations_familiales/base_ressource.py @@ -1,8 +1,8 @@ -from numpy import logical_or as or_ +from numpy import datetime64, logical_or as or_ -from openfisca_france.model.base import * +from openfisca_core.periods import Period -from numpy import datetime64 +from openfisca_france.model.base import * class autonomie_financiere(Variable): @@ -18,7 +18,7 @@ class autonomie_financiere(Variable): def formula(individu, period, parameters): # D'après service-public.fr, la condition de dépassement du salaire plafonds n'est pas évalué de la même manière suivant si l'enfant est étudiant ou salarié/apprenti/stagiaire. - salaire_net_mensualise = individu('salaire_net', period.start.period('month', 6).offset(-6), options = [ADD]) / 6 + salaire_net_mensualise = individu('salaire_net', Period(('month', period.start, 6)).offset(-6), options = [ADD]) / 6 _P = parameters(period) diff --git a/openfisca_france/model/revenus/activite/non_salarie.py b/openfisca_france/model/revenus/activite/non_salarie.py index ca43f12240..87fed1d723 100644 --- a/openfisca_france/model/revenus/activite/non_salarie.py +++ b/openfisca_france/model/revenus/activite/non_salarie.py @@ -1,3 +1,5 @@ +from openfisca_core.periods import Period + from openfisca_france.model.base import * @@ -2086,7 +2088,7 @@ class travailleur_non_salarie(Variable): set_input = set_input_dispatch_by_period def formula(individu, period, parameters): - this_year_and_last_year = period.start.offset('first-of', 'year').period('year', 2).offset(-1) + this_year_and_last_year = Period(('year', period.start.offset('first-of', 'year'), 2)).offset(-1) rpns_auto_entrepreneur_chiffre_affaires = individu('rpns_auto_entrepreneur_chiffre_affaires', period) != 0 rpns_micro_entreprise_chiffre_affaires = individu('rpns_micro_entreprise_chiffre_affaires', this_year_and_last_year, options = [ADD]) != 0 rpns_autres_revenus = individu('rpns_autres_revenus', this_year_and_last_year, options = [ADD]) != 0 diff --git a/openfisca_france/model/revenus/activite/salarie.py b/openfisca_france/model/revenus/activite/salarie.py index 1336ce0cb5..bc9afe9ae9 100644 --- a/openfisca_france/model/revenus/activite/salarie.py +++ b/openfisca_france/model/revenus/activite/salarie.py @@ -1,5 +1,8 @@ from functools import partial from numpy import busday_count as original_busday_count, datetime64, timedelta64, where + +from openfisca_core.periods import Period + from openfisca_france.model.base import * @@ -707,7 +710,7 @@ class ppv_eligibilite_exceptionnelle(Variable): ''' def formula_2022_07_01(individu, period, parameters): - annee_glissante = period.start.period('year').offset(-1) + annee_glissante = Period(('year', period.start, 1)).offset(-1) salaire_de_base_annuel = individu('salaire_de_base', annee_glissante, options=[ADD]) smic_b_annuel = parameters(period).marche_travail.salaire_minimum.smic.smic_b_mensuel * 12 quotite_de_travail = individu('quotite_de_travail', period, options=[ADD]) / 12 @@ -804,7 +807,7 @@ def formula_2019_01_01(individu, period, parameters): sinon Pas d'exonération ''' - annee_glissante = period.start.period('year').offset(-1) + annee_glissante = Period(('year', period.start, 1)).offset(-1) salaire_de_base_annuel = individu('salaire_de_base', annee_glissante, options=[ADD]) smic_b_annuel = parameters(period).marche_travail.salaire_minimum.smic.smic_b_mensuel * 12 quotite_de_travail = individu('quotite_de_travail', period, options=[ADD]) / 12 @@ -1234,7 +1237,7 @@ class indice_majore(Variable): set_input = set_input_dispatch_by_period def formula(individu, period, parameters): - period = period.start.period('month').offset('first-of') + period = Period(('month', period.start, 1)).offset('first-of') categorie_salarie = individu('categorie_salarie', period) traitement_indiciaire_brut = individu('traitement_indiciaire_brut', period) traitement_annuel_brut = parameters(period).prestations_sociales.fonc.IM_100 @@ -1285,7 +1288,7 @@ def formula(famille, period, parameters): D'où l'introduction de cette variable alternative. ''' - salaire_de_base_mensualise = famille.members('salaire_de_base', period.start.period('month', 6).offset(-6), options = [ADD]) + salaire_de_base_mensualise = famille.members('salaire_de_base', Period(('month', period.start, 6)).offset(-6), options = [ADD]) law = parameters(period) nbh_travaillees = 169 smic_mensuel_brut = law.marche_travail.salaire_minimum.smic.smic_b_horaire * nbh_travaillees diff --git a/openfisca_france/model/revenus/remplacement/rente_accident_travail.py b/openfisca_france/model/revenus/remplacement/rente_accident_travail.py index 580d9163d3..8768295662 100644 --- a/openfisca_france/model/revenus/remplacement/rente_accident_travail.py +++ b/openfisca_france/model/revenus/remplacement/rente_accident_travail.py @@ -1,3 +1,5 @@ +from openfisca_core.periods import Period + from openfisca_france.model.base import * @@ -10,7 +12,7 @@ class rente_accident_travail(Variable): set_input = set_input_divide_by_period def formula(individu, period): - previous_year = period.start.period('year').offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) non_salarie_agricole = individu('rpns_benefice_exploitant_agricole', previous_year, options=[ADD]) != 0 rente_accident_travail_salarie = individu('rente_accident_travail_salarie', period) rente_accident_travail_exploitant_agricole = individu('rente_accident_travail_exploitant_agricole', period) @@ -27,7 +29,7 @@ class rente_accident_travail_salarie(Variable): set_input = set_input_divide_by_period def formula(individu, period): - previous_year = period.start.period('year').offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) salarie = individu('salaire_net', previous_year, options=[ADD]) != 0 rente_accident_travail_rachat = individu('rente_accident_travail_rachat', period) taux_incapacite = individu('taux_accident_travail', period) @@ -52,7 +54,7 @@ class rente_accident_travail_exploitant_agricole(Variable): set_input = set_input_divide_by_period def formula(individu, period): - previous_year = period.start.period('year').offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) non_salarie_agricole = individu('rpns_benefice_exploitant_agricole', previous_year, options=[ADD]) != 0 rente_accident_travail_rachat = individu('rente_accident_travail_rachat', period) taux_incapacite = individu('taux_accident_travail', period) @@ -180,7 +182,7 @@ class rente_accident_travail_salaire_utile(Variable): set_input = set_input_divide_by_period def formula(individu, period, parameters): - previous_year = period.start.period('year').offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) rente_at = parameters(period).prestations_sociales.solidarite_insertion.minima_sociaux.accident_travail.rente salaire_net = individu('salaire_net', previous_year, options=[ADD]) diff --git a/setup.py b/setup.py index 17bee9718b..0a9eb1a3fa 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ #! /usr/bin/env python -from setuptools import setup, find_packages +from setuptools import setup, find_namespace_packages from pathlib import Path # Read the contents of our README file for PyPi @@ -9,7 +9,7 @@ setup( name = 'OpenFisca-France', - version = '148.0.0', + version = '149.0.0', author = 'OpenFisca Team', author_email = 'contact@openfisca.fr', classifiers = [ @@ -17,10 +17,9 @@ 'License :: OSI Approved :: GNU Affero General Public License v3', 'Operating System :: POSIX', 'Programming Language :: Python', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', 'Topic :: Scientific/Engineering :: Information Analysis', ], description = 'French tax and benefit system for OpenFisca', @@ -39,37 +38,37 @@ ], extras_require = { 'inversion_revenus': [ - 'scipy >= 0.17', + 'scipy >=1.10.1, <2.0', ], 'de_net_a_brut': [ - 'scipy >= 0.17', + 'scipy >=1.10.1, <2.0', ], 'taxipp': [ - 'pandas >= 0.13', + 'pandas >=1.5.3, <2.0', ], 'dev': [ - 'autopep8 ==1.5.7', - 'flake8 >= 4.0.0, < 5.0.0', - 'flake8-print >= 5.0.0, < 6.0.0', - 'flake8-quotes >= 3.3.1, < 6.0.0', - 'pytest >= 5.0.0, < 7.0.0', - 'scipy >= 0.17', # Only used to test de_net_a_brut reform - 'requests >= 2.8', - 'yamllint >=1.11.1,<1.27' + 'autopep8 >=2.0.2, <3.0', + 'flake8 >=6.0.0, <7.0.0', + 'flake8-print >=5.0.0, <6.0.0', + 'flake8-quotes >=3.3.2', + 'pytest >=7.2.2, <8.0', + 'scipy >=1.10.1, <2.0', # Only used to test de_net_a_brut reform + 'requests >=2.28.2, <3.0', + 'yamllint >=1.30.0, <2.0' ], 'casd-dev': [ # Same as dev with packages not available at CASD removed - 'autopep8 >=1.3.2', - 'pytest >= 5.0.0, < 7.0.0', - 'requests >= 2.8', - 'scipy >= 0.17', # Only used to test de_net_a_brut reform + 'autopep8 >=2.0.2, <3.0', + 'pytest >=7.2.2, <8.0', + 'requests >=2.28.2, <3.0', + 'scipy >=1.10.1, <2.0', # Only used to test de_net_a_brut reform ] }, include_package_data = True, # Will read MANIFEST.in install_requires = [ - 'OpenFisca-Core >=35.8.0,<36.0', + 'OpenFisca-Core >=40, <41', ], - packages = find_packages(exclude = [ + packages = find_namespace_packages(exclude = [ 'openfisca_france.tests*', 'openfisca_france.assets.taxe_habitation.source*', ]), diff --git a/tests/formulas/age.yaml b/tests/formulas/age.yaml index 2afb21337f..336934d64d 100644 --- a/tests/formulas/age.yaml +++ b/tests/formulas/age.yaml @@ -116,3 +116,24 @@ - 40 - 9 - 9 +- name: Age des enfants dans les familles sans enfants (pour éviter les -inf) + period: 2015-01 + absolute_error_margin: 0.005 + input: + famille: + parents: [parent1, parent2] + foyer_fiscal: + declarants: [parent1, parent2] + menage: + personne_de_reference: parent1 + conjoint: parent2 + individus: + parent1: + age_en_mois: + 2015-01: 40 * 12 + parent2: + age_en_mois: + 2015-01: 40 * 12 + output: + af_age_aine: + 2015-01: -9999 diff --git a/tests/test_entities.py b/tests/test_entities.py index 8cedba7b84..adb6e6a0db 100644 --- a/tests/test_entities.py +++ b/tests/test_entities.py @@ -112,7 +112,7 @@ def test_transpose_string(): depcom_famille = famille.first_person.menage('depcom', period = reference_period) - assert((depcom_famille == [b'93400', b'89300']).all()) + assert (depcom_famille == [b'93400', b'89300']).all() def test_value_from_person():