In laps.pick_track_status, the contains, excludes, any, and none values of the how argument can cause crashes when a driver retires on track. The last laps of these drivers have NaN as their track status. When supplied to Pandas.Series.str.contains, NaN is returned which cannot be used to index the dataframe.
Two potential solutions:
Handle the NaN case directly by passing the na argument to str.contains. The default behavior can depend on how inclusive/exclusive the how argument is.
Add track status to the last lap of retired drivers.
File "/mnt/d/Projects/F1-Visualization/test.py", line 5, in <module>
session.laps.pick_track_status("467", how="none")
File "/home/robery/.local/lib/python3.11/site-packages/fastf1/core.py", line 3199, in pick_track_status
return self[~self['TrackStatus'].str.contains('|'.join(status),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/robery/.local/lib/python3.11/site-packages/pandas/core/generic.py", line 1461, in __invert__
new_data = self._mgr.apply(operator.invert)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/robery/.local/lib/python3.11/site-packages/pandas/core/internals/managers.py", line 350, in apply
applied = b.apply(f, **kwargs)
^^^^^^^^^^^^^^^^^^^^
File "/home/robery/.local/lib/python3.11/site-packages/pandas/core/internals/blocks.py", line 329, in apply
result = func(self.values, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: bad operand type for unary ~: 'float'
Describe the issue:
In
laps.pick_track_status
, thecontains
,excludes
,any
, andnone
values of thehow
argument can cause crashes when a driver retires on track. The last laps of these drivers haveNaN
as their track status. When supplied toPandas.Series.str.contains
,NaN
is returned which cannot be used to index the dataframe.Two potential solutions:
NaN
case directly by passing thena
argument tostr.contains
. The default behavior can depend on how inclusive/exclusive thehow
argument is.Reproduce the code example:
Error message: