Repository: theOehrly/Fast-F1

Issue:
[BUG] Legacy plotting cannot handle RB
### Describe the issue:

The legacy `team_color` function throws a `KeyError` when `rb` is used as an input 

### Reproduce the code example:

```python
session = f.get_session(2024, "US Grand Prix", "R")

laps = session.laps.pick_wo_box().pick_track_status("467", how="none")

laps["LapTime (s)"] = laps["LapTime"].dt.total_seconds()
team_order = (
    laps[["Team", "LapTime (s)"]]
    .groupby("Team")
    .median(numeric_only=True)["LapTime (s)"]
    .sort_values()
    .index
)
team_palette = {team: p.team_color(team) for team in team_order}
```


### Error message:

```shell
File "/home/robery/Projects/Armchair-Strategist/f1_visualization/readme_machine.py", line 151, in main
    team_palette = {team: p.team_color(team) for team in team_order}
                          ^^^^^^^^^^^^^^^^^^
  File "/home/robery/Projects/Armchair-Strategist/env/lib/python3.12/site-packages/fastf1/plotting/_plotting.py", line 244, in team_color
    return LEGACY_TEAM_COLORS[LEGACY_TEAM_TRANSLATE[identifier.upper()]]
           ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'rb'
```



Discussion:
Values in `LEGACY_TEAM_TRANSLATE` are used as keys for `LEGACY_TEAM_COLORS` without checking:

```
return LEGACY_TEAM_COLORS[LEGACY_TEAM_TRANSLATE[identifier.upper()]]
```

There is no `rb` key in `LEGACY_TEAM_COLORS`:

```
LEGACY_TEAM_COLORS = {
    'mercedes': '#00d2be', 'ferrari': '#dc0000',
    'red bull': '#fcd700', 'mclaren': '#ff8700',
    'alpine': '#fe86bc', 'aston martin': '#006f62',
    'sauber': '#00e701', 'visa rb': '#1634cb',
    'haas': '#ffffff', 'williams': '#00a0dd'
}


LEGACY_TEAM_TRANSLATE: dict[str, str] = {
    'MER': 'mercedes',
    'FER': 'ferrari',
    'RBR': 'red bull',
    'MCL': 'mclaren',
    'APN': 'alpine',
    'AMR': 'aston martin',
    'SAU': 'sauber',
    'RB': 'rb',
    'HAA': 'haas',
    'WIL': 'williams'
}
```

Confirmed locally that this is the only change needed



Patch:
diff --git a/fastf1/plotting/__init__.py b/fastf1/plotting/__init__.py
index 1e6b6c568..9d1051feb 100644
--- a/fastf1/plotting/__init__.py
+++ b/fastf1/plotting/__init__.py
@@ -4,6 +4,8 @@
     LEGACY_DRIVER_COLORS as _LEGACY_DRIVER_COLORS
 from fastf1.plotting._constants import \
     LEGACY_DRIVER_TRANSLATE as _LEGACY_DRIVER_TRANSLATE
+from fastf1.plotting._constants import \
+    LEGACY_TEAM_COLORS as _LEGACY_TEAM_COLORS
 from fastf1.plotting._constants import \
     LEGACY_TEAM_TRANSLATE as _LEGACY_TEAM_TRANSLATE
 from fastf1.plotting._constants import Constants as _Constants
@@ -134,12 +136,7 @@ def __getattr__(name):
     future version. Use :func:`~fastf1.plotting.get_driver_name` instead.
 """
 
-_DEPR_TEAM_COLORS: dict[str, str] = {
-    # str(key.value): val for key, val
-    # in _Constants['2024'].Colormaps[_Colormaps.Default].items()
-    name.replace("kick ", ""): team.TeamColor.FastF1 for name, team
-    in _Constants['2024'].Teams.items()
-}
+_DEPR_TEAM_COLORS: dict[str, str] = _LEGACY_TEAM_COLORS.copy()
 TEAM_COLORS: dict[str, str]
 """
 Mapping of team names to team colors (hex color codes).
diff --git a/fastf1/plotting/_constants/__init__.py b/fastf1/plotting/_constants/__init__.py
index f79bf1aa2..c888de832 100644
--- a/fastf1/plotting/_constants/__init__.py
+++ b/fastf1/plotting/_constants/__init__.py
@@ -38,7 +38,7 @@
     'APN': 'alpine',
     'AMR': 'aston martin',
     'SAU': 'sauber',
-    'RB': 'rb',
+    'RB' : 'visa rb',
     'HAA': 'haas',
     'WIL': 'williams'
 }
diff --git a/fastf1/plotting/_plotting.py b/fastf1/plotting/_plotting.py
index 2256a15b5..be3976308 100644
--- a/fastf1/plotting/_plotting.py
+++ b/fastf1/plotting/_plotting.py
@@ -176,18 +176,23 @@ 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)):
+        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
             # 100) and that it has a minimum confidence (at least 20% better
             # than second best)
-            raise KeyError
+            raise KeyError(
+                f"Cannot find a good match for user input: {identifier}"
+            )
+
+        if key_ratios[0][0] != 100:
+            _logger.warning(
+                "Correcting invalid user input "
+                f"'{identifier}' to '{key_ratios[0][1]}'."
+            )
+
         best_matched_key = key_ratios[0][1]
         return LEGACY_DRIVER_COLORS[best_matched_key]
 
@@ -263,18 +268,22 @@ 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)):
+        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
             # 100) and that it has a minimum confidence (at least 20% better
             # than second best)
-            raise KeyError
+            raise KeyError(
+                f"Cannot find a good match for user input: {identifier}"
+            )
+
+        if key_ratios[0][0] != 100:
+            _logger.warning(
+                "Correcting invalid user input "
+                f"'{identifier}' to '{key_ratios[0][1]}'."
+            )
         best_matched_key = key_ratios[0][1]
         return LEGACY_TEAM_COLORS[best_matched_key]
 


Test patch:
diff --git a/fastf1/tests/test_plotting_deprecated.py b/fastf1/tests/test_plotting_deprecated.py
index 4beb77e96..9276e8c87 100644
--- a/fastf1/tests/test_plotting_deprecated.py
+++ b/fastf1/tests/test_plotting_deprecated.py
@@ -102,11 +102,20 @@ def test_driver_color():
 
 def test_team_color():
     with pytest.warns(FutureWarning, match="is deprecated"):
-        color = fastf1.plotting.team_color('ferrari')
+        color_ferrari = fastf1.plotting.team_color('ferrari')
 
-    assert color.startswith('#')
-    assert len(color) == 7
-    _ = int(color[1:], base=16)  # ensure that it's a valid hex color
+    assert color_ferrari.startswith('#')
+    assert len(color_ferrari) == 7
+    _ = int(color_ferrari[1:], base=16)  # ensure that it's a valid hex color
+
+    with pytest.warns(FutureWarning, match="is deprecated"):
+        color_visa = fastf1.plotting.team_color("visa")
+        color_rb = fastf1.plotting.team_color("rb")
+        color_visa_rb = fastf1.plotting.team_color("visa rb")
+        color_rbr = fastf1.plotting.team_color("RBR")
+    
+    assert color_visa == color_rb == color_visa_rb
+    assert color_visa_rb != color_rbr
 
 
 def test_lapnumber_axis():