Skip to content

Commit

Permalink
Merge branch 'v3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
theOehrly committed Jan 7, 2024
2 parents a4cbe89 + be98a4f commit a59bbf2
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 61 deletions.
88 changes: 88 additions & 0 deletions docs/changelog/v3.1.x.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,91 @@
What's new in v3.1.5
--------------------

(released 24/11/2023)

New Features
^^^^^^^^^^^^

- Added driver colors for OWA, DEN, OSU


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

(released 17/11/2023)

Bug Fixes
^^^^^^^^^

- Fixed a bug that caused inconsistent behaviour in
:func:`~fastf1.core.Laps.pick_fastest` in some cases were there was no lap
that met the criteria for a fastest lap. Now, an empty
:class:`~fastf1.core.Lap` object will always be returned when there is no
fastest lap. (Note that this will change in the future, see 'Deprecations'
below (#476) (by @Casper-Guo)

- Fixed a bug that prevented some sessions of the Las Vegas Grand Prix from
being loaded (#481)

Deprecations
^^^^^^^^^^^^

- In cases were no lap meets the criteria for a fastest lap,
:func:`~fastf1.core.Laps.pick_fastest` currently returns an empty
:class:`~fastf1.core.Lap` object. Starting from version 3.3, this will
return ``None`` instead


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

(released 26/10/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)

- Improved robustness of the Ergast API parser to prevent crashes caused by some
empty values in the API response (#433) (by @harningle)

- Fixed: some laps that were generated by FastF1 had incorrect lap numbers

- Fixed: pit out times from the lap onto the grid are no longer shown for the
first lap of a race-like session. The first lap will only have a pit out time
if a driver started from the pit lane or pitted on the formation lap.
(#467) (by @Casper-Guo)

- Improved robustness of the 'f1timing' schedule backend to prevent a crash
caused by partially incorrect data for the schedule of the Qatar GP

- Fixed: laps for all drivers were marked as inaccurate if the lap accuracy
check could not be performed for one driver


New Features
^^^^^^^^^^^^

- Added driver colors for VES, POU, HAD, DOO and BEA
(#471) (by @pesaventofilippo)



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

(released 07/10/2023)

Bug Fixes
^^^^^^^^^

- fixed a bug in the driver list parser that caused Piastri to be missing from
the results in the 2023 Qatar Sprint Shootout (#460)



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

Expand Down
71 changes: 26 additions & 45 deletions fastf1/_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
import collections
import datetime
import json
import zlib
Expand Down Expand Up @@ -1474,7 +1475,7 @@ def driver_info(path, response=None, livedata=None):
`['RacingNumber', 'BroadcastName', 'FullName', 'Tla', 'Line',
'TeamName', 'TeamColour', 'FirstName', 'LastName', 'Reference',
'HeadshotUrl']`
'HeadshotUrl', 'CountryCode']`
Args:
path (str): api path base string (usually ``Session.api_path``)
Expand Down Expand Up @@ -1503,51 +1504,31 @@ def driver_info(path, response=None, livedata=None):
"recently, please try again in a few minutes."
)

# search for the correct entries that contain driver/team/headshot info
# for some sessions headshots are one entry for each team (Miami 22 FPs, Q)
drv_idx = None
team_idx = None
headshots = []

for i, entry in enumerate(response):
if 'RacingNumber' in str(entry):
drv_idx = i
if 'TeamName' in str(entry):
team_idx = i
if 'HeadshotUrl' in str(entry):
headshots.append(i)
if drv_idx and team_idx:
break

# parse data
try:
drv_info = response[drv_idx][1]
except (IndexError, TypeError):
return dict()

try:
team_info = response[team_idx][1]
except (IndexError, TypeError):
return dict()

# loop through headshots
try:
head_info = dict()
for head in headshots:
head_info.update(response[head][1])
except (IndexError, TypeError):
return dict()
drivers = collections.defaultdict(dict)

else:
for drv in drv_info:
drv_info[drv].update(team_info.get(drv, {}))
drv_info[drv].update(head_info.get(drv, {}))

if not len(drv_info) or not isinstance(drv_info, dict):
return dict()
if 'RacingNumber' not in list(drv_info.values())[0]:
return dict()
return drv_info
default_keys = [
'RacingNumber', 'BroadcastName', 'FullName', 'Tla', 'Line',
'TeamName', 'TeamColour', 'FirstName', 'LastName', 'Reference',
'HeadshotUrl', 'CountryCode'
]

for line in response:
try:
ts, content = line
except ValueError:
# unexpected data format, incorrect number of values to unpack
continue
if not isinstance(content, dict):
continue # unexpected data format
for drv_num, patch in content.items():
if not isinstance(patch, dict):
continue # unexpected data format
for key, val in patch.items():
if key not in default_keys:
continue
drivers[drv_num][key] = val

return drivers


@Cache.api_request_wrapper
Expand Down
17 changes: 12 additions & 5 deletions fastf1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,10 +917,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 Expand Up @@ -1165,10 +1165,17 @@ def __init__(self, event, session_name, f1_api_support=False):
data and telemetry data are available."""
self.date = self.event.get_session_date(session_name, utc=True)
"""pandas.Datetime: Date at which this session took place."""

try:
_api_date = self.event.get_session_date(session_name, utc=False)
except ValueError:
# not all backends provide local timestamps, use UTC then which
# works in almost all cases
_api_date = self.date
self.api_path = api.make_path(
self.event['EventName'],
self.event['EventDate'].strftime('%Y-%m-%d'),
self.name, self.date.strftime('%Y-%m-%d')
self.name, _api_date.strftime('%Y-%m-%d')
)
"""str: API base path for this session"""

Expand Down
8 changes: 7 additions & 1 deletion fastf1/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,19 @@ def warn_change(self):

"oscar piastri": "#ff8700",
"lando norris": "#eeb370",
"pato oward": "#ee6d3a",

"lewis hamilton": "#00d2be",
"george russell": "#24ffff",
"frederik vesti": "#00a6ff",

"max verstappen": "#0600ef",
"sergio perez": "#716de2",
"jake dennis": "#9f99e2",

"alexander albon": "#005aff",
"logan sargeant": "#012564",
"zak osullivan": "#1b3d97",
}
"""Mapping of driver names to driver colors (hex color codes).
(current season only)"""
Expand All @@ -148,7 +151,9 @@ def warn_change(self):
'LEC': 'charles leclerc', 'SAI': 'carlos sainz',
'SHW': 'robert shwartzman',
'VER': 'max verstappen', 'PER': 'sergio perez',
'DEN': 'jake dennis',
'PIA': 'oscar piastri', 'NOR': 'lando norris',
'OWA': 'pato oward',
'GAS': 'pierre gasly', 'OCO': 'esteban ocon',
'DOO': 'jack doohan',
'BOT': 'valtteri bottas', 'ZHO': 'zhou guanyu',
Expand All @@ -162,7 +167,8 @@ def warn_change(self):
'DRU': 'felipe drugovich',
'HAM': 'lewis hamilton', 'RUS': 'george russell',
'VES': 'frederik vesti',
'ALB': 'alexander albon', 'SAR': 'logan sargeant'}
'ALB': 'alexander albon', 'SAR': 'logan sargeant',
'OSU': 'zak osullivan'}
"""Mapping of driver names to theirs respective abbreviations."""

COMPOUND_COLORS: Dict[str, str] = {
Expand Down
2 changes: 1 addition & 1 deletion fastf1/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class Cache(metaclass=_MetaCache):
"""
_CACHE_DIR = None
# version of the api parser code (unrelated to release version number)
_API_CORE_VERSION = 11
_API_CORE_VERSION = 12
_IGNORE_VERSION = False
_FORCE_RENEW = False

Expand Down
Loading

0 comments on commit a59bbf2

Please sign in to comment.