diff --git a/fastf1/core.py b/fastf1/core.py index 3538738b8..363852147 100644 --- a/fastf1/core.py +++ b/fastf1/core.py @@ -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. @@ -3049,10 +3049,8 @@ 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: @@ -3060,19 +3058,10 @@ def pick_fastest(self, only_by_time: bool = False) -> "Lap": 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):