From a06079611f58f11bffcec9973c8e844f6d4418ac Mon Sep 17 00:00:00 2001 From: Casper Guo Date: Sat, 1 Feb 2025 01:57:12 -0500 Subject: [PATCH 1/2] Eliminate type cohersion from #676 See pandas-dev/pandas#60728 for discussion --- fastf1/core.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fastf1/core.py b/fastf1/core.py index 4f67563b..7717a90f 100644 --- a/fastf1/core.py +++ b/fastf1/core.py @@ -1550,9 +1550,7 @@ def _load_laps_data(self, livedata=None): # started can only be made for the race laps_start_time.insert(0, self.session_start_time) else: - laps_start_time.insert(0, pd.NaT) - laps_start_time = pd.Series(laps_start_time, - dtype="timedelta64[ns]") + laps_start_time.insert(0, np.timedelta64("NaT")) # don't set lap start times after red flag restart to the time # at which the previous lap was set From 35d3fcbf461849335026cd10767be67348347f47 Mon Sep 17 00:00:00 2001 From: theOehrly <23384863+theOehrly@users.noreply.github.com> Date: Thu, 6 Feb 2025 10:24:03 +0100 Subject: [PATCH 2/2] add test --- fastf1/tests/test_input_data_handling.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fastf1/tests/test_input_data_handling.py b/fastf1/tests/test_input_data_handling.py index 3e5304e3..4637716e 100644 --- a/fastf1/tests/test_input_data_handling.py +++ b/fastf1/tests/test_input_data_handling.py @@ -157,6 +157,16 @@ def test_first_lap_time_added_from_ergast_in_race(): assert not pd.isna(session.laps.pick_laps(1)['LapTime']).any() +@pytest.mark.f1telapi +def test_lap_start_time_dtype_single_lap(): + # When a driver only completes one lap, the LapStartTime column only + # contains a NaT value. Ensure that this column still has the correct + # timedelta64 dtype as pandas defaults to datetime64[ns] when all values + # are NaT (see GH#674) + session = fastf1.get_session(2022, 10, 1) + session.load(telemetry=False, weather=False) + + assert session.laps['LapStartTime'].dtype == 'timedelta64[ns]' @pytest.mark.f1telapi def test_consecutive_equal_lap_times():