Skip to content
Snippets Groups Projects
Unverified Commit bd8e39ff authored by Ayush Lall's avatar Ayush Lall Committed by GitHub
Browse files

[Fix]: PandasQueryEngine can now execute 'pd.*' functions (#12240)

parent f513d6c2
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,7 @@ def default_output_processor( ...@@ -30,6 +30,7 @@ def default_output_processor(
return output return output
local_vars = {"df": df} local_vars = {"df": df}
global_vars = {"np": np, "pd": pd}
output = parse_code_markdown(output, only_last=True)[0] output = parse_code_markdown(output, only_last=True)[0]
...@@ -44,13 +45,13 @@ def default_output_processor( ...@@ -44,13 +45,13 @@ def default_output_processor(
if module_end_str.strip("'\"") != module_end_str: if module_end_str.strip("'\"") != module_end_str:
# if there's leading/trailing quotes, then we need to eval # if there's leading/trailing quotes, then we need to eval
# string to get the actual expression # string to get the actual expression
module_end_str = safe_eval(module_end_str, {"np": np}, local_vars) module_end_str = safe_eval(module_end_str, global_vars, local_vars)
try: try:
# str(pd.dataframe) will truncate output by display.max_colwidth # str(pd.dataframe) will truncate output by display.max_colwidth
# set width temporarily to extract more text # set width temporarily to extract more text
if "max_colwidth" in output_kwargs: if "max_colwidth" in output_kwargs:
pd.set_option("display.max_colwidth", output_kwargs["max_colwidth"]) pd.set_option("display.max_colwidth", output_kwargs["max_colwidth"])
output_str = str(safe_eval(module_end_str, {"np": np}, local_vars)) output_str = str(safe_eval(module_end_str, global_vars, local_vars))
pd.reset_option("display.max_colwidth") pd.reset_option("display.max_colwidth")
return output_str return output_str
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment