Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistency in pick_fastest, add deprecation warning for future behavior change #476

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Casper-Guo marked this conversation as resolved.
Show resolved Hide resolved
laps = self.loc[self['IsPersonalBest'] == True] # noqa: E712
theOehrly marked this conversation as resolved.
Show resolved Hide resolved

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"),
Casper-Guo marked this conversation as resolved.
Show resolved Hide resolved
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