diff --git a/fastf1/internals/pandas_base.py b/fastf1/internals/pandas_base.py index f21d3f628..60a1069f8 100644 --- a/fastf1/internals/pandas_base.py +++ b/fastf1/internals/pandas_base.py @@ -6,6 +6,11 @@ ) import pandas as pd +# dangerous! some way around this would be better +from pandas.core.internals import ( + BlockManager, + SingleBlockManager +) class BaseDataFrame(pd.DataFrame): @@ -97,7 +102,12 @@ def __new__(cls, data=None, index=None, *args, **kwargs) -> pd.Series: # the data is a row of the parent DataFrame constructor = parent._constructor_sliced_horizontal - obj = constructor(data=data, index=index, *args, **kwargs) + if (isinstance(data, (BlockManager, SingleBlockManager)) + and hasattr(constructor, '_from_mgr') + and pd.__version__.startswith('2.')): + obj = constructor._from_mgr(data, axes=data.axes) + else: + obj = constructor(data=data, index=index, *args, **kwargs) if parent is not None: # catch-all fix for some missing __finalize__ calls in Pandas