-
-
Notifications
You must be signed in to change notification settings - Fork 336
Closed
Description
Describe the issue:
This is not really a bug, rather an inconsistency in a very specific case.
In Mexico FP1, POU did 4 laps, but all of them had no data (specifically, LapTime
is NaN
).
In that case, using laps.pick_fastest(only_by_time=False)
works and returns (I think) the first lap, although all data is NaN
, while using laps.pick_fastest(only_by_time=True)
throws ValueError: attempt to get argmin of an empty sequence
(obviously because there's no lap times to compare).
Sometimes it could be useful to check if a lap's time is NaN
after picking it with pick_fastest()
, so I think we should return the first lap (or any) if all of them are NaN
. But let me know what you think.
Reproduce the code example:
import fastf1
session = fastf1.get_session(2023, "Mexico", "FP1")
session.load()
laps = session.laps.pick_driver("POU")
flap = laps.pick_fastest()
print(flap.LapTime) # nan
flap = laps.pick_fastest(only_by_time=True) # ValueError
Error message:
>>> laps.pick_fastest(only_by_time=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/fastf1/core.py", line 2818, in pick_fastest
lap = laps.loc[laps['LapTime'].idxmin()]
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/core/series.py", line 2460, in idxmin
i = self.argmin(axis, skipna, *args, **kwargs) # type: ignore[arg-type]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/core/base.py", line 738, in argmin
return delegate.argmin()
^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/core/arrays/_mixins.py", line 201, in argmin
return nargminmax(self, "argmin", axis=axis)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/core/sorting.py", line 473, in nargminmax
return _nanargminmax(arr_values, mask, func)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/core/sorting.py", line 484, in _nanargminmax
return non_nan_idx[func(non_nans)]
^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 1325, in argmin
return _wrapfunc(a, 'argmin', axis=axis, out=out, **kwds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 59, in _wrapfunc
return bound(*args, **kwds)
^^^^^^^^^^^^^^^^^^^^
ValueError: attempt to get argmin of an empty sequence
Metadata
Metadata
Assignees
Labels
No labels