Describe the issue:
For the 2025 São Paulo GP, Bortoleto missed the qualifying session due to crashing in the sprint race.
The ergast (jolpica) data does not have an entry for Bortoleto, while the F1 API data does, which results in the TeamId being nan.
{'Abbreviation': 'BOR',
'BroadcastName': 'G BORTOLETO',
'ClassifiedPosition': '',
'CountryCode': '',
'DriverId': 'nan',
'DriverNumber': '5',
'FirstName': 'Gabriel',
'FullName': 'Gabriel Bortoleto',
'GridPosition': nan,
'HeadshotUrl': 'https://media.formula1.com/d_driver_fallback_image.png/content/dam/fom-website/drivers/G/GABBOR01_Gabriel_Bortoleto/gabbor01.png.transform/1col/image.png',
'Laps': nan,
'LastName': 'Bortoleto',
'Points': nan,
'Position': nan,
'Q1': NaT,
'Q2': NaT,
'Q3': NaT,
'Status': '',
'TeamColor': '01C00E',
'TeamId': 'nan',
'TeamName': 'Kick Sauber',
'Time': NaT}
Looking at the code, it seems like it's set up for the opposite scenario where the F1 API data would be missing the row.
Since TeamName is in the F1 API data, this could be fixed by taking the TeamId from the teammate's row.
if 'TeamId' in self._results and 'TeamName' in self._results:
# Build a mapping from drivers who have both TeamName (F1 API) and TeamId (Ergast) already populated
team_id_map = {}
for idx in self._results.index:
team_name = self._results.loc[idx, 'TeamName']
team_id = self._results.loc[idx, 'TeamId']
# Check for valid (non-NaN, non-'nan' string) values
if (pd.notna(team_name) and pd.notna(team_id) and str(team_id).lower() != 'nan'):
team_id_map[team_name] = team_id
# Apply the mapping to fill NaN/missing TeamId values
mask = ((self._results['TeamId'].isna()
| (self._results['TeamId'].astype(str).str.lower() == 'nan'))
& self._results['TeamName'].notna())
for idx in self._results[mask].index:
team_name = self._results.loc[idx, 'TeamName']
if team_name in team_id_map:
self._results.loc[idx, 'TeamId'] = team_id_map[team_name]
Reproduce the code example:
import fastf1
from pprint import pprint
# Reproduce: Bortoleto TeamId is NaN for 2025 São Paulo GP qualifying
# Reason: He's registered but didn't participate in the session
event = fastf1.get_event(2025, 21)
q = event.get_qualifying()
q.load()
# Check Bortoleto's data
bort = q.results[q.results['Abbreviation'] == 'BOR'].iloc[0]
pprint(bort.to_dict())
Error message:
Describe the issue:
For the 2025 São Paulo GP, Bortoleto missed the qualifying session due to crashing in the sprint race.
The ergast (jolpica) data does not have an entry for Bortoleto, while the F1 API data does, which results in the
TeamIdbeingnan.{'Abbreviation': 'BOR', 'BroadcastName': 'G BORTOLETO', 'ClassifiedPosition': '', 'CountryCode': '', 'DriverId': 'nan', 'DriverNumber': '5', 'FirstName': 'Gabriel', 'FullName': 'Gabriel Bortoleto', 'GridPosition': nan, 'HeadshotUrl': 'https://media.formula1.com/d_driver_fallback_image.png/content/dam/fom-website/drivers/G/GABBOR01_Gabriel_Bortoleto/gabbor01.png.transform/1col/image.png', 'Laps': nan, 'LastName': 'Bortoleto', 'Points': nan, 'Position': nan, 'Q1': NaT, 'Q2': NaT, 'Q3': NaT, 'Status': '', 'TeamColor': '01C00E', 'TeamId': 'nan', 'TeamName': 'Kick Sauber', 'Time': NaT}Looking at the code, it seems like it's set up for the opposite scenario where the F1 API data would be missing the row.
Since
TeamNameis in the F1 API data, this could be fixed by taking theTeamIdfrom the teammate's row.Reproduce the code example:
Error message: