Skip to content

Commit

Permalink
FIX: remove first lap pitout time for race-like sessions (#467)
Browse files Browse the repository at this point in the history
(cherry picked from commit cd115fc)
  • Loading branch information
Casper-Guo authored and theOehrly committed Oct 26, 2023
1 parent f029cfe commit 1e94af2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fastf1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,11 @@ def _load_laps_data(self, livedata=None):
mask = pd.isna(result['LapStartTime']) & (~pd.isna(result['PitOutTime']))
result.loc[mask, 'LapStartTime'] = result.loc[mask, 'PitOutTime']

# remove first lap pitout time if it is before session_start_time
mask = (result["PitOutTime"] < self.session_start_time) & \
(result["NumberOfLaps"] == 1)
result.loc[mask, 'PitOutTime'] = pd.NaT

# create total laps counter for each tyre used
for npit in result['Stint'].unique():
sel = result['Stint'] == npit
Expand Down
17 changes: 17 additions & 0 deletions fastf1/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ def test_lap_data_loading_position_calculation():
assert (delta == 0).all() # assert that the delta is zero for all laps


@pytest.mark.f1telapi
def test_first_lap_pitout_times():
sprint_session = fastf1.get_session(2023, 4, "Sprint")
sprint_session.load(telemetry=False, weather=False, messages=False)
sprint_laps = sprint_session.laps
sprint_mask = (sprint_laps["LapNumber"] == 1) & \
(~sprint_laps["PitOutTime"].isna())
assert sprint_laps[sprint_mask]["Driver"].tolist() == ["OCO"]

race_session = fastf1.get_session(2023, 5, "R")
race_session.load(telemetry=False, weather=False, messages=False)
race_laps = race_session.laps
race_mask = (race_laps["LapNumber"] == 1) & \
(~race_laps["PitOutTime"].isna())
assert race_laps[race_mask]["Driver"].tolist() == []


def test_laps_constructor_metadata_propagation(reference_laps_data):
session, laps = reference_laps_data

Expand Down

0 comments on commit 1e94af2

Please sign in to comment.