[check] add import check and warning for pandas (#3944)

- as titled, add an `import` catch for pandas with a user suggestion
message.
fix_agent_callbacks
Mike Wang 1 year ago committed by GitHub
parent 71a337dac6
commit c26cf04110
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -26,10 +26,16 @@ def create_pandas_dataframe_agent(
**kwargs: Dict[str, Any],
) -> AgentExecutor:
"""Construct a pandas agent from an LLM and dataframe."""
import pandas as pd
try:
import pandas as pd
except ImportError:
raise ValueError(
"pandas package not found, please install with `pip install pandas`"
)
if not isinstance(df, pd.DataFrame):
raise ValueError(f"Expected pandas object, got {type(df)}")
if input_variables is None:
input_variables = ["df", "input", "agent_scratchpad"]
tools = [PythonAstREPLTool(locals={"df": df})]

Loading…
Cancel
Save