mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +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],
|
**kwargs: Dict[str, Any],
|
||||||
) -> AgentExecutor:
|
) -> AgentExecutor:
|
||||||
"""Construct a pandas agent from an LLM and dataframe."""
|
"""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):
|
if not isinstance(df, pd.DataFrame):
|
||||||
raise ValueError(f"Expected pandas object, got {type(df)}")
|
raise ValueError(f"Expected pandas object, got {type(df)}")
|
||||||
|
|
||||||
if input_variables is None:
|
if input_variables is None:
|
||||||
input_variables = ["df", "input", "agent_scratchpad"]
|
input_variables = ["df", "input", "agent_scratchpad"]
|
||||||
tools = [PythonAstREPLTool(locals={"df": df})]
|
tools = [PythonAstREPLTool(locals={"df": df})]
|
||||||
|
Loading…
Reference in New Issue
Block a user