Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Optional

import cloudpickle
import numpy as np

from executorlib.standalone.select import FutureSelector

Expand Down Expand Up @@ -245,6 +244,8 @@ def export_dependency_graph_function(
edge_lst (list): List of edges.
file_name (str): Name of the file to store the exported graph in.
"""
import numpy as np

Comment on lines +247 to +248
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Handle ImportError to make numpy truly optional.

The local import achieves lazy loading but doesn't make numpy optional. If numpy is not installed, the function will raise an ImportError when called. To align with the PR objective ("Do not require numpy"), wrap the import in a try-except block and conditionally handle numpy-specific operations.

🔧 Proposed fix to handle missing numpy gracefully
-    import numpy as np
-
+    try:
+        import numpy as np
+        HAS_NUMPY = True
+    except ImportError:
+        HAS_NUMPY = False
+
     pwd_nodes_lst = []
     for n in node_lst:
         if n["type"] == "function":
             pwd_nodes_lst.append(
                 {"id": n["id"], "type": n["type"], "value": n["value"]}
             )
-        elif n["type"] == "input" and isinstance(n["value"], np.ndarray):
+        elif HAS_NUMPY and n["type"] == "input" and isinstance(n["value"], np.ndarray):
             pwd_nodes_lst.append(
                 {
                     "id": n["id"],
🤖 Prompt for AI Agents
In @src/executorlib/task_scheduler/interactive/dependency_plot.py around lines
247 - 248, The module currently does a direct local import "import numpy as np"
which will raise ImportError if numpy is absent; wrap that import in a
try/except ImportError and set np = None on failure, then update any functions
in dependency_plot.py that use numpy to check for np is not None before
performing numpy-specific operations (or raise a clear RuntimeError advising the
user to install numpy), ensuring the module remains importable when numpy is not
installed.

pwd_nodes_lst = []
for n in node_lst:
if n["type"] == "function":
Expand Down