Skip to content

Commit

Permalink
MNT: fix pandas resample interval deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
theOehrly committed Feb 1, 2024
1 parent 0d3f29c commit d645a40
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion fastf1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def merge_channels(
merged = merged.reset_index().rename(columns={'index': 'Date'})

else:
frq = f'{1 / frequency}S'
frq = pd.Timedelta(seconds=1/frequency)

resampled_columns = dict()

Expand Down
11 changes: 6 additions & 5 deletions fastf1/tests/test_telemetry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy
import pandas
import pandas as pd
import pytest

import fastf1.core
Expand Down Expand Up @@ -82,7 +83,7 @@ def test_resample_channels_with_metadata_propagation(reference_laps_data):
lap = laps.pick_fastest()
car_data = lap.get_car_data()

for freq in ('0.5S', '0.1S'):
for freq in (pd.Timedelta(seconds=0.5), pd.Timedelta(seconds=0.1)):
resampled = car_data.resample_channels(rule=freq)
for attr in fastf1.core.Telemetry._metadata:
assert getattr(resampled, attr, None) is not None
Expand Down Expand Up @@ -246,7 +247,7 @@ def test_resampling_down(reference_laps_data):
drv = lap['DriverNumber']
test_data = session.car_data[drv].slice_by_lap(lap)

test_data = test_data.resample_channels(rule='0.5S')
test_data = test_data.resample_channels(rule=pd.Timedelta(seconds=0.5))

# assert correct number of samples for duration at 2 Hz within +-1 sample
n_samples_target = round(test_data['Time'].iloc[-1].total_seconds() * 2, 0)
Expand All @@ -267,7 +268,7 @@ def test_resampling_up(reference_laps_data):
drv = lap['DriverNumber']
test_data = session.car_data[drv].slice_by_lap(lap)

test_data = test_data.resample_channels(rule='0.05S')
test_data = test_data.resample_channels(rule=pd.Timedelta(seconds=0.05))

# assert correct number of samples for duration at 20 Hz within +-1 sample
n_samples_target = round(test_data['Time'].iloc[-1].total_seconds() * 20, 0)
Expand All @@ -284,7 +285,7 @@ def test_resampling_up(reference_laps_data):
@pytest.mark.f1telapi
@pytest.mark.parametrize(
"resample_rule",
[None, "0.1S"] # test base frequency and resampled
[None, pd.Timedelta(seconds=0.1)] # test base frequency and resampled
)
def test_add_driver_ahead(reference_laps_data, resample_rule):
session, laps = reference_laps_data
Expand All @@ -304,7 +305,7 @@ def test_add_driver_ahead(reference_laps_data, resample_rule):
def test_add_driver_ahead_resampled(reference_laps_data):
session, laps = reference_laps_data
test_data = laps.pick_fastest().get_car_data()\
.resample_channels(rule='0.5S')
.resample_channels(rule=pd.Timedelta(seconds=0.5))
test_data = test_data.add_driver_ahead()
# only first value may be NaN
assert test_data['DistanceToDriverAhead'].isnull().sum() <= 1
Expand Down
1 change: 0 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,3 @@ filterwarnings =
# TODO: temp, needs to be actually fixed before pandas 3.0.0
ignore:A value is trying to be set on a copy of.*:FutureWarning
ignore:Downcasting object dtype arrays.*:FutureWarning
ignore:'S' is deprecated and will be removed.*:FutureWarning

0 comments on commit d645a40

Please sign in to comment.