theOehrly / Fast-F1

FastF1 is a python package for accessing and analyzing Formula 1 results, schedules, timing data and telemetry
https://docs.fastf1.dev
MIT License
2.29k stars 239 forks source link

[BUG] Unable to load Saudi Arabia session after successful prior load #555

Closed flipjj closed 3 months ago

flipjj commented 3 months ago

Describe the issue:

Trying to load the Saudi race data again (forgot to run something) and now it is throwing an error on load. I did load it after the race. There was an issue with early laps, but otherwise everything ran perfectly.

The other day, tried running it again and it has been throwing an error on load and I cannot get past it. Stupidly, I deleted the cache and when I went looking for it, the bin was cleared already, so no help there.

All other weekend sessions load without an issue, all Bahrain sessions load without issue, and all other sessions with Bearman in them (my first thought) run OK as well.

Reproduce the code example:

races = 'Australia'
year = 2023
sessions = 'Race'

sesh.load(laps=True, telemetry=True, weather=True, messages=True, livedata=None)

Error message:

KeyError                                  Traceback (most recent call last)
Cell In[7], line 13
     11 sesh = ff1.get_session(year, races, sessions)
     12 # sesh.api_path = '/static/2024/2024-03-09_Saudi_Arabian_Grand_Prix/2024-03-09_Race'
---> 13 sesh.load(laps=True, telemetry=True, weather=True, messages=True, livedata=None)

File D:\Anaconda\anaconda3\lib\site-packages\fastf1\core.py:1415, in Session.load(self, laps, telemetry, weather, messages, livedata)
   1410 _logger.info(f"Loading data for "
   1411              f"{self.event['EventName']} - {self.name}"
   1412              f" [v{fastf1.__version__}]")
   1414 self._load_session_info(livedata=livedata)
-> 1415 self._load_drivers_results(livedata=livedata)
   1417 if self.f1_api_support:
   1418     if laps:

File D:\Anaconda\anaconda3\lib\site-packages\fastf1\core.py:2146, in Session._load_drivers_results(self, livedata)
   2142 # try loading from both sources if they are supported
   2143 # data is joined afterwards depending on availability
   2144 if self.f1_api_support:
   2145     # load driver info from f1 api
-> 2146     driver_info_f1 = self._drivers_from_f1_api(livedata=livedata)
   2147 if not self.event.is_testing():
   2148     # load driver info from ergast
   2149     driver_info_ergast = self._drivers_results_from_ergast(
   2150         load_drivers=True, load_results=True
   2151     )

File D:\Anaconda\anaconda3\lib\site-packages\fastf1\core.py:2230, in Session._drivers_from_f1_api(self, livedata)
   2227         for first, last in zip(driver_info['FirstName'],
   2228                                driver_info['LastName']):
   2229             driver_info['FullName'].append(f"{first} {last}")
-> 2230 return pd.DataFrame(driver_info, index=driver_info['DriverNumber'])

KeyError: 'DriverNumber'
Casper-Guo commented 3 months ago

You mention the Saudi Arabia race but your provided code segment is loading the Australia GP. Is that a mistake?

Also just to sanity check, what version of Fastf1 are you using?

Just running what you supplied here. I couldn't reproduce the error.

flipjj commented 3 months ago

Crap. I have the latest one, upgrading was the first thing I tried, and the code is for Saudi, yeah, just pasted after working onustralia 2023, sorry.

I will reinstall everything and see what happens, if you tried to recreate it and it worked.

Thank you, friend.

Casper-Guo commented 3 months ago

No problem. I will definitely recommend retrying in a virtual environment. I just tried loading Saudi data in a clean environment and it worked without an issue so hopefully that resolves your problem as well.

flipjj commented 3 months ago

Thank you, Casper, Guo.

Reinstalled everything and we are back in business. Took some time, but problem solved.