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

error: can't pass polars dataframe to tools #418

Open
Light2Dark opened this issue Jan 20, 2025 · 0 comments
Open

error: can't pass polars dataframe to tools #418

Light2Dark opened this issue Jan 20, 2025 · 0 comments

Comments

@Light2Dark
Copy link

I get the following error when I try to pass df to a tool.

This cell raised an exception: PydanticUserError('`filter_dataset` is not fully defined; you should define `pl`, then call `filter_dataset.model_rebuild()`. 

For further information visit https://errors.pydantic.dev/2.10/u/class-not-fully-defined')

import polars as pl
import ell

Code:

@ell.tool()
def filter_dataset(df: pl.DataFrame, sql_query: str):
    """
    Filter a polars dataframe using SQL. Please only use fields from the schema.
    """
    return df.sql(sql_query, table_name="data")


@ell.complex(
    model="deepseek-chat",
    client=deepseek_client,
    tools=[chart_data, filter_dataset],
)
def analyze_dataset(df: pl.DataFrame, prompt: str):
    """You are a data scientist that can analyze a dataset"""
    return f"""I have a dataset with schema: {df.schema}.\n These are the first 5 rows: {df.head()}.\n {prompt}"""

analyze_dataset(df, 'What is the min and median of petal length?')

I face the same issue with pandas dataframes, how do I resolve this?

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

1 participant