[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:
Mike Wang 2023-05-02 10:08:16 -07:00 committed by GitHub
parent 71a337dac6
commit c26cf04110
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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})]