Skip to content

Commit

Permalink
FIX: add_driver_ahead doesn't work with resampled telemetry (fixes #430)
Browse files Browse the repository at this point in the history
  • Loading branch information
theOehrly committed Oct 10, 2023
1 parent cf64aba commit 756be97
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
14 changes: 14 additions & 0 deletions docs/changelog/v3.1.x.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
What's new in v3.1.4
--------------------

(released ??/??/2023)

Bug Fixes
^^^^^^^^^

- fixed a bug that caused :func:`~fastf1.core.Telemetry.add_driver_ahead` to
only work with telemetry data that matches the sampling timebase of the
car data (#430)



What's new in v3.1.3
--------------------

Expand Down
8 changes: 4 additions & 4 deletions fastf1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,10 +812,10 @@ def add_driver_ahead(self, drop_existing: bool = True) -> "Telemetry":
index=ref_tel.index)
)

if ((d['SessionTime'].shape != dtd['SessionTime'].shape)
or np.any((d['SessionTime'].values
!= dtd['SessionTime'].values))):
dtd = dtd.resample_channels(new_date_ref=d["SessionTime"])
if ((d['Date'].shape != dtd['Date'].shape)
or np.any((d['Date'].values
!= dtd['Date'].values))):
dtd = dtd.resample_channels(new_date_ref=d["Date"])

# indices need to match as .join works index-on-index
dtd['_SelfIndex'] = d.index
Expand Down
12 changes: 11 additions & 1 deletion fastf1/tests/test_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,22 @@ def test_resampling_up(reference_laps_data):


@pytest.mark.f1telapi
def test_add_driver_ahead(reference_laps_data):
@pytest.mark.parametrize(
"resample_rule",
[None, "0.1S"] # test base frequency and resampled
)
def test_add_driver_ahead(reference_laps_data, resample_rule):
session, laps = reference_laps_data
test_data = laps.pick_fastest().get_car_data()
if resample_rule is not None:
test_data = test_data.resample_channels(rule=resample_rule)
test_data = test_data.add_driver_ahead()
# only first value may be NaN
assert test_data['DistanceToDriverAhead'].isnull().sum() <= 1
# values need to change over the course of the lap
assert len(test_data['DistanceToDriverAhead'].unique()) > 2
# DriverAhead must not be empty
assert (test_data['DriverAhead'].unique() != ['']).any()


@pytest.mark.f1telapi
Expand Down

0 comments on commit 756be97

Please sign in to comment.