diff --git a/fastf1/core.py b/fastf1/core.py index 7fbdde49d..4efcd9852 100644 --- a/fastf1/core.py +++ b/fastf1/core.py @@ -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') @@ -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!") @@ -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'] @@ -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 @@ -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'] @@ -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: @@ -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'] @@ -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()): @@ -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 diff --git a/fastf1/ergast/structure.py b/fastf1/ergast/structure.py index 9dbf455cb..5a6ed3224 100644 --- a/fastf1/ergast/structure.py +++ b/fastf1/ergast/structure.py @@ -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)) diff --git a/fastf1/livetiming/data.py b/fastf1/livetiming/data.py index e09e5508d..ab2ed3ebf 100644 --- a/fastf1/livetiming/data.py +++ b/fastf1/livetiming/data.py @@ -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): @@ -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': [] diff --git a/fastf1/plotting.py b/fastf1/plotting.py index 6b515dcf9..8d3293de8 100644 --- a/fastf1/plotting.py +++ b/fastf1/plotting.py @@ -45,8 +45,6 @@ "Plotting of timedelta values will be restricted!", UserWarning) -import warnings - with warnings.catch_warnings(): warnings.filterwarnings('ignore', @@ -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)