From 01322a5fa7df879331c21adcc702048c83b10f98 Mon Sep 17 00:00:00 2001 From: Emmanuel Raviart Date: Tue, 20 Dec 2022 15:49:48 +0100 Subject: [PATCH 1/6] Use Period() instead of .period method --- .../cotisations_sociales/allegements.py | 8 ++++-- .../cotisations_sociales/base.py | 8 ++++-- .../taxe_habitation/taxe_habitation.py | 4 ++- openfisca_france/model/prestations/agepi.py | 4 ++- .../model/prestations/aide_mobilite.py | 5 +++- .../indemnite_inflation.py | 28 ++++++++++--------- .../model/prestations/aides_logement.py | 6 ++-- .../model/prestations/autonomie.py | 10 ++++--- .../jeunes/contrat_engagement_jeune.py | 6 ++-- .../model/prestations/logement_social.py | 4 +-- .../model/prestations/minima_sociaux/aah.py | 12 ++++---- .../prestations/minima_sociaux/asi_aspa.py | 4 ++- .../model/prestations/minima_sociaux/ass.py | 12 ++++---- .../minima_sociaux/cs/eligibilite.py | 5 +++- .../minima_sociaux/cs/ressources.py | 6 ++-- .../model/prestations/minima_sociaux/rsa.py | 6 ++-- .../prestations/prestations_familiales/ars.py | 7 +++-- .../prestations_familiales/base_ressource.py | 7 +++-- .../model/revenus/activite/non_salarie.py | 4 ++- .../model/revenus/activite/salarie.py | 11 +++++--- .../remplacement/rente_accident_travail.py | 10 ++++--- 21 files changed, 104 insertions(+), 63 deletions(-) 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 78b1006f09..8167643a22 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__) @@ -535,7 +537,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 @@ -546,8 +548,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..41c51e8541 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 * @@ -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..b0c4d49d1a 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')).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..89a102b510 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).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..66261d5849 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).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 064536d4ef..39d68bb886 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_core.periods import Period + from openfisca_france.model.base import * -from openfisca_core import periods + from numpy import logical_or as or_, logical_and as and_ # Les éligibilités séparées de l'indemnité inflation @@ -16,14 +18,14 @@ class eligibilite_indemnite_inflation_non_salarie(Variable): def formula(individu, period, parameters): - oct_2021 = periods.period('2021-10') + oct_2021 = Period('2021-10') # non-salarié eligibilite_cat_non_sal = (individu('categorie_non_salarie', oct_2021.this_year) != TypesCategorieNonSalarie.non_pertinent) # revenu d'activité inférieure à € 2000 nets par mois en 2020 (selon déclaration annuelle des revenus) - annee_2020 = periods.period('2020') - jan_sep_2021 = periods.period('month:2021-01:9') + annee_2020 = Period('2020') + jan_sep_2021 = Period('month:2021-01:9') # chiffre d'affaires rev_net_auto = individu('rpns_auto_entrepreneur_revenus_net', annee_2020, options = [ADD]) @@ -55,7 +57,7 @@ class eligibilite_indemnite_inflation_salarie_prive(Variable): def formula(individu, period, parameters): # éligibilité statut - oct_2021 = periods.period('2021-10') + oct_2021 = Period('2021-10') eligibilite_activite = individu('activite', oct_2021) == TypesActivite.actif eligibilite_alternance = individu('alternant', oct_2021) > 0 eligibilite = (eligibilite_activite + eligibilite_alternance) > 0 @@ -79,7 +81,7 @@ def formula(individu, period, parameters): tsal = 0 for rp in rev_periods: - per = periods.period(rp) + per = Period(rp) sal = individu('salaire_net', per, options=[ADD]) if sal > 0: @@ -106,7 +108,7 @@ class eligibilite_indemnite_inflation_public(Variable): def formula(individu, period, parameters): - oct_2021 = periods.period('2021-10') + oct_2021 = Period('2021-10') # agent public eligibilite_public = ((individu('categorie_salarie', oct_2021) == TypesCategorieSalarie.public_titulaire_etat) @@ -134,7 +136,7 @@ def formula(individu, period, parameters): tsal = 0 for rp in rev_periods: - per = periods.period(rp) + per = Period(rp) sal = individu('salaire_net', per, options=[ADD]) if sal > 0: @@ -162,8 +164,8 @@ class eligibilite_indemnite_inflation_retraite(Variable): def formula(individu, period, parameters): - oct_2021 = periods.period('2021-10') - annee_2021 = periods.period('2021') + oct_2021 = Period('2021-10') + annee_2021 = Period('2021') # bénéficiaire d'une pension de retraite en octobre 2021 eligibilite_retraite = (individu('activite', oct_2021) == TypesActivite.retraite) @@ -194,7 +196,7 @@ class eligibilite_indemnite_inflation_prest_soc(Variable): def formula(individu, period, parameters): - oct_2021 = periods.period('2021-10') + oct_2021 = Period('2021-10') # pension d'invalidité <= 2000 par mois eligibilite_pension_invalidite = (individu('pensions_invalidite', oct_2021) <= 2000) * (individu('pensions_invalidite', oct_2021) > 0) @@ -224,7 +226,7 @@ class eligibilite_indemnite_inflation_jeune(Variable): def formula(individu, period, parameters): - oct_2021 = periods.period('2021-10') + oct_2021 = Period('2021-10') # au moins 16 ans eligibilite_age = individu('age', oct_2021) >= 16 @@ -271,7 +273,7 @@ class eligibilite_indemnite_inflation_demandeur_emploi(Variable): def formula(individu, period, parameters): - oct_2021 = periods.period('2021-10') + oct_2021 = Period('2021-10') # chômeur en octobre 2021 eligibilite_chomeur = (individu('activite', oct_2021) == TypesActivite.chomeur) diff --git a/openfisca_france/model/prestations/aides_logement.py b/openfisca_france/model/prestations/aides_logement.py index 8154196b8e..9154e103f0 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).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..5558da6138 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')) 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')) 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')) 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')) 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 d9f49c563f..96f8edb28e 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 @@ -17,7 +19,7 @@ def formula_2022_03_01(individu, period, parameters): montant_degressivite = parameters(period).prestations_sociales.aides_jeunes.contrat_engagement_jeune.degressivite.montant age = individu('age', period) majeur = individu('majeur', period) - previous_year = period.start.period('year').offset(-1) + previous_year = Period('year', period.start).offset(-1) tranche = individu.foyer_fiscal('ir_tranche', previous_year) degressivite = majeur * (tranche > 0) * montant_degressivite @@ -91,7 +93,7 @@ def formula_2022_03_01(individu, period, parameters): niveau_ressources = (niveau_ressources_individuelles_3_mois) / 3 - previous_year = period.start.period('year').offset(-1) + previous_year = Period('year', period.start).offset(-1) tranche = individu.foyer_fiscal('ir_tranche', previous_year) <= 1 return (niveau_ressources <= plafond) * sans_rsa * sans_ppa * tranche diff --git a/openfisca_france/model/prestations/logement_social.py b/openfisca_france/model/prestations/logement_social.py index 84fa73fd9e..ddb503b2e3 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'))) 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..dfd294b101 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]) @@ -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).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) diff --git a/openfisca_france/model/prestations/minima_sociaux/asi_aspa.py b/openfisca_france/model/prestations/minima_sociaux/asi_aspa.py index 5a691c3ca5..421f2c86af 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).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..0327e9f8a8 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).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).offset(-1) - last_month = period.start.period('month').offset(-1) + last_month = Period('month', period.start).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).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).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..487547fb63 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).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..93792d9a76 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).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).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 b7d6dce308..68233af899 100644 --- a/openfisca_france/model/prestations/minima_sociaux/rsa.py +++ b/openfisca_france/model/prestations/minima_sociaux/rsa.py @@ -1,6 +1,6 @@ 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 @@ -676,7 +676,7 @@ def formula(famille, period, parameters): etudiant_i = famille.members('etudiant', period) - if period.start < periods.period('2009-06').start: + if period.start < Period('2009-06').start: # Les jeunes de moins de 25 ans ne sont pas éligibles au RMI rsa_jeune_condition_i = False else: @@ -939,7 +939,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/ars.py b/openfisca_france/model/prestations/prestations_familiales/ars.py index 27552b7a6a..e17def39ce 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')) + decembre = Period('month', period.start.offset('first-of', 'year').offset(11, 'month')) 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..43700aaf6d 100644 --- a/openfisca_france/model/prestations/prestations_familiales/base_ressource.py +++ b/openfisca_france/model/prestations/prestations_familiales/base_ressource.py @@ -1,8 +1,9 @@ -from numpy import logical_or as or_ +from numpy import datetime64, logical_or as or_ + +from openfisca_core.periods import Period from openfisca_france.model.base import * -from numpy import datetime64 class autonomie_financiere(Variable): @@ -18,7 +19,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 9814f81123..1becb19073 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 * @@ -2085,7 +2087,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 f7ad8ea6d7..8fa2debcda 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 * @@ -717,7 +720,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).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 @@ -814,7 +817,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).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 @@ -1246,7 +1249,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).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 @@ -1297,7 +1300,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..b09eff0896 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).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).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).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).offset(-1) rente_at = parameters(period).prestations_sociales.solidarite_insertion.minima_sociaux.accident_travail.rente salaire_net = individu('salaire_net', previous_year, options=[ADD]) From e86067a200d184b40650a5c407afadd9abff4d47 Mon Sep 17 00:00:00 2001 From: Emmanuel Raviart Date: Tue, 20 Dec 2022 16:32:05 +0100 Subject: [PATCH 2/6] Ensure Period argument is a triple Restore use of periods.period() --- .../cotisations_sociales/allegements.py | 6 ++--- .../cotisations_sociales/base.py | 2 +- .../taxe_habitation/taxe_habitation.py | 2 +- openfisca_france/model/prestations/agepi.py | 2 +- .../model/prestations/aide_mobilite.py | 2 +- .../indemnite_inflation.py | 26 +++++++++---------- .../model/prestations/aides_logement.py | 2 +- .../model/prestations/autonomie.py | 8 +++--- .../jeunes/contrat_engagement_jeune.py | 4 +-- .../model/prestations/logement_social.py | 2 +- .../model/prestations/minima_sociaux/aah.py | 10 +++---- .../prestations/minima_sociaux/asi_aspa.py | 2 +- .../model/prestations/minima_sociaux/ass.py | 10 +++---- .../minima_sociaux/cs/eligibilite.py | 2 +- .../minima_sociaux/cs/ressources.py | 4 +-- .../model/prestations/minima_sociaux/rsa.py | 6 +++-- .../prestations/prestations_familiales/ars.py | 4 +-- .../prestations_familiales/base_ressource.py | 3 +-- .../model/revenus/activite/non_salarie.py | 2 +- .../model/revenus/activite/salarie.py | 8 +++--- .../remplacement/rente_accident_travail.py | 8 +++--- 21 files changed, 58 insertions(+), 57 deletions(-) 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 8167643a22..cde0441bcf 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 @@ -537,7 +537,7 @@ def compute_allegement_anticipe(individu, period, parameters, variable_name, com if period.start.month == 12: cumul = individu( variable_name, - Period('month', period.start.offset('first-of', 'year'), 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 +548,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('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) + 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 41c51e8541..940135b9e5 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 @@ -375,7 +375,7 @@ def compute_cotisation_anticipee(individu, period, parameters, cotisation_type = if period.start.month == 12: cumul = individu( variable_name, - Period('month', period.start.offset('first-of', 'month').offset(-11, 'month'), 11), + 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 b0c4d49d1a..025d552c48 100644 --- a/openfisca_france/model/prelevements_obligatoires/taxe_habitation/taxe_habitation.py +++ b/openfisca_france/model/prelevements_obligatoires/taxe_habitation/taxe_habitation.py @@ -335,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('year', period.start.offset('first-of', 'year')).offset(-ecart_avec_2000) + annee_2000 = Period(('year', period.start.offset('first-of', 'year'))).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 89a102b510..c2d4a3dd1d 100644 --- a/openfisca_france/model/prestations/agepi.py +++ b/openfisca_france/model/prestations/agepi.py @@ -85,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('year', period.start).offset(-1).offset(-1, 'month') + annee_glissante = Period(('year', period.start).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 66261d5849..fcf618c891 100644 --- a/openfisca_france/model/prestations/aide_mobilite.py +++ b/openfisca_france/model/prestations/aide_mobilite.py @@ -329,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('year', period.start).offset(-1) + annee_glissante = Period(('year', period.start)).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 39d68bb886..b8894b994f 100644 --- a/openfisca_france/model/prestations/aides_exceptionnelles/indemnite_inflation.py +++ b/openfisca_france/model/prestations/aides_exceptionnelles/indemnite_inflation.py @@ -1,4 +1,4 @@ -from openfisca_core.periods import Period +from openfisca_core import periods from openfisca_france.model.base import * @@ -18,14 +18,14 @@ class eligibilite_indemnite_inflation_non_salarie(Variable): def formula(individu, period, parameters): - oct_2021 = Period('2021-10') + oct_2021 = periods.period('2021-10') # non-salarié eligibilite_cat_non_sal = (individu('categorie_non_salarie', oct_2021.this_year) != TypesCategorieNonSalarie.non_pertinent) # revenu d'activité inférieure à € 2000 nets par mois en 2020 (selon déclaration annuelle des revenus) - annee_2020 = Period('2020') - jan_sep_2021 = Period('month:2021-01:9') + annee_2020 = periods.period('2020') + jan_sep_2021 = periods.period('month:2021-01:9') # chiffre d'affaires rev_net_auto = individu('rpns_auto_entrepreneur_revenus_net', annee_2020, options = [ADD]) @@ -57,7 +57,7 @@ class eligibilite_indemnite_inflation_salarie_prive(Variable): def formula(individu, period, parameters): # éligibilité statut - oct_2021 = Period('2021-10') + oct_2021 = periods.period('2021-10') eligibilite_activite = individu('activite', oct_2021) == TypesActivite.actif eligibilite_alternance = individu('alternant', oct_2021) > 0 eligibilite = (eligibilite_activite + eligibilite_alternance) > 0 @@ -81,7 +81,7 @@ def formula(individu, period, parameters): tsal = 0 for rp in rev_periods: - per = Period(rp) + per = periods.period(rp) sal = individu('salaire_net', per, options=[ADD]) if sal > 0: @@ -108,7 +108,7 @@ class eligibilite_indemnite_inflation_public(Variable): def formula(individu, period, parameters): - oct_2021 = Period('2021-10') + oct_2021 = periods.period('2021-10') # agent public eligibilite_public = ((individu('categorie_salarie', oct_2021) == TypesCategorieSalarie.public_titulaire_etat) @@ -136,7 +136,7 @@ def formula(individu, period, parameters): tsal = 0 for rp in rev_periods: - per = Period(rp) + per = periods.period(rp) sal = individu('salaire_net', per, options=[ADD]) if sal > 0: @@ -164,8 +164,8 @@ class eligibilite_indemnite_inflation_retraite(Variable): def formula(individu, period, parameters): - oct_2021 = Period('2021-10') - annee_2021 = Period('2021') + oct_2021 = periods.period('2021-10') + annee_2021 = periods.period('2021') # bénéficiaire d'une pension de retraite en octobre 2021 eligibilite_retraite = (individu('activite', oct_2021) == TypesActivite.retraite) @@ -196,7 +196,7 @@ class eligibilite_indemnite_inflation_prest_soc(Variable): def formula(individu, period, parameters): - oct_2021 = Period('2021-10') + oct_2021 = periods.period('2021-10') # pension d'invalidité <= 2000 par mois eligibilite_pension_invalidite = (individu('pensions_invalidite', oct_2021) <= 2000) * (individu('pensions_invalidite', oct_2021) > 0) @@ -226,7 +226,7 @@ class eligibilite_indemnite_inflation_jeune(Variable): def formula(individu, period, parameters): - oct_2021 = Period('2021-10') + oct_2021 = periods.period('2021-10') # au moins 16 ans eligibilite_age = individu('age', oct_2021) >= 16 @@ -273,7 +273,7 @@ class eligibilite_indemnite_inflation_demandeur_emploi(Variable): def formula(individu, period, parameters): - oct_2021 = Period('2021-10') + oct_2021 = periods.period('2021-10') # chômeur en octobre 2021 eligibilite_chomeur = (individu('activite', oct_2021) == TypesActivite.chomeur) diff --git a/openfisca_france/model/prestations/aides_logement.py b/openfisca_france/model/prestations/aides_logement.py index 9154e103f0..9d6e24d437 100644 --- a/openfisca_france/model/prestations/aides_logement.py +++ b/openfisca_france/model/prestations/aides_logement.py @@ -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('year', period.start).offset(-1).offset(-1, 'month') + annee_glissante = Period(('year', period.start)).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 5558da6138..f1e0dd25d3 100644 --- a/openfisca_france/model/prestations/autonomie.py +++ b/openfisca_france/model/prestations/autonomie.py @@ -135,7 +135,7 @@ class apa_eligibilite(Variable): set_input = set_input_dispatch_by_period def formula_2002(individu, period, parameters): - period = Period('month', period.start.offset('first-of', 'month')) + period = Period(('month', period.start.offset('first-of', 'month'))) 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 @@ -174,7 +174,7 @@ class apa_domicile(Variable): set_input = set_input_divide_by_period def formula_2002(individu, period, parameters): - period = Period('month', period.start.offset('first-of', 'month')) + period = Period(('month', period.start.offset('first-of', 'month'))) 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 @@ -195,7 +195,7 @@ class apa_etablissement(Variable): set_input = set_input_divide_by_period def formula_2002(individu, period, parameters): - period = Period('month', period.start.offset('first-of', 'month')) + period = Period(('month', period.start.offset('first-of', 'month'))) 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 @@ -352,7 +352,7 @@ class apa_urgence_institution(Variable): set_input = set_input_divide_by_period def formula_2002(individu, period, parameters): - period = Period('month', period.start.offset('first-of', 'month')) + period = Period(('month', period.start.offset('first-of', 'month'))) 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 96f8edb28e..d648e2279c 100644 --- a/openfisca_france/model/prestations/jeunes/contrat_engagement_jeune.py +++ b/openfisca_france/model/prestations/jeunes/contrat_engagement_jeune.py @@ -19,7 +19,7 @@ def formula_2022_03_01(individu, period, parameters): montant_degressivite = parameters(period).prestations_sociales.aides_jeunes.contrat_engagement_jeune.degressivite.montant age = individu('age', period) majeur = individu('majeur', period) - previous_year = Period('year', period.start).offset(-1) + previous_year = Period(('year', period.start)).offset(-1) tranche = individu.foyer_fiscal('ir_tranche', previous_year) degressivite = majeur * (tranche > 0) * montant_degressivite @@ -93,7 +93,7 @@ def formula_2022_03_01(individu, period, parameters): niveau_ressources = (niveau_ressources_individuelles_3_mois) / 3 - previous_year = Period('year', period.start).offset(-1) + previous_year = Period(('year', period.start)).offset(-1) tranche = individu.foyer_fiscal('ir_tranche', previous_year) <= 1 return (niveau_ressources <= plafond) * sans_rsa * sans_ppa * tranche diff --git a/openfisca_france/model/prestations/logement_social.py b/openfisca_france/model/prestations/logement_social.py index ddb503b2e3..c8a5668854 100644 --- a/openfisca_france/model/prestations/logement_social.py +++ b/openfisca_france/model/prestations/logement_social.py @@ -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('year', period.start.offset('first-of', 'year'))) + rfr_n0 = famille.demandeur.foyer_fiscal('rfr', Period(('year', period.start.offset('first-of', 'year')))) 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 dfd294b101..5b2164d3cd 100644 --- a/openfisca_france/model/prestations/minima_sociaux/aah.py +++ b/openfisca_france/model/prestations/minima_sociaux/aah.py @@ -107,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('month', period.first_month.start, 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]) @@ -153,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('month', period.first_month.start, 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]) @@ -241,7 +241,7 @@ class aah_base_ressources_activite_eval_trimestrielle(Variable): def formula(individu, period): period = period.first_month - three_previous_months = Period('month', period.start, 3).offset(-3) + three_previous_months = Period(('month', period.start, 3)).offset(-3) last_year = period.last_year ressources_a_inclure = [ @@ -301,7 +301,7 @@ class aah_base_ressources_hors_activite_eval_trimestrielle(Variable): def formula(individu, period): period = period.first_month - three_previous_months = Period('month', period.start, 3).offset(-3) + three_previous_months = Period(('month', period.start, 3)).offset(-3) ressources_a_inclure = [ 'asi', @@ -566,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('year', period.start).offset(-1) + annee_precedente = Period(('year', period.start)).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) diff --git a/openfisca_france/model/prestations/minima_sociaux/asi_aspa.py b/openfisca_france/model/prestations/minima_sociaux/asi_aspa.py index 421f2c86af..240a141426 100644 --- a/openfisca_france/model/prestations/minima_sociaux/asi_aspa.py +++ b/openfisca_france/model/prestations/minima_sociaux/asi_aspa.py @@ -149,7 +149,7 @@ class asi_eligibilite(Variable): set_input = set_input_dispatch_by_period def formula(individu, period): - last_month = Period('month', period.start).offset(-1) + last_month = Period(('month', period.start)).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 0327e9f8a8..88062b21b9 100644 --- a/openfisca_france/model/prestations/minima_sociaux/ass.py +++ b/openfisca_france/model/prestations/minima_sociaux/ass.py @@ -81,7 +81,7 @@ class ass_base_ressources_individu(Variable): def formula(individu, period, parameters): # Rolling year - previous_year = Period('year', period.start).offset(-1) + previous_year = Period(('year', period.start)).offset(-1) # N-1 last_year = period.last_year @@ -132,9 +132,9 @@ class ass_base_ressources_conjoint(Variable): def formula(individu, period, parameters): # Rolling year - previous_year = Period('year', period.start).offset(-1) + previous_year = Period(('year', period.start)).offset(-1) - last_month = Period('month', period.start).offset(-1) + last_month = Period(('month', period.start)).offset(-1) ass_base_ressources_individu = individu('ass_base_ressources_individu', period) chomage_net_interrompue = individu('chomage_net', last_month) == 0 @@ -149,14 +149,14 @@ def formula(individu, period, parameters): def calculateWithAbatement(individu, parameters, period, ressourceName): - last_month = Period('month', period.start).offset(-1) + last_month = Period(('month', period.start)).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('year', period.start).offset(-1) + previous_year = Period(('year', period.start)).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 487547fb63..8d27e4413f 100644 --- a/openfisca_france/model/prestations/minima_sociaux/cs/eligibilite.py +++ b/openfisca_france/model/prestations/minima_sociaux/cs/eligibilite.py @@ -13,7 +13,7 @@ class css_cmu_acs_eligibilite(Variable): set_input = set_input_dispatch_by_period def formula(famille, period, parameters): - previous_year = Period('year', period.start).offset(-1) + previous_year = Period(('year', period.start)).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 93792d9a76..7f30c386f0 100644 --- a/openfisca_france/model/prestations/minima_sociaux/cs/ressources.py +++ b/openfisca_france/model/prestations/minima_sociaux/cs/ressources.py @@ -31,7 +31,7 @@ class css_cmu_base_ressources_individu(Variable): def formula(individu, period, parameters): # Rolling year - previous_year = Period('year', period.start).offset(-1) + previous_year = Period(('year', period.start)).offset(-1) # N-1 last_year = period.last_year last_month = period.last_month @@ -95,7 +95,7 @@ class css_cmu_base_ressources(Variable): set_input = set_input_divide_by_period def formula(famille, period, parameters): - previous_year = Period('year', period.start).offset(-1) + previous_year = Period(('year', period.start)).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 68233af899..ca961476db 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 @@ -676,7 +678,7 @@ def formula(famille, period, parameters): etudiant_i = famille.members('etudiant', period) - if period.start < Period('2009-06').start: + if period.start < periods.period('2009-06').start: # Les jeunes de moins de 25 ans ne sont pas éligibles au RMI rsa_jeune_condition_i = False else: @@ -939,7 +941,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('year', period.start.offset('first-of', '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/ars.py b/openfisca_france/model/prestations/prestations_familiales/ars.py index e17def39ce..d5c92551fa 100644 --- a/openfisca_france/model/prestations/prestations_familiales/ars.py +++ b/openfisca_france/model/prestations/prestations_familiales/ars.py @@ -18,8 +18,8 @@ def formula(famille, period, parameters): Allocation de rentrée scolaire brute de CRDS ''' janvier = period.first_month - octobre = Period('month', period.start.offset('first-of', 'year').offset(9, 'month')) - decembre = Period('month', period.start.offset('first-of', 'year').offset(11, 'month')) + octobre = Period(('month', period.start.offset('first-of', 'year').offset(9, 'month'))) + decembre = Period(('month', period.start.offset('first-of', 'year').offset(11, 'month'))) 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 43700aaf6d..3722dcea4b 100644 --- a/openfisca_france/model/prestations/prestations_familiales/base_ressource.py +++ b/openfisca_france/model/prestations/prestations_familiales/base_ressource.py @@ -5,7 +5,6 @@ from openfisca_france.model.base import * - class autonomie_financiere(Variable): value_type = bool entity = Individu @@ -19,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('month', period.start, 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 1becb19073..f1d6696863 100644 --- a/openfisca_france/model/revenus/activite/non_salarie.py +++ b/openfisca_france/model/revenus/activite/non_salarie.py @@ -2087,7 +2087,7 @@ class travailleur_non_salarie(Variable): set_input = set_input_dispatch_by_period def formula(individu, period, parameters): - this_year_and_last_year = Period('year', period.start.offset('first-of', '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 8fa2debcda..7e0f061dd5 100644 --- a/openfisca_france/model/revenus/activite/salarie.py +++ b/openfisca_france/model/revenus/activite/salarie.py @@ -720,7 +720,7 @@ class ppv_eligibilite_exceptionnelle(Variable): ''' def formula_2022_07_01(individu, period, parameters): - annee_glissante = Period('year', period.start).offset(-1) + annee_glissante = Period(('year', period.start)).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 @@ -817,7 +817,7 @@ def formula_2019_01_01(individu, period, parameters): sinon Pas d'exonération ''' - annee_glissante = Period('year', period.start).offset(-1) + annee_glissante = Period(('year', period.start)).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 @@ -1249,7 +1249,7 @@ class indice_majore(Variable): set_input = set_input_dispatch_by_period def formula(individu, period, parameters): - period = Period('month', period.start).offset('first-of') + period = Period(('month', period.start)).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 @@ -1300,7 +1300,7 @@ def formula(famille, period, parameters): D'où l'introduction de cette variable alternative. ''' - salaire_de_base_mensualise = famille.members('salaire_de_base', Period('month', period.start, 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 b09eff0896..64417c061b 100644 --- a/openfisca_france/model/revenus/remplacement/rente_accident_travail.py +++ b/openfisca_france/model/revenus/remplacement/rente_accident_travail.py @@ -12,7 +12,7 @@ class rente_accident_travail(Variable): set_input = set_input_divide_by_period def formula(individu, period): - previous_year = Period('year', period.start).offset(-1) + previous_year = Period(('year', period.start)).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) @@ -29,7 +29,7 @@ class rente_accident_travail_salarie(Variable): set_input = set_input_divide_by_period def formula(individu, period): - previous_year = Period('year', period.start).offset(-1) + previous_year = Period(('year', period.start)).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) @@ -54,7 +54,7 @@ class rente_accident_travail_exploitant_agricole(Variable): set_input = set_input_divide_by_period def formula(individu, period): - previous_year = Period('year', period.start).offset(-1) + previous_year = Period(('year', period.start)).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) @@ -182,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('year', period.start).offset(-1) + previous_year = Period(('year', period.start)).offset(-1) rente_at = parameters(period).prestations_sociales.solidarite_insertion.minima_sociaux.accident_travail.rente salaire_net = individu('salaire_net', previous_year, options=[ADD]) From bfa4a11da5b6441d79a90356a59b3d1427f41334 Mon Sep 17 00:00:00 2001 From: Emmanuel Raviart Date: Tue, 20 Dec 2022 16:56:05 +0100 Subject: [PATCH 3/6] Typo --- openfisca_france/model/prestations/agepi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openfisca_france/model/prestations/agepi.py b/openfisca_france/model/prestations/agepi.py index c2d4a3dd1d..8af9bd7ea6 100644 --- a/openfisca_france/model/prestations/agepi.py +++ b/openfisca_france/model/prestations/agepi.py @@ -85,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(('year', period.start).offset(-1).offset(-1, 'month') + annee_glissante = Period(('year', period.start)).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é" From 6f48f76b92a41262b5ba997dbcddd9cb8972b136 Mon Sep 17 00:00:00 2001 From: Emmanuel Raviart Date: Tue, 20 Dec 2022 17:10:23 +0100 Subject: [PATCH 4/6] Ensure that Period tuple argument is always a triple --- .../taxe_habitation/taxe_habitation.py | 2 +- openfisca_france/model/prestations/agepi.py | 2 +- openfisca_france/model/prestations/aide_mobilite.py | 2 +- openfisca_france/model/prestations/aides_logement.py | 2 +- openfisca_france/model/prestations/autonomie.py | 8 ++++---- .../prestations/jeunes/contrat_engagement_jeune.py | 4 ++-- openfisca_france/model/prestations/logement_social.py | 2 +- .../model/prestations/minima_sociaux/aah.py | 2 +- .../model/prestations/minima_sociaux/asi_aspa.py | 2 +- .../model/prestations/minima_sociaux/ass.py | 10 +++++----- .../model/prestations/minima_sociaux/cs/eligibilite.py | 2 +- .../model/prestations/minima_sociaux/cs/ressources.py | 4 ++-- .../model/prestations/prestations_familiales/ars.py | 4 ++-- openfisca_france/model/revenus/activite/salarie.py | 6 +++--- .../revenus/remplacement/rente_accident_travail.py | 8 ++++---- 15 files changed, 30 insertions(+), 30 deletions(-) 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 025d552c48..2f6e32c41d 100644 --- a/openfisca_france/model/prelevements_obligatoires/taxe_habitation/taxe_habitation.py +++ b/openfisca_france/model/prelevements_obligatoires/taxe_habitation/taxe_habitation.py @@ -335,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(('year', period.start.offset('first-of', '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 8af9bd7ea6..ef3a1ac84b 100644 --- a/openfisca_france/model/prestations/agepi.py +++ b/openfisca_france/model/prestations/agepi.py @@ -85,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(('year', period.start)).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 fcf618c891..63f0e6f671 100644 --- a/openfisca_france/model/prestations/aide_mobilite.py +++ b/openfisca_france/model/prestations/aide_mobilite.py @@ -329,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(('year', period.start)).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_logement.py b/openfisca_france/model/prestations/aides_logement.py index 9d6e24d437..a357421a11 100644 --- a/openfisca_france/model/prestations/aides_logement.py +++ b/openfisca_france/model/prestations/aides_logement.py @@ -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(('year', period.start)).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 f1e0dd25d3..c5833d397b 100644 --- a/openfisca_france/model/prestations/autonomie.py +++ b/openfisca_france/model/prestations/autonomie.py @@ -135,7 +135,7 @@ class apa_eligibilite(Variable): set_input = set_input_dispatch_by_period def formula_2002(individu, period, parameters): - period = Period(('month', period.start.offset('first-of', '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 @@ -174,7 +174,7 @@ class apa_domicile(Variable): set_input = set_input_divide_by_period def formula_2002(individu, period, parameters): - period = Period(('month', period.start.offset('first-of', '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 @@ -195,7 +195,7 @@ class apa_etablissement(Variable): set_input = set_input_divide_by_period def formula_2002(individu, period, parameters): - period = Period(('month', period.start.offset('first-of', '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 @@ -352,7 +352,7 @@ class apa_urgence_institution(Variable): set_input = set_input_divide_by_period def formula_2002(individu, period, parameters): - period = Period(('month', period.start.offset('first-of', '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 d648e2279c..73e31c8a69 100644 --- a/openfisca_france/model/prestations/jeunes/contrat_engagement_jeune.py +++ b/openfisca_france/model/prestations/jeunes/contrat_engagement_jeune.py @@ -19,7 +19,7 @@ def formula_2022_03_01(individu, period, parameters): montant_degressivite = parameters(period).prestations_sociales.aides_jeunes.contrat_engagement_jeune.degressivite.montant age = individu('age', period) majeur = individu('majeur', period) - previous_year = Period(('year', period.start)).offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) tranche = individu.foyer_fiscal('ir_tranche', previous_year) degressivite = majeur * (tranche > 0) * montant_degressivite @@ -93,7 +93,7 @@ def formula_2022_03_01(individu, period, parameters): niveau_ressources = (niveau_ressources_individuelles_3_mois) / 3 - previous_year = Period(('year', period.start)).offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) tranche = individu.foyer_fiscal('ir_tranche', previous_year) <= 1 return (niveau_ressources <= plafond) * sans_rsa * sans_ppa * tranche diff --git a/openfisca_france/model/prestations/logement_social.py b/openfisca_france/model/prestations/logement_social.py index c8a5668854..1049300e17 100644 --- a/openfisca_france/model/prestations/logement_social.py +++ b/openfisca_france/model/prestations/logement_social.py @@ -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(('year', period.start.offset('first-of', '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 5b2164d3cd..3c71cfdfba 100644 --- a/openfisca_france/model/prestations/minima_sociaux/aah.py +++ b/openfisca_france/model/prestations/minima_sociaux/aah.py @@ -566,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(('year', period.start)).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) diff --git a/openfisca_france/model/prestations/minima_sociaux/asi_aspa.py b/openfisca_france/model/prestations/minima_sociaux/asi_aspa.py index 240a141426..44f675b56e 100644 --- a/openfisca_france/model/prestations/minima_sociaux/asi_aspa.py +++ b/openfisca_france/model/prestations/minima_sociaux/asi_aspa.py @@ -149,7 +149,7 @@ class asi_eligibilite(Variable): set_input = set_input_dispatch_by_period def formula(individu, period): - last_month = Period(('month', period.start)).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 88062b21b9..faa8b74ae1 100644 --- a/openfisca_france/model/prestations/minima_sociaux/ass.py +++ b/openfisca_france/model/prestations/minima_sociaux/ass.py @@ -81,7 +81,7 @@ class ass_base_ressources_individu(Variable): def formula(individu, period, parameters): # Rolling year - previous_year = Period(('year', period.start)).offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) # N-1 last_year = period.last_year @@ -132,9 +132,9 @@ class ass_base_ressources_conjoint(Variable): def formula(individu, period, parameters): # Rolling year - previous_year = Period(('year', period.start)).offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) - last_month = Period(('month', period.start)).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 @@ -149,14 +149,14 @@ def formula(individu, period, parameters): def calculateWithAbatement(individu, parameters, period, ressourceName): - last_month = Period(('month', period.start)).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(('year', period.start)).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 8d27e4413f..6903afb120 100644 --- a/openfisca_france/model/prestations/minima_sociaux/cs/eligibilite.py +++ b/openfisca_france/model/prestations/minima_sociaux/cs/eligibilite.py @@ -13,7 +13,7 @@ class css_cmu_acs_eligibilite(Variable): set_input = set_input_dispatch_by_period def formula(famille, period, parameters): - previous_year = Period(('year', period.start)).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 7f30c386f0..6699e6ead0 100644 --- a/openfisca_france/model/prestations/minima_sociaux/cs/ressources.py +++ b/openfisca_france/model/prestations/minima_sociaux/cs/ressources.py @@ -31,7 +31,7 @@ class css_cmu_base_ressources_individu(Variable): def formula(individu, period, parameters): # Rolling year - previous_year = Period(('year', period.start)).offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) # N-1 last_year = period.last_year last_month = period.last_month @@ -95,7 +95,7 @@ class css_cmu_base_ressources(Variable): set_input = set_input_divide_by_period def formula(famille, period, parameters): - previous_year = Period(('year', period.start)).offset(-1) + previous_year = Period(('year', period.start, 1)).offset(-1) ressources_famille_a_inclure = [ 'af', diff --git a/openfisca_france/model/prestations/prestations_familiales/ars.py b/openfisca_france/model/prestations/prestations_familiales/ars.py index d5c92551fa..4cd2943b70 100644 --- a/openfisca_france/model/prestations/prestations_familiales/ars.py +++ b/openfisca_france/model/prestations/prestations_familiales/ars.py @@ -18,8 +18,8 @@ def formula(famille, period, parameters): Allocation de rentrée scolaire brute de CRDS ''' janvier = period.first_month - octobre = Period(('month', period.start.offset('first-of', 'year').offset(9, 'month'))) - decembre = Period(('month', period.start.offset('first-of', 'year').offset(11, '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/revenus/activite/salarie.py b/openfisca_france/model/revenus/activite/salarie.py index 7e0f061dd5..3a7d5f8cf0 100644 --- a/openfisca_france/model/revenus/activite/salarie.py +++ b/openfisca_france/model/revenus/activite/salarie.py @@ -720,7 +720,7 @@ class ppv_eligibilite_exceptionnelle(Variable): ''' def formula_2022_07_01(individu, period, parameters): - annee_glissante = Period(('year', period.start)).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 @@ -817,7 +817,7 @@ def formula_2019_01_01(individu, period, parameters): sinon Pas d'exonération ''' - annee_glissante = Period(('year', period.start)).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 @@ -1249,7 +1249,7 @@ class indice_majore(Variable): set_input = set_input_dispatch_by_period def formula(individu, period, parameters): - period = Period(('month', period.start)).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 diff --git a/openfisca_france/model/revenus/remplacement/rente_accident_travail.py b/openfisca_france/model/revenus/remplacement/rente_accident_travail.py index 64417c061b..8768295662 100644 --- a/openfisca_france/model/revenus/remplacement/rente_accident_travail.py +++ b/openfisca_france/model/revenus/remplacement/rente_accident_travail.py @@ -12,7 +12,7 @@ class rente_accident_travail(Variable): set_input = set_input_divide_by_period def formula(individu, period): - previous_year = Period(('year', period.start)).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) @@ -29,7 +29,7 @@ class rente_accident_travail_salarie(Variable): set_input = set_input_divide_by_period def formula(individu, period): - previous_year = Period(('year', period.start)).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) @@ -54,7 +54,7 @@ class rente_accident_travail_exploitant_agricole(Variable): set_input = set_input_divide_by_period def formula(individu, period): - previous_year = Period(('year', period.start)).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) @@ -182,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(('year', period.start)).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]) From b9507cddc162c9f6f295a073e013a68865b443ec Mon Sep 17 00:00:00 2001 From: Emmanuel Raviart Date: Tue, 20 Dec 2022 17:19:36 +0100 Subject: [PATCH 5/6] Typo --- openfisca_france/model/prestations/logement_social.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openfisca_france/model/prestations/logement_social.py b/openfisca_france/model/prestations/logement_social.py index 1049300e17..6b04c9293a 100644 --- a/openfisca_france/model/prestations/logement_social.py +++ b/openfisca_france/model/prestations/logement_social.py @@ -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(('year', period.start.offset('first-of', 'year')), 1)) + 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) From cc5f99eb68aeca806bb29ad5f5c4007a781c8fcd Mon Sep 17 00:00:00 2001 From: Emmanuel Raviart Date: Thu, 2 Feb 2023 15:38:15 +0100 Subject: [PATCH 6/6] Corrige de nouveaux .period --- openfisca_france/model/prestations/minima_sociaux/aah.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openfisca_france/model/prestations/minima_sociaux/aah.py b/openfisca_france/model/prestations/minima_sociaux/aah.py index 3c71cfdfba..3c3ec5376c 100644 --- a/openfisca_france/model/prestations/minima_sociaux/aah.py +++ b/openfisca_france/model/prestations/minima_sociaux/aah.py @@ -194,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]) @@ -608,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