You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OS version: macOS 14.5
Python version: Python 3.10.7
The current version of pandasai being used: 2.2.12
🐛 Describe the bug
Bug: find_function_calls Fails to Detect Skills Used as Arguments in Higher-Order Functions
Description
The find_function_calls method in the CodeCleaning class is failing to detect skills that are used as arguments in higher-order functions, particularly when the skill produces a list or DataFrame as output.
Current Behavior
When a skill is passed as an argument to a method like pandas.DataFrame.apply(), the current implementation of find_function_calls does not recognize it as a used skill.
Expected Behavior
The method should detect and record all uses of skills, including when they are passed as arguments to higher-order functions.
Example
Consider a skill that produces a list as output:
@skilldefcalculate_salary_percentiles(salaries: list[int]) ->list[float]:
""" Calculates the 25th, 50th and 75th percentiles of salaries. Args: salaries (list[int]): List of employee salaries Returns: list[float]: A list containing the 25th, 50th, and 75th percentiles """importnumpyasnppercentiles=np.percentile(salaries, [25, 50, 75])
returnpercentiles.tolist()
When this skill is used in a DataFrame operation like:
To address the issue where the find_function_calls method fails to detect skills used as arguments in higher-order functions, you can modify the method to recursively check for function calls within the arguments of other function calls. Here is the updated implementation:
deffind_function_calls(self, node: ast.AST, context: CodeExecutionContext):
ifisinstance(node, ast.Call):
ifisinstance(node.func, ast.Name):
ifcontext.skills_manager.skill_exists(node.func.id):
context.skills_manager.add_used_skill(node.func.id)
elifisinstance(node.func, ast.Attribute) andisinstance(node.func.value, ast.Name):
context.skills_manager.add_used_skill(f"{node.func.value.id}.{node.func.attr}")
# Check for skills used as arguments in higher-order functionsforarginnode.args:
ifisinstance(arg, ast.Name) andcontext.skills_manager.skill_exists(arg.id):
context.skills_manager.add_used_skill(arg.id)
elifisinstance(arg, ast.Call):
self.find_function_calls(arg, context)
forchild_nodeinast.iter_child_nodes(node):
self.find_function_calls(child_node, context)
This modification ensures that the method recursively checks for function calls within the arguments of other function calls, thereby detecting and recording skills used as arguments in higher-order functions [1].
System Info
OS version: macOS 14.5
Python version: Python 3.10.7
The current version of pandasai being used: 2.2.12
🐛 Describe the bug
Bug:
find_function_calls
Fails to Detect Skills Used as Arguments in Higher-Order FunctionsDescription
The
find_function_calls
method in theCodeCleaning
class is failing to detect skills that are used as arguments in higher-order functions, particularly when the skill produces a list or DataFrame as output.Current Behavior
When a skill is passed as an argument to a method like
pandas.DataFrame.apply()
, the current implementation offind_function_calls
does not recognize it as a used skill.Expected Behavior
The method should detect and record all uses of skills, including when they are passed as arguments to higher-order functions.
Example
Consider a skill that produces a list as output:
When this skill is used in a DataFrame operation like:
The current
find_function_calls
method fails to detectcalculate_salary_percentiles
as a used skill.Current Implementation
Proposed Fix
To address this issue, we need to extend the method to check function arguments:
The text was updated successfully, but these errors were encountered: