Skip to content

Commit

Permalink
MNT: make pick_fastest return None instead of empty lap following dep…
Browse files Browse the repository at this point in the history
…recation (closes #477)
  • Loading branch information
theOehrly committed Feb 19, 2024
1 parent 9f37e01 commit 4aeb91a
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions fastf1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3027,18 +3027,18 @@ def pick_teams(self, names: Union[str, Iterable[str]]) -> "Laps":

return self[self['Team'].isin(names)]

def pick_fastest(self, only_by_time: bool = False) -> "Lap":
def pick_fastest(self, only_by_time: bool = False) -> Optional["Lap"]:
"""Return the lap with the fastest lap time.
This method will by default return the quickest lap out of self, that
This method will by default return the quickest lap out of self that
is also marked as personal best lap of a driver.
If the quickest lap by lap time is not marked as personal best, this
means that it was not counted. This can be the case for example, if
means that it was not counted. This can be the case, for example, if
the driver exceeded track limits and the lap time was deleted.
If no lap is marked as personal best lap or self contains no laps,
an empty Lap object will be returned.
``None`` is returned instead.
The check for personal best lap can be disabled, so that any quickest
lap will be returned.
Expand All @@ -3049,30 +3049,19 @@ def pick_fastest(self, only_by_time: bool = False) -> "Lap":
lowest lap time.
Returns:
instance of :class:`Lap`
instance of :class:`Lap` or ``None``
"""
# 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

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)
return None

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)
return None

lap = laps.loc[laps['LapTime'].idxmin()]
if isinstance(lap, pd.DataFrame):
Expand Down

0 comments on commit 4aeb91a

Please sign in to comment.