From 88d61916b1b8258ab0832ab77e4b91661ea9c18e Mon Sep 17 00:00:00 2001 From: Casper Guo Date: Tue, 7 Nov 2023 16:51:28 -0500 Subject: [PATCH] Add deprecation warnings, handle uncaught error --- fastf1/core.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/fastf1/core.py b/fastf1/core.py index faa6e37ee..b52e30e4a 100644 --- a/fastf1/core.py +++ b/fastf1/core.py @@ -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