mirror of
https://github.com/hwchase17/langchain.git
synced 2025-05-29 11:09:07 +00:00
[check] add import check and warning for pandas (#3944)
- as titled, add an `import` catch for pandas with a user suggestion message.
This commit is contained in:
parent
71a337dac6
commit
c26cf04110
@ -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…
Reference in New Issue
Block a user