Skip to content

Commit

Permalink
Add deprecation warnings, handle uncaught error
Browse files Browse the repository at this point in the history
  • Loading branch information
Casper-Guo committed Nov 7, 2023
1 parent d962fa8 commit 88d6191
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 with "
"IsPersonalBest=True 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 with IsPersonalBest=True 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 88d6191

Please sign in to comment.