Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check if whitelisted lib is actually exists in the additional deps #1499

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions pandasai/pipelines/chat/code_cleaning.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,23 +623,22 @@ def _check_imports(self, node: Union[ast.Import, ast.ImportFrom]):
if library == "pandas":
return

if (
library
in WHITELISTED_LIBRARIES + self._config.custom_whitelisted_dependencies
):
for alias in node.names:
self._additional_dependencies.append(
{
"module": module,
"name": alias.name,
"alias": alias.asname or alias.name,
}
)
return
whitelisted_libs = (
WHITELISTED_LIBRARIES + self._config.custom_whitelisted_dependencies
)

if library not in WHITELISTED_LIBRARIES:
if library not in whitelisted_libs:
raise BadImportError(
f"The library '{library}' is not in the list of whitelisted libraries. "
"To learn how to whitelist custom dependencies, visit: "
"https://docs.pandas-ai.com/custom-whitelisted-dependencies#custom-whitelisted-dependencies"
)

for alias in node.names:
self._additional_dependencies.append(
{
"module": module,
"name": alias.name,
"alias": alias.asname or alias.name,
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,11 @@ def test_custom_whitelisted_dependencies(
code_cleaning._config.custom_whitelisted_dependencies = ["my_custom_library"]
output = code_cleaning.execute(code, context=context, logger=logger)

print(code_cleaning._additional_dependencies)
assert output.output == "my_custom_library.do_something()"
assert (
code_cleaning._additional_dependencies[0]["module"] == "my_custom_library"
)
assert isinstance(output, LogicUnitOutput)
assert output.success
assert output.message == "Code Cleaned Successfully"
Expand Down
Loading