From 3c7050892607306c9c9c050795dbe8a8ec309a5d Mon Sep 17 00:00:00 2001 From: rjambrecic <32619626+rjambrecic@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:41:08 +0100 Subject: [PATCH] Fix sheet category merge to be case insensitive (#173) --- google_sheets/app.py | 7 +++++++ google_sheets/data_processing/processing.py | 2 +- tests/app/test_app.py | 20 ++++++++------------ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/google_sheets/app.py b/google_sheets/app.py index 94193a7..410b54f 100644 --- a/google_sheets/app.py +++ b/google_sheets/app.py @@ -474,6 +474,13 @@ async def process_data( status_code=status.HTTP_400_BAD_REQUEST, detail=validation_error_msg ) + template_df["Category"] = template_df["Category"].str.lower() + new_campaign_df["Category"] = new_campaign_df["Category"].str.lower() + for col in ["Ad Group Category", "Real Category"]: + merged_campaigns_ad_groups_df[col] = merged_campaigns_ad_groups_df[ + col + ].str.lower() + processed_df = process_data_f( merged_campaigns_ad_groups_df, template_df, diff --git a/google_sheets/data_processing/processing.py b/google_sheets/data_processing/processing.py index 362d5a9..6520deb 100644 --- a/google_sheets/data_processing/processing.py +++ b/google_sheets/data_processing/processing.py @@ -191,7 +191,7 @@ def _replace_headline_values(new_row: pd.Series, station: Dict[str, Any]) -> pd. return new_row -USE_ORIGINAL_STATION_FROM = ["Transfer", "Taxi"] +USE_ORIGINAL_STATION_FROM = ["transfer", "taxi"] def _process_row( diff --git a/tests/app/test_app.py b/tests/app/test_app.py index 5669b38..53f09ee 100644 --- a/tests/app/test_app.py +++ b/tests/app/test_app.py @@ -358,8 +358,8 @@ class TestProcessData: ( GoogleSheetValues( values=[ - ["Fake column"], - ["fake"], + ["Fake column", "Category"], + ["fake", "Bus"], ] ), GoogleSheetValues( @@ -371,6 +371,7 @@ class TestProcessData: "Final Url From", "Final Url To", "Language Code", + "Category", ], [ "India", @@ -379,6 +380,7 @@ class TestProcessData: "https://www.example.com/from", "https://www.example.com/to", "EN", + "Bus", ], ] ), @@ -394,8 +396,6 @@ class TestProcessData: "Negative", "Language Code", "Category", - "Ad Group Category", - "Real Category", ], [ "Keyword A", @@ -404,8 +404,6 @@ class TestProcessData: "False", "EN", "Bus", - "Bus", - "Bus", ], [ "Keyword N", @@ -414,8 +412,6 @@ class TestProcessData: "True", "EN", "Bus", - "Bus", - "Bus", ], ] ), @@ -498,6 +494,8 @@ async def test_process_data_keywords( "Ad Group Name": ["{INSERT_STATION_FROM} - {INSERT_STATION_TO}"], "Match Type": ["Exact"], "Target Category": ["True"], + "Ad Group Category": ["Bus"], + "Real Category": ["Bus"], } ) if isinstance(detail, GoogleSheetValues): @@ -535,8 +533,6 @@ async def test_process_data_ads(self) -> None: "Path 1", "Path 2", "Match Type", - "Ad Group Category", - "Real Category", ], [ "EN", @@ -550,8 +546,6 @@ async def test_process_data_ads(self) -> None: "Path 1", "Path 2", "Exact", - "Bus", - "Bus", ], ] ) @@ -588,6 +582,8 @@ async def test_process_data_ads(self) -> None: "Ad Group Name": ["{INSERT_STATION_FROM} - {INSERT_STATION_TO}"], "Match Type": ["Exact"], "Target Category": ["False"], + "Ad Group Category": ["bus"], + "Real Category": ["bus"], } ) result = await process_data(