Skip to content

Commit

Permalink
Fix inconsistency in pick_fastest, add deprecation warning for future…
Browse files Browse the repository at this point in the history
… behavior change (#476)
  • Loading branch information
Casper-Guo authored Nov 9, 2023
1 parent f5b4498 commit aef3668
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions fastf1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2844,18 +2844,32 @@ def pick_fastest(self, only_by_time: bool = False) -> "Lap":
Returns:
instance of :class:`Lap`
"""
# TODO: Deprecate returning empty lap object when there is no lap
# that matches definion
if only_by_time:
laps = self # all laps
else:
# select only laps marked as personal fastest
laps = self.loc[self['IsPersonalBest'] == True] # noqa: E712 comparison with True
laps = self.loc[self['IsPersonalBest'] == True] # noqa: E712

if not laps.size:
warnings.warn(("None will be returned instead of an empty Lap "
"object when there are no laps that satisfies "
"the definition for fastest lap starting from "
"version 3.3"),
DeprecationWarning)
return Lap(index=self.columns, dtype=object).__finalize__(self)

if laps['LapTime'].isna().all():
warnings.warn(("None will be returned instead of an empty Lap "
"object when there is no recorded LapTime for "
"any lap starting from version 3.3"),
DeprecationWarning)
return Lap(index=self.columns, dtype=object).__finalize__(self)

lap = laps.loc[laps['LapTime'].idxmin()]
if isinstance(lap, pd.DataFrame):
# More laps, same time
# Multiple laps, same time
lap = lap.iloc[0] # take first clocked

return lap
Expand Down

0 comments on commit aef3668

Please sign in to comment.