diff --git a/fastf1/internals/pandas_base.py b/fastf1/internals/pandas_base.py index f21d3f628..1f085a138 100644 --- a/fastf1/internals/pandas_base.py +++ b/fastf1/internals/pandas_base.py @@ -6,6 +6,14 @@ ) import pandas as pd +from pandas.core.internals import ( + BlockManager, + SingleBlockManager +) + + +# TODO: make this work without importing internals? assume block manager if +# not Series or DataFrame maybe? class BaseDataFrame(pd.DataFrame): @@ -97,7 +105,11 @@ 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')): + 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