Skip to content

Commit

Permalink
CLN: remove unused D_LOOKUP table, code style, exceptions not raised (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Casper-Guo authored Mar 5, 2024
1 parent d1868e9 commit b8f755e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 30 deletions.
34 changes: 11 additions & 23 deletions fastf1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,6 @@

_logger = get_logger(__name__)

D_LOOKUP: List[List] = \
[[44, 'HAM', 'Mercedes'], [77, 'BOT', 'Mercedes'],
[55, 'SAI', 'Ferrari'], [16, 'LEC', 'Ferrari'],
[33, 'VER', 'Red Bull'], [11, 'PER', 'Red Bull'],
[3, 'RIC', 'McLaren'], [4, 'NOR', 'McLaren'],
[5, 'VET', 'Aston Martin'], [18, 'STR', 'Aston Martin'],
[14, 'ALO', 'Alpine'], [31, 'OCO', 'Alpine'],
[22, 'TSU', 'AlphaTauri'], [10, 'GAS', 'AlphaTauri'],
[47, 'MSC', 'Haas F1 Team'], [9, 'MAZ', 'Haas F1 Team'],
[7, 'RAI', 'Alfa Romeo'], [99, 'GIO', 'Alfa Romeo'],
[6, 'LAT', 'Williams'], [63, 'RUS', 'Williams']]

_RACE_LIKE_SESSIONS = ('Race', 'Sprint', 'Sprint Qualifying')
_QUALI_LIKE_SESSIONS = ('Qualifying', 'Sprint Shootout')

Expand Down Expand Up @@ -324,8 +312,8 @@ def slice_by_lap(
"""
if isinstance(ref_laps, Laps) and len(ref_laps) > 1:
if 'DriverNumber' not in ref_laps.columns:
ValueError("Laps is missing 'DriverNumber'. Cannot return "
"telemetry for unknown driver.")
raise ValueError("Laps is missing 'DriverNumber'. "
"Cannot return telemetry for unknown driver.")
if not len(ref_laps['DriverNumber'].unique()) <= 1:
raise ValueError("Cannot create telemetry for multiple "
"drivers at once!")
Expand All @@ -337,8 +325,8 @@ def slice_by_lap(
if isinstance(ref_laps, Laps): # one lap in Laps
ref_laps = ref_laps.iloc[0] # handle as a single lap
if 'DriverNumber' not in ref_laps.index:
ValueError("Lap is missing 'DriverNumber'. Cannot return "
"telemetry for unknown driver.")
raise ValueError("Lap is missing 'DriverNumber'. "
"Cannot return telemetry for unknown driver.")
end_time = ref_laps['Time']
start_time = ref_laps['LapStartTime']

Expand Down Expand Up @@ -462,7 +450,7 @@ def merge_channels(
dtype_map = dict()
for df in data, other:
for col in df.columns:
if col not in dtype_map.keys():
if col not in dtype_map:
dtype_map[col] = df[col].dtype

# Exclude columns existing on both dataframes from one dataframe
Expand Down Expand Up @@ -504,7 +492,7 @@ def merge_channels(

resampled_columns = dict()

for ch in self._CHANNELS.keys():
for ch in self._CHANNELS:
if ch not in merged.columns:
continue
sig_type = self._CHANNELS[ch]['type']
Expand Down Expand Up @@ -569,7 +557,7 @@ def merge_channels(
= merged['SessionTime'] - merged['SessionTime'].iloc[0]

# restore data types from before merging
for col in dtype_map.keys():
for col in dtype_map:
try:
merged[col] = merged.loc[:, col].astype(dtype_map[col])
except ValueError:
Expand Down Expand Up @@ -643,12 +631,12 @@ def fill_missing(self):
registered custom channels. For example:
| Linear interpolation will be used for continuous values (Speed, RPM)
| Forward-fill will be used for discrete values (Gear, DRS, ...)
b
See :meth:`register_new_channel` for adding custom channels.
"""
ret = self.copy()

for ch in self._CHANNELS.keys():
for ch in self._CHANNELS:
if ch not in self.columns:
continue
sig_type = self._CHANNELS[ch]['type']
Expand Down Expand Up @@ -1487,7 +1475,7 @@ def _load_laps_data(self, livedata=None):
"list from timing data.")

df = None
for i, driver in enumerate(drivers):
for _, driver in enumerate(drivers):
d1 = data[data['Driver'] == driver]
d2 = useful[useful['Driver'] == driver]
if d2.shape[0] != len(d2['Stint'].unique()):
Expand Down Expand Up @@ -2077,7 +2065,7 @@ def _check_lap_accuracy(self):
if prev_lap is not None:
# first lap after safety car often has timing issues
# (as do all laps under safety car)
check_3 = (prev_lap['TrackStatus'] != '4')
check_3 = prev_lap['TrackStatus'] != '4'
else:
check_3 = True # no previous lap, no SC error

Expand Down
2 changes: 1 addition & 1 deletion fastf1/ergast/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def _merge_dicts_of_lists(data):
if len(data) <= 1:
return data[0]

for i in range(len(data) - 1):
for _ in range(len(data) - 1):
_tmp = data.pop(1)
for key in data[0].keys():
data[0][key].extend(_tmp.pop(key))
Expand Down
6 changes: 3 additions & 3 deletions fastf1/livetiming/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ def _add_to_category(self, cat, entry):

def _parse_session_data(self, msg):
# make sure the categories exist as we want to append to them
if 'TrackStatus' not in self.data.keys():
if 'TrackStatus' not in self.data:
self.data['TrackStatus'] = {'Time': [], 'Status': [],
'Message': []}
if 'SessionStatus' not in self.data.keys():
if 'SessionStatus' not in self.data:
self.data['SessionStatus'] = {'Time': [], 'Status': []}

if ('StatusSeries' in msg) and isinstance(msg['StatusSeries'], dict):
Expand Down Expand Up @@ -194,7 +194,7 @@ def _parse_session_data(self, msg):
self.data['SessionStatus']['Status'].append(entry['SessionStatus'])

def _parse_race_control_message(self, msg):
if 'RaceControlMessages' not in self.data.keys():
if 'RaceControlMessages' not in self.data:
self.data['RaceControlMessages'] = {
'Utc': [], 'Category': [], 'Message': [], 'Status': [],
'Flag': [], 'Scope': [], 'Sector': [], 'RacingNumber': []
Expand Down
4 changes: 1 addition & 3 deletions fastf1/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
"Plotting of timedelta values will be restricted!",
UserWarning)

import warnings


with warnings.catch_warnings():
warnings.filterwarnings('ignore',
Expand Down Expand Up @@ -284,7 +282,7 @@ def driver_color(identifier: str) -> str:

# do fuzzy string matching
key_ratios = list()
for existing_key in DRIVER_COLORS.keys():
for existing_key in DRIVER_COLORS:
ratio = fuzz.ratio(identifier, existing_key)
key_ratios.append((ratio, existing_key))
key_ratios.sort(reverse=True)
Expand Down

0 comments on commit b8f755e

Please sign in to comment.