theOehrly/Fast-F1

[BUG] Miami Sprint Qualifying: failure in quali results

Closed this issue · 5 comments

Describe the issue:

Every time I load the session this error appears on my computer. Hopefully fastf1 is managing the error properly and it does not affect in my case.

TypeError: bad operand type for unary ~: 'NoneType'

I attach the complete error below:

Thanks

Reproduce the code example:

2024-05-04 00:14:46,448 - fastf1.fastf1.core - DEBUG - Traceback for failure in quali results
Traceback (most recent call last):
  File 	  .venv\Lib\site-packages\fastf1\logger.py", line 151, in __wrapped
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File 	  .venv\Lib\site-packages\fastf1\core.py", line 1861, in _calculate_quali_like_session_results
    session[~session['LapTime'].isna() & ~session['Deleted']]
                                         ^^^^^^^^^^^^^^^^^^^
  File 	  .venv\Lib\site-packages\pandas\core\generic.py", line 1570, in __invert__
    new_data = self._mgr.apply(operator.invert)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File 	  .venv\Lib\site-packages\pandas\core\internals\managers.py", line 362, in apply
    applied = b.apply(f, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^
  File 	  .venv\Lib\site-packages\pandas\core\internals\blocks.py", line 393, in apply
    result = func(self.values, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: bad operand type for unary ~: 'NoneType'

Error message:

2024-05-04 00:14:46,448 - fastf1.fastf1.core - DEBUG - Traceback for failure in quali results
Traceback (most recent call last):
  File 	  .venv\Lib\site-packages\fastf1\logger.py", line 151, in __wrapped
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File 	  .venv\Lib\site-packages\fastf1\core.py", line 1861, in _calculate_quali_like_session_results
    session[~session['LapTime'].isna() & ~session['Deleted']]
                                         ^^^^^^^^^^^^^^^^^^^
  File 	  .venv\Lib\site-packages\pandas\core\generic.py", line 1570, in __invert__
    new_data = self._mgr.apply(operator.invert)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File 	  .venv\Lib\site-packages\pandas\core\internals\managers.py", line 362, in apply
    applied = b.apply(f, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^
  File 	  .venv\Lib\site-packages\pandas\core\internals\blocks.py", line 393, in apply
    result = func(self.values, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: bad operand type for unary ~: 'NoneType'

Please ensure that you are using the newest version of FastF1. It contains some required bug fixes to support this years modified sprint weekend format.

If this does not fix the problem, please post the full output as well as a short snippet of code that allows me to reproduce the problem.

I'm using version 3.3.5 which is the lastest, I have deleted the cache but error persists

Code
import fastf1 as ff1
session = ff1.get_session(2024, 'Miami', 'SQ')
session.load(laps=True, telemetry=False, weather=False, messages=False, livedata=None)

Error
core INFO Loading data for Miami Grand Prix - Sprint Qualifying [v3.3.5]
2024-05-04 11:55:56,997 - fastf1.fastf1.core - INFO - Loading data for Miami Grand Prix - Sprint Qualifying [v3.3.5]
req INFO No cached data found for session_info. Loading data...
2024-05-04 11:55:56,998 - fastf1.fastf1.req - INFO - No cached data found for session_info. Loading data...
_api INFO Fetching session info data...
2024-05-04 11:55:56,998 - fastf1.api - INFO - Fetching session info data...
req INFO Data has been written to cache!
2024-05-04 11:55:57,873 - fastf1.fastf1.req - INFO - Data has been written to cache!
req INFO No cached data found for driver_info. Loading data...
2024-05-04 11:55:57,874 - fastf1.fastf1.req - INFO - No cached data found for driver_info. Loading data...
_api INFO Fetching driver list...
2024-05-04 11:55:57,874 - fastf1.api - INFO - Fetching driver list...
req INFO Data has been written to cache!
2024-05-04 11:55:58,804 - fastf1.fastf1.req - INFO - Data has been written to cache!
core WARNING No result data for this session available on Ergast! (This is expected for recent sessions)
2024-05-04 11:55:59,729 - fastf1.fastf1.core - WARNING - No result data for this session available on Ergast! (This is expected for recent sessions)
req INFO No cached data found for session_status_data. Loading data...
2024-05-04 11:55:59,785 - fastf1.fastf1.req - INFO - No cached data found for session_status_data. Loading data...
_api INFO Fetching session status data...
2024-05-04 11:55:59,786 - fastf1.api - INFO - Fetching session status data...
req INFO Data has been written to cache!
2024-05-04 11:56:00,698 - fastf1.fastf1.req - INFO - Data has been written to cache!
req INFO No cached data found for track_status_data. Loading data...
2024-05-04 11:56:00,701 - fastf1.fastf1.req - INFO - No cached data found for track_status_data. Loading data...
_api INFO Fetching track status data...
2024-05-04 11:56:00,702 - fastf1.api - INFO - Fetching track status data...
req INFO Data has been written to cache!
2024-05-04 11:56:01,634 - fastf1.fastf1.req - INFO - Data has been written to cache!
req INFO No cached data found for _extended_timing_data. Loading data...
2024-05-04 11:56:01,637 - fastf1.fastf1.req - INFO - No cached data found for _extended_timing_data. Loading data...
_api INFO Fetching timing data...
2024-05-04 11:56:01,637 - fastf1.api - INFO - Fetching timing data...
_api INFO Parsing timing data...
2024-05-04 11:56:02,961 - fastf1.api - INFO - Parsing timing data...
req INFO Data has been written to cache!
2024-05-04 11:56:03,422 - fastf1.fastf1.req - INFO - Data has been written to cache!
req INFO No cached data found for timing_app_data. Loading data...
2024-05-04 11:56:03,422 - fastf1.fastf1.req - INFO - No cached data found for timing_app_data. Loading data...
_api INFO Fetching timing app data...
2024-05-04 11:56:03,422 - fastf1.api - INFO - Fetching timing app data...
req INFO Data has been written to cache!
2024-05-04 11:56:04,582 - fastf1.fastf1.req - INFO - Data has been written to cache!
core INFO Processing timing data...
2024-05-04 11:56:04,582 - fastf1.fastf1.core - INFO - Processing timing data...
logger WARNING Failed to calculate quali results from lap times!
2024-05-04 11:56:05,145 - fastf1.fastf1.core - WARNING - Failed to calculate quali results from lap times!
2024-05-04 11:56:05,145 - fastf1.fastf1.core - DEBUG - Traceback for failure in quali results
Traceback (most recent call last):
File ".venv\Lib\site-packages\fastf1\logger.py", line 151, in __wrapped
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\fastf1\core.py", line 1861, in _calculate_quali_like_session_results
session[~session['LapTime'].isna() & ~session['Deleted']]
^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\pandas\core\generic.py", line 1570, in invert
new_data = self._mgr.apply(operator.invert)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\pandas\core\internals\managers.py", line 362, in apply
applied = b.apply(f, **kwargs)
^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\pandas\core\internals\blocks.py", line 393, in apply
result = func(self.values, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: bad operand type for unary ~: 'NoneType'
core INFO Finished loading data for 20 drivers: ['1', '81', '55', '63', '18', '11', '44', '22', '31', '10', '3', '20', '27', '23', '24', '4', '77', '2', '14', '16']
2024-05-04 11:56:05,147 - fastf1.fastf1.core - INFO - Finished loading data for 20 drivers: ['1', '81', '55', '63', '18', '11', '44', '22', '31', '10', '3', '20', '27', '23', '24', '4', '77', '2', '14', '16']

I don't know I am able to see the full error. Maybe because I am using try, except and this error is due to Ergast but the normal output is:
core INFO Loading data for Miami Grand Prix - Sprint Qualifying [v3.3.5]
req INFO Using cached data for session_info
req INFO Using cached data for driver_info
core WARNING No result data for this session available on Ergast! (This is expected for recent sessions)
req INFO Using cached data for session_status_data
req INFO Using cached data for track_status_data
req INFO Using cached data for _extended_timing_data
req INFO Using cached data for timing_app_data
core INFO Processing timing data...
logger WARNING Failed to calculate quali results from lap times!
core INFO Finished loading data for 20 drivers: ['1', '81', '55', '63', '18', '11', '44', '22', '31', '10', '3', '20', '27', '23', '24', '4', '77', '2', '14', '16']

You need to use .load(..., messages=True) (which is the default by the way). I will investigate what specifically causes the problem. But it is possible, that there is no fix and FastF1 simply needs the data.
Race control messages are not just loaded for so that users can access them. They are also parsed to get additional information that isn't available otherwise.

You are seeing the full error, because apparently something else in Python environment reconfigures the logger to show the DEBUG level as well. But I have no idea what package might be doing that or if you configured it this way.

Ok, after a quick check, this basically needs to fail without race control messages being loaded. Without the messages, FastF1 cannot reliably know which laps were deleted. But then, it is impossible to accurately calculate qualifying results because the deleted laps are still included in the data.

A better error message would be helpful here though.

I added a better warning message for this.