Skip to content

Commit

Permalink
WIP: fix passing block manager to frame or series
Browse files Browse the repository at this point in the history
  • Loading branch information
theOehrly committed Jan 23, 2024
1 parent b4ee5d4 commit 68ea01a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion fastf1/internals/pandas_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 68ea01a

Please sign in to comment.