From 22b832bb302a1d2293198b612755a75e70e5f3ae Mon Sep 17 00:00:00 2001 From: Nicolas Oudard Date: Wed, 11 Dec 2024 09:23:55 +0100 Subject: [PATCH] =?UTF-8?q?Correction=20des=20transformations=20quand=20la?= =?UTF-8?q?=20colonne=20origin=20et=20destination=20est=20la=20m=C3=AAme?= =?UTF-8?q?=20(#1126)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tasks/business_logic/source_data_normalize.py | 3 ++- .../business_logic/test_source_data_normalize.py | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/dags/sources/tasks/business_logic/source_data_normalize.py b/dags/sources/tasks/business_logic/source_data_normalize.py index d9434993f..140c5a80d 100755 --- a/dags/sources/tasks/business_logic/source_data_normalize.py +++ b/dags/sources/tasks/business_logic/source_data_normalize.py @@ -57,7 +57,8 @@ def source_data_normalize( df[transformation["destination"]] = df[transformation["origin"]].apply( TRANSFORMATION_MAPPING[function_name] ) - df.drop(columns=[transformation["origin"]], inplace=True) + if transformation["destination"] != transformation["origin"]: + df.drop(columns=[transformation["origin"]], inplace=True) # DEBUT Traitement des identifiants diff --git a/dags_unit_tests/sources/tasks/business_logic/test_source_data_normalize.py b/dags_unit_tests/sources/tasks/business_logic/test_source_data_normalize.py index 4c0e73d54..515afca44 100755 --- a/dags_unit_tests/sources/tasks/business_logic/test_source_data_normalize.py +++ b/dags_unit_tests/sources/tasks/business_logic/test_source_data_normalize.py @@ -263,7 +263,7 @@ class TestSourceDataNormalize: - [ ] test Suppresion des colonnes non voulues - [ ] test ignore_duplicates - [ ] test produitsdechets_acceptes vide ou None - - [ ] test transformation from column_transformations is called + - [x] test transformation from column_transformations is called """ @pytest.fixture @@ -523,7 +523,12 @@ def test_column_transformations_is_called(self, source_data_normalize_kwargs): "origin": "nom origin", "transformation": "test_fct", "destination": "nom destination", - } + }, + { + "origin": "nom", + "transformation": "test_fct", + "destination": "nom", + }, ] source_data_normalize_kwargs["df_acteur_from_source"] = pd.DataFrame( { @@ -532,7 +537,8 @@ def test_column_transformations_is_called(self, source_data_normalize_kwargs): "source_id": ["source_id1"], "acteur_type_id": ["decheterie"], "produitsdechets_acceptes": ["Plastic Box"], - "nom origin": ["nom"], + "nom origin": ["nom origin 1"], + "nom": ["nom"], } ) @@ -541,6 +547,9 @@ def test_column_transformations_is_called(self, source_data_normalize_kwargs): assert "nom destination" in df.columns assert df["nom destination"].iloc[0] == "success" + assert "nom" in df.columns + assert df["nom"].iloc[0] == "success" + class TestDfNormalizePharmacie: """