Skip to content
Snippets Groups Projects
Commit a5af3c08 authored by clallemand's avatar clallemand
Browse files

Ajoute gestion des valeurs non communiqué dans les booléens

parent 1cacdce7
No related branches found
No related tags found
1 merge request!16Corrections data 2024
......@@ -11,7 +11,8 @@ from leximpact_dotations_back.mapping.valeurs_dgcl import (
DGCL_VALUE__NON_DISPONIBLE_BEFORE_2024,
DGCL_VALUE__NON_DISPONIBLE_2024,
DGCL_VALUE_STRING_TRUE_BEFORE_2024, DGCL_VALUE_STRING_TRUE_PATTERN_BEFORE_2024,
DGCL_VALUE_STRING_TRUE, DGCL_VALUE_STRING_FALSE
DGCL_VALUE_STRING_TRUE, DGCL_VALUE_STRING_FALSE,
DGCL_VALUE__NON_COMMUNIQUE
)
from leximpact_dotations_back.mapping.criteres_dgcl_2024 import ( # noqa: F401
colonnes_utiles_2024, # TODO avoid this variable name inference in 'adapt_criteres'
......@@ -301,9 +302,9 @@ def convert_cols_to_real_bool(data, bool_col_list, year):
# Toute année - Les colonnes qui contiennent soit 1 soit le code commune lorsque vrai
else:
data[col] = data[col].replace(DGCL_VALUE__NON_DISPONIBLE, DGCL_VALUE_STRING_FALSE).copy()
data[col] = data[col].replace("n.c", DGCL_VALUE_STRING_FALSE).copy()
data[col] = data[col].replace(DGCL_VALUE__NON_COMMUNIQUE, DGCL_VALUE_STRING_FALSE).copy()
data[col].replace(to_replace=r"^\d{5}$", value=DGCL_VALUE_STRING_TRUE, regex=True)
data[col] = data[col].astype(bool)
data[col] = data[col].astype(int).astype(bool)
# Les colonnes qui contiennent soit 0 ou 1 et de type int
else:
......@@ -432,6 +433,8 @@ def adapt_criteres(year: int, data: DataFrame, data_insee_communes_history: Data
montant_commune_eligible = colonnes_utiles["montant_commune_eligible"]
part_pfi = colonnes_utiles["part_pfi"]
extracolumns["dotation_globale_fonctionnement_reference_communes"] = colonnes_utiles["dotation_globale_fonctionnement_reference_communes"]
translation_cols = {**variables_openfisca_presentes_fichier, **extracolumns}
# TODO: check why data_cleanup.py applied format is lost on "montant_commune_eligible" and "part_pfi"
......@@ -464,13 +467,15 @@ def adapt_criteres(year: int, data: DataFrame, data_insee_communes_history: Data
# Passe les "booléens dgf" (oui/non) en booléens normaux
liste_columns_to_real_bool = [
"zone_de_montagne",
"insulaire",
"bureau_centralisateur",
"chef_lieu_arrondissement",
"chef_lieu_de_canton",
"chef_lieu_departement_dans_agglomeration",
"zrr",
"zone_de_montagne",
"insulaire",
"dotation_communes_nouvelles_eligible_part_amorcage",
"dotation_communes_nouvelles_eligible_part_garantie"
]
data = convert_cols_to_real_bool(data, liste_columns_to_real_bool, year)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment