Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 2022, 5 (Miami) Lap data #431

Closed
tmceld opened this issue Jul 31, 2023 · 7 comments
Closed

[BUG] 2022, 5 (Miami) Lap data #431

tmceld opened this issue Jul 31, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@tmceld
Copy link

tmceld commented Jul 31, 2023

Describe the issue:

version: 3.0.7

I'm not having difficulty with any other sessions (for 2022) Just this one

output of session.load()

core           INFO 	Loading data for Miami Grand Prix - Qualifying [v3.0.7]
req            INFO 	Using cached data for driver_info
req            INFO 	Using cached data for session_status_data
req            INFO 	Using cached data for track_status_data
req            INFO 	Updating cache for timing_data...
_api           INFO 	Fetching timing data...
_api           INFO 	Parsing timing data...
logger      WARNING 	Failed to load timing data!
req            INFO 	Using cached data for car_data
req            INFO 	Using cached data for position_data
req            INFO 	Using cached data for weather_data
req            INFO 	Using cached data for race_control_messages
core           INFO 	Finished loading data for 20 drivers: ['16', '55', '1', '11', '77', '44', '10', '4', '22', '18', '14', '63', '5', '3', '47', '20', '24', '23', '6', '31']

Reproduce the code example:

year=2022
rnd=5
session = fastf1.get_session(year, rnd, 'Q')
session.load()
print(session.event['EventName'])
session.laps

Error message:

DataNotLoadedError: The data you are trying to access has not been loaded yet. See `Session.load
@Casper-Guo
Copy link
Contributor

Working for me as of now:

import fastf1

session = fastf1.get_session(2022, 5, 'Q')
session.load(telemetry=False)
print(session)
print(session.laps.head())
2022 Season Round 5: Miami Grand Prix - Qualifying
                    Time Driver DriverNumber                LapTime  ...  Deleted  DeletedReason FastF1Generated IsAccurate
0 0 days 00:18:09.430000    LEC           16                    NaT  ...    False                          False      False
1 0 days 00:19:40.779000    LEC           16 0 days 00:01:31.349000  ...    False                          False      False
2 0 days 00:21:50.328000    LEC           16 0 days 00:02:09.549000  ...    False                          False      False
3 0 days 00:24:03.862000    LEC           16 0 days 00:02:13.534000  ...    False                          False      False
4 0 days 00:25:33.336000    LEC           16 0 days 00:01:29.474000  ...    False                          False      False

@tmceld
Copy link
Author

tmceld commented Aug 1, 2023

Working for me as of now:

Interesting. Still failing for me. Just tried without using the cache, and same result:


core           INFO 	Loading data for Miami Grand Prix - Qualifying [v3.0.7]
req            INFO 	No cached data found for driver_info. Loading data...
_api           INFO 	Fetching driver list...
req            INFO 	Data has been written to cache!
req            INFO 	No cached data found for session_status_data. Loading data...
_api           INFO 	Fetching session status data...
req            INFO 	Data has been written to cache!
req            INFO 	No cached data found for track_status_data. Loading data...
_api           INFO 	Fetching track status data...
req            INFO 	Data has been written to cache!
req            INFO 	No cached data found for timing_data. Loading data...
_api           INFO 	Fetching timing data...
_api           INFO 	Parsing timing data...
logger      WARNING 	Failed to load timing data!
req            INFO 	No cached data found for car_data. Loading data...
_api           INFO 	Fetching car data...
_api           INFO 	Parsing car data...
req            INFO 	Data has been written to cache!
req            INFO 	No cached data found for position_data. Loading data...
_api           INFO 	Fetching position data...
_api           INFO 	Parsing position data...
req            INFO 	Data has been written to cache!
req            INFO 	No cached data found for weather_data. Loading data...
_api           INFO 	Fetching weather data...
req            INFO 	Data has been written to cache!
req            INFO 	No cached data found for race_control_messages. Loading data...
_api           INFO 	Fetching race control messages...
req            INFO 	Data has been written to cache!
core           INFO 	Finished loading data for 20 drivers: ['16', '55', '1', '11', '77', '44', '10', '4', '22', '18', '14', '63', '5', '3', '47', '20', '24', '23', '6', '31']

@theOehrly
Copy link
Owner

Failing for me as well. I'll only get around to look at this in one or two weeks. Sorry for that.

@harningle
Copy link
Contributor

harningle commented Aug 1, 2023

I can reproduce this error in version 3.0.7. Seems related to #403 and 95d0186:

Fast-F1/fastf1/_api.py

Lines 440 to 448 in 95d0186

# Create approximate (sub)session (i.e. quali) split times by
# (mis)using the session number counter from 'BestLapTimes'.
# (Note: those lap times cannot be used for correct personal best
# detection, because the previous value is not resent here when a lap
# is deleted.)
if val := recursive_dict_get(resp, 'BestLapTimes'):
session_n = int(list(val.keys())[0])
if (session_n + 1) > len(session_split_times):
session_split_times.append(to_timedelta(time))

L445 wants to get the value of BestLapTimes, which itself is supposed to be dict, and thus L446 can call .keys(). However, in this particular qualifying, some value of BestLapTimes is a list rather than a dict.

Below are one working example of resp and one example that causes the error here:

{'Stats': {'0': {'TimeDiffToFastest': '+1.850', 'TimeDifftoPositionAhead': '+0.036'}}, 'BestLapTimes': {'0': {'Value': '1:32.085', 'Lap': 4}}, 'Line': 13, 'Position': '13', 'NumberOfLaps': 5, 'Sectors': {'2': {'Value': '25.934'}}, 'Speeds': {'FL': {'Value': '284'}}, 'BestLapTime': {'Value': '1:32.085', 'Lap': 4}, 'LastLapTime': {'Value': '1:32.085', 'PersonalFastest': True}}
{'BestLapTimes': {'0': {'Value': '1:31.647', 'Lap': 7}}, 'NumberOfLaps': 8, 'BestLapTime': {'Value': '1:31.647', 'Lap': 7}, 'LastLapTime': {'Value': '1:31.647', 'PersonalFastest': True}}
{'BestLapTimes': {'0': {'Value': '1:31.325', 'Lap': 9}}, 'NumberOfLaps': 10, 'BestLapTime': {'Value': '1:31.325', 'Lap': 9}, 'LastLapTime': {'Value': '1:31.325', 'PersonalFastest': True}}
{'Stats': [{'TimeDiffToFastest': '', 'TimeDifftoPositionAhead': ''}, {'TimeDiffToFastest': '', 'TimeDifftoPositionAhead': ''}, {'TimeDiffToFastest': '', 'TimeDifftoPositionAhead': ''}], 'KnockedOut': False, 'Cutoff': True, 'BestLapTimes': [{'Value': ''}, {}, {}], 'Line': 20, 'Position': '20', 'ShowPosition': False, 'RacingNumber': '31', 'Retired': False, 'InPit': True, 'PitOut': False, 'Stopped': False, 'Status': 272, 'Sectors': [{'Stopped': False, 'Value': '', 'Status': 0, 'OverallFastest': False, 'PersonalFastest': False}, {'Stopped': False, 'Value': '', 'Status': 0, 'OverallFastest': False, 'PersonalFastest': False}, {'Stopped': False, 'Value': '', 'Status': 0, 'OverallFastest': False, 'PersonalFastest': False}], 'Speeds': {'I1': {'Value': '', 'Status': 0, 'OverallFastest': False, 'PersonalFastest': False}, 'I2': {'Value': '', 'Status': 0, 'OverallFastest': False, 'PersonalFastest': False}, 'FL': {'Value': '', 'Status': 0, 'OverallFastest': False, 'PersonalFastest': False}, 'ST': {'Value': '', 'Status': 0, 'OverallFastest': False, 'PersonalFastest': False}}, 'BestLapTime': {'Value': ''}, 'LastLapTime': {'Value': '', 'Status': 0, 'OverallFastest': False, 'PersonalFastest': True}}

I don't know if this is the only case where L445-46 fail. If so, a dirty workaround would be checking val == [{'Value': ''}, {}, {}]

@tmceld
Copy link
Author

tmceld commented Aug 1, 2023

I don't know if this is the only case where L445-46 fail. If so, a dirty workaround would be checking val == [{'Value': ''}, {}, {}]

This is great, many thanks:

For anyone else having this problem, i edited line 445 of:
/Users/tmceld/opt/anaconda3/envs/base2/lib/python3.10/site-packages/fastf1/_api.py
to read:

          #if val := recursive_dict_get(resp, 'BestLapTimes'):
          if val == [{'Value': ''}, {}, {}]:
              session_n = int(list(val.keys())[0])
             if (session_n + 1) > len(session_split_times):

And i get a dataframe back, so can continue - many thanks.

@harningle
Copy link
Contributor

For anyone else having this problem, i edited line 445 of: /Users/tmceld/opt/anaconda3/envs/base2/lib/python3.10/site-packages/fastf1/_api.py to read:

          #if val := recursive_dict_get(resp, 'BestLapTimes'):
          if val == [{'Value': ''}, {}, {}]:
              session_n = int(list(val.keys())[0])
             if (session_n + 1) > len(session_split_times):

And i get a dataframe back, so can continue - many thanks.

Sorry I didn't make myself clear. We should always let the code run, unless val equals [{'Value': ''}, {}, {}]. So I guess the change is going to be:

        if val := recursive_dict_get(resp, 'BestLapTimes'):
            if val != [{'Value': ''}, {}, {}]:
                session_n = int(list(val.keys())[0])
                if (session_n + 1) > len(session_split_times):
                    session_split_times.append(to_timedelta(time))

This dirty fix may break stuff mentioned in #403. But as long as you are not working with fastest laps, it should be fine.

@theOehrly theOehrly added the bug Something isn't working label Aug 28, 2023
@theOehrly
Copy link
Owner

Sorry that this took quite a bit longer than the predicted 1-2 weeks, even though it wasn't very difficult to fix in the end.
Also, thanks @harningle for already analysing the issue in detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants