Skip to main content

Overview

The fastf1.utils module provides utility functions for common operations in FastF1, including time conversions, delta time calculations, and recursive dictionary access.

Functions

to_timedelta()

Fast timedelta object creation from a time string. Parameters:
  • x (str | datetime.timedelta): Timestamp string or timedelta object
Returns:
  • datetime.timedelta | None: Parsed timedelta object or None if parsing fails
Permissible String Formats: For example: 13:24:46.320215 with:
  • Optional hours and minutes
  • Optional microseconds and milliseconds with arbitrary precision (1 to 6 digits)
Examples of valid formats:
  • 24.3564 - seconds + milli/microseconds
  • 36:54 - minutes + seconds
  • 8:45:46 - hours, minutes, seconds
Example:

to_datetime()

Fast datetime object creation from a date string. Parameters:
  • x (str | datetime.datetime): Timestamp string or datetime object
Returns:
  • datetime.datetime | None: Parsed datetime object or None if parsing fails
Permissible String Formats: For example: 2020-12-13T13:27:15.320000Z with:
  • Optional milliseconds and microseconds with arbitrary precision (1 to 6 digits)
  • Optional trailing letter ‘Z’
Examples of valid formats:
  • 2020-12-13T13:27:15.320000
  • 2020-12-13T13:27:15.32Z
  • 2020-12-13T13:27:15
Example:

delta_time()

This function is deprecated since version 3.0.0 and may be modified or removed in a future release due to accuracy concerns.
This function has a tendency to give inaccurate results. Always verify the result against sector time differences.
Calculates the delta time of a given lap, along the ‘Distance’ axis of the reference lap. Parameters:
  • reference_lap (fastf1.core.Lap): The lap taken as reference
  • compare_lap (fastf1.core.Lap): The lap to compare
Returns:
  • tuple[pd.Series, fastf1.core.Telemetry, fastf1.core.Telemetry]: A tuple containing:
    • pd.Series of type float64 with the delta in seconds
    • Telemetry for the reference lap
    • Telemetry for the comparison lap
Use the returned telemetry for plotting to ensure you have telemetry data that was created with the same interpolation and resampling options.
Example:

recursive_dict_get()

Recursive dict get. Can take an arbitrary number of keys and returns an empty dict if any key does not exist. Parameters:
  • d (dict): The dictionary to traverse
  • *keys (str): Variable number of keys to traverse
  • default_none (bool, optional): If True, return None instead of empty dict when key doesn’t exist. Default is False.
Returns:
  • The value at the nested key path, or {} (or None if default_none=True) if any key doesn’t exist
Example: