Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Allow creation of Model.DataFrame from polars.DataFrame/LazyFrame #27

Open
jjfantini opened this issue Oct 17, 2023 · 2 comments

Comments

@jjfantini
Copy link

Right now, you can only create a model-aware DataFrame from either a dict representation or from pandas. It would be great for workflow to be able to do this with polars objects.

from openbb_terminal.stocks import stocks_helper as stocks
import polars as pl

df = stocks.load(
    symbol="AAPL",
    start_date="1950-01-01",
    end_date="2023-10-16",
) 

df = pl.from_pandas(df, include_index=True).lazy()

# THIS DOESNT WORK
df = StocksBaseModel.LazyFrame(df)

TypeError: DataFrame constructor called with unsupported type 'LazyFrame' for the `data` parameter
@Fizzizist
Copy link

@jjfantini I agree that this should be added, but in the meantime, wouldn't an instantiation using pyarrow be better because the data is already stored as Arrow arrays on the backend?

StockBaseModel.DataFrame._from_arrow(df.to_arrow())

@jjfantini
Copy link
Author

jjfantini commented Nov 3, 2023

Yup, that is what I currently do, although I would suggest df.to_dict(). It is a smidge faster.

Although I have stopped using patito since my project requires Pydantic v2. I have published a package humblpatito that is compatible with Pydantic V2, but don't have time right now to flesh out all the edge cases. Plus, I want to use AliasChoices in V2

@lmmx lmmx added this to Planner Sep 9, 2024
@lmmx lmmx moved this to 🛒 TODO in Planner Sep 9, 2024
@lmmx lmmx removed this from Planner Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants