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

Implement removing first lap pitout time and add tests #467

Merged
merged 2 commits into from
Oct 16, 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
5 changes: 5 additions & 0 deletions fastf1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,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