From 88d61916b1b8258ab0832ab77e4b91661ea9c18e Mon Sep 17 00:00:00 2001 From: Casper Guo Date: Tue, 7 Nov 2023 16:51:28 -0500 Subject: [PATCH 1/3] 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 From aca823035f3244fe1db4f58b7b9112c5a7099ca9 Mon Sep 17 00:00:00 2001 From: manpean <71012769+manpean@users.noreply.github.com> Date: Wed, 8 Nov 2023 20:22:20 +0100 Subject: [PATCH 2/3] ENH: add 'Lap' information to race control messages (#475) --- fastf1/_api.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fastf1/_api.py b/fastf1/_api.py index 0a1997519..a2308e51e 100644 --- a/fastf1/_api.py +++ b/fastf1/_api.py @@ -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``) @@ -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'] From 251bcee8a47a7bae8b2c5f6a932a7722db9bd5ba Mon Sep 17 00:00:00 2001 From: Casper Guo Date: Tue, 7 Nov 2023 16:51:28 -0500 Subject: [PATCH 3/3] Add deprecation warnings, handle uncaught error --- fastf1/core.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fastf1/core.py b/fastf1/core.py index b52e30e4a..bb9867a59 100644 --- a/fastf1/core.py +++ b/fastf1/core.py @@ -2854,16 +2854,16 @@ def pick_fastest(self, only_by_time: bool = False) -> "Lap": 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"), + "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 with IsPersonalBest=True starting from " - " version 3.3"), + "any lap starting from version 3.3"), DeprecationWarning) return Lap(index=self.columns, dtype=object).__finalize__(self)