From 53a1e7468096767016b7f29614b9d0b467f61aff Mon Sep 17 00:00:00 2001 From: Casper Guo Date: Fri, 19 Apr 2024 18:06:08 -0400 Subject: [PATCH 1/2] Add warnings to users when identifier is fuzzy matched --- fastf1/plotting.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fastf1/plotting.py b/fastf1/plotting.py index 8d3293de8..2e958a96e 100644 --- a/fastf1/plotting.py +++ b/fastf1/plotting.py @@ -30,6 +30,8 @@ import numpy as np import pandas as pd +from fastf1.logger import get_logger + try: import matplotlib @@ -45,6 +47,7 @@ "Plotting of timedelta values will be restricted!", UserWarning) +_logger = get_logger(__name__) with warnings.catch_warnings(): warnings.filterwarnings('ignore', @@ -286,6 +289,12 @@ def driver_color(identifier: str) -> str: ratio = fuzz.ratio(identifier, existing_key) key_ratios.append((ratio, existing_key)) key_ratios.sort(reverse=True) + if key_ratios[0][0] != 100: + _logger.warning( + ("Correcting invalid user input " + f"{identifier} to {key_ratios[0][1]}." + ) + ) if ((key_ratios[0][0] < 35) or (key_ratios[0][0] / key_ratios[1][0] < 1.2)): # ensure that the best match has a minimum accuracy (35 out of @@ -361,6 +370,12 @@ def team_color(identifier: str) -> str: ratio = fuzz.ratio(identifier, existing_key) key_ratios.append((ratio, existing_key)) key_ratios.sort(reverse=True) + if key_ratios[0][0] != 100: + _logger.warning( + ("Correcting invalid user input " + f"{identifier} to {key_ratios[0][1]}." + ) + ) if ((key_ratios[0][0] < 35) or (key_ratios[0][0] / key_ratios[1][0] < 1.2)): # ensure that the best match has a minimum accuracy (35 out of From 0ae361bb282b5c31260d62872220d53072bfc367 Mon Sep 17 00:00:00 2001 From: Casper Guo Date: Sat, 20 Apr 2024 15:17:53 -0400 Subject: [PATCH 2/2] Reformat warning string --- fastf1/plotting.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fastf1/plotting.py b/fastf1/plotting.py index 2e958a96e..414198222 100644 --- a/fastf1/plotting.py +++ b/fastf1/plotting.py @@ -292,7 +292,7 @@ def driver_color(identifier: str) -> str: if key_ratios[0][0] != 100: _logger.warning( ("Correcting invalid user input " - f"{identifier} to {key_ratios[0][1]}." + f"'{identifier}' to '{key_ratios[0][1]}'." ) ) if ((key_ratios[0][0] < 35) @@ -373,7 +373,7 @@ def team_color(identifier: str) -> str: if key_ratios[0][0] != 100: _logger.warning( ("Correcting invalid user input " - f"{identifier} to {key_ratios[0][1]}." + f"'{identifier}' to '{key_ratios[0][1]}'." ) ) if ((key_ratios[0][0] < 35)