theOehrly / Fast-F1

FastF1 is a python package for accessing and analyzing Formula 1 results, schedules, timing data and telemetry
https://docs.fastf1.dev
MIT License
2.48k stars 259 forks source link

[BUG] Laps and Telemetry data not loading with Pandas 2.0.0 #345

Closed mrkeuz closed 1 year ago

mrkeuz commented 1 year ago

Describe the issue:

Casue

I use isolated and fresh env for running Fast-F1. Judging setup.cfg

https://github.com/theOehrly/Fast-F1/blob/79fa22efdc47c7ffdcfbcddef54d6ec8905dfd65/setup.cfg#L22

So it's installing the latest pandas == 2.0.0.

After that I got next error (see error log).

Solution

If you pin pandas == 1.5.3 (latest before major) seems all work as expected. Think temporary solution is can be to pin pandas version to 1 until compatibility problems will not be solved.

Full error log issue_pd.log

Reproduce the code example:

import logging
import sys

import fastf1
fastf1.Cache.enable_cache('./doc_cache')

root = logging.getLogger()
root.setLevel(logging.DEBUG)

handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
root.addHandler(handler)

session = fastf1.get_session(2021, 2, 'R', force_ergast=True)
session.load(laps=True)

print(session.laps)

Error message:

2023-04-05 14:39:45,804 - root - WARNING - Failed to load lap data!
2023-04-05 14:39:45,804 - root - DEBUG - Lap data failure traceback:
Traceback (most recent call last):
  File "/home/user/.cache/pypoetry/virtualenvs/f1-telem-y3ewXBhG-py3.8/lib/python3.8/site-packages/fastf1/core.py", line 1175, in load
    self._load_laps_data(livedata)
  File "/home/user/.cache/pypoetry/virtualenvs/f1-telem-y3ewXBhG-py3.8/lib/python3.8/site-packages/fastf1/core.py", line 1284, in _load_laps_data
    d2 = self.__fix_tyre_info(d2)
  File "/home/user/.cache/pypoetry/virtualenvs/f1-telem-y3ewXBhG-py3.8/lib/python3.8/site-packages/fastf1/core.py", line 1492, in __fix_tyre_info
    for key, value in row.iteritems():
  File "/home/user/.cache/pypoetry/virtualenvs/f1-telem-y3ewXBhG-py3.8/lib/python3.8/site-packages/pandas/core/generic.py", line 5989, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'iteritems'
core        WARNING     Failed to load lap data!
mrkeuz commented 1 year ago

Also, with pandas == 1.5.3 it shows future incompatibles warnings. Seems this exactly places where issue raise after switching to 2.0.0

Here warnings that I got: pd_warnings.log

theOehrly commented 1 year ago

Thanks for the report. These things are already fixed on master as a reaction to the deprecation warnings. I actually just yesterday realized that pandas 2.0 was released two days ago. Looks like they were faster with their new major release than I was with adapting to it. I'll see if I'll maybe push a new patch release for this. I'm still looking into some other problems at the moment related to subclassing pandas objects. Those have resulted from the pandas 2.0 release and were completely unexpected. I need to assess the severity first and decide what to do.

mrkeuz commented 1 year ago

Really cool!

Then, I will try to install master release into my project. And also try to test things. Just want to help with testing. Will add notes if found something.

Thanks! πŸš€

mrkeuz commented 1 year ago

@theOehrly got next error on latest master 9e60248efb6a89462545947a4681c76bb3014ecc

just at first import fastf1

/home/user/.cache/pypoetry/virtualenvs/f1-telem-y3ewXBhG-py3.8/bin/python /home/user/Projects/_Learn/python/f1_telem/plot_qualifying_results.py 
Traceback (most recent call last):
  File "/home/user/Projects/_Learn/python/f1_telem/plot_qualifying_results.py", line 4, in <module>
    import fastf1
  File "/home/user/.cache/pypoetry/virtualenvs/f1-telem-y3ewXBhG-py3.8/lib/python3.8/site-packages/fastf1/__init__.py", line 59, in <module>
    from fastf1.events import (get_session,  # noqa: F401
  File "/home/user/.cache/pypoetry/virtualenvs/f1-telem-y3ewXBhG-py3.8/lib/python3.8/site-packages/fastf1/events.py", line 172, in <module>
    from fastf1.core import Session
  File "/home/user/.cache/pypoetry/virtualenvs/f1-telem-y3ewXBhG-py3.8/lib/python3.8/site-packages/fastf1/core.py", line 54, in <module>
    from fastf1 import api, ergast
ImportError: cannot import name 'ergast' from partially initialized module 'fastf1' (most likely due to a circular import) (/home/user/.cache/pypoetry/virtualenvs/f1-telem-y3ewXBhG-py3.8/lib/python3.8/site-packages/fastf1/__init__.py)
theOehrly commented 1 year ago

I cannot reproduce this even in a clean environement. How did you install from master?

mrkeuz commented 1 year ago

With Poetry tool. It can add dependencies that point right to git repo.

Here project sample: f1_telem_test.zip

To run:

pip3 install poetry
cd f1_telem_test
# Install deps to venv
poetry update
# Run inside venv
poetry run python3 main.py

python3.8

Reproduced now on clean env. Of course maybe something wrong with Poetry. Think it is not issue then.

mrkeuz commented 1 year ago

Same result via (without venv): pip3 install 'git+https://github.com/theOehrly/Fast-F1.git@master'

theOehrly commented 1 year ago

Ok, I managed to reproduce it now. I'll look into it

theOehrly commented 1 year ago

@mrkeuz the import error should be fixed now

mrkeuz commented 1 year ago

Confirm. Working! πŸš€

theOehrly commented 1 year ago

I also made a new maintenance patch release v2.3.2 just now that limits pandas to <2.0.0 on clean installations. This should at least prevent the problem that you get errors on a fresh install until the next proper release with support for pandas 2.0