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
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions fastf1/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,7 @@ def race_control_messages(path, response=None, livedata=None):
- Scope (str): Scope of message "Track", "Sector", "Driver"
- Sector (int): Affected track sector for sector-scoped messages
- RacingNumber (str): Affected driver for CarEvent messages
- Lap (int): Number of the lap in which the message was displayed

Args:
path (str): api path base string (usually ``Session.api_path``)
Expand Down Expand Up @@ -1361,11 +1362,11 @@ def race_control_messages(path, response=None, livedata=None):

data = {
'Time': [], 'Category': [], 'Message': [], 'Status': [],
'Flag': [], 'Scope': [], 'Sector': [], 'RacingNumber': []
'Flag': [], 'Scope': [], 'Sector': [], 'RacingNumber': [], 'Lap': []
}
data_keys = ('Category', 'Message', 'Status', 'Flag', 'Scope', 'Sector',
'RacingNumber')
converters = (str, str, str, str, str, int, str)
'RacingNumber', 'Lap')
converters = (str, str, str, str, str, int, str, int)

for line in response:
messages = line[1]['Messages']
Expand Down
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 that satisfies "
"the definition for fastest lap 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 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