GraKeL
GraKeL copied to clipboard
Can't import GraKeL due to a numpy import error
Describe the bug When trying to import GraKel, I get an error due to a numpy import which doesn't seem to be located in the same place in the package anymore. I'm using numpy version 2.1.1
To Reproduce
Write import grakel in an empty file and run as a python script.
Expected behavior The script should run without any errors.
Stack Trace
{
"name": "ImportError",
"message": "cannot import name 'ComplexWarning' from 'numpy' (/home/edishasaj/.local/share/virtualenvs/GNN/lib64/python3.12/site-packages/numpy/__init__.py)",
"stack": "---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[6], line 1
----> 1 import grakel
3 gk_computer = grakel.GraphletSampling(k=5)
File ~/.local/share/virtualenvs/GNN/lib64/python3.12/site-packages/grakel/__init__.py:6
2 from grakel import datasets
4 from grakel.graph import Graph
----> 6 from grakel.graph_kernels import GraphKernel
9 from grakel.kernels import Kernel
11 from grakel.kernels import GraphletSampling
File ~/.local/share/virtualenvs/GNN/lib64/python3.12/site-packages/grakel/graph_kernels.py:13
10 from sklearn.utils import check_random_state
11 from sklearn.utils.validation import check_is_fitted
---> 13 from grakel.kernels import GraphletSampling
14 from grakel.kernels import RandomWalk
15 from grakel.kernels import RandomWalkLabeled
File ~/.local/share/virtualenvs/GNN/lib64/python3.12/site-packages/grakel/kernels/__init__.py:7
4 from grakel.kernels.kernel import Kernel
6 from grakel.kernels.graphlet_sampling import GraphletSampling
----> 7 from grakel.kernels.random_walk import RandomWalk
8 from grakel.kernels.random_walk import RandomWalkLabeled
9 from grakel.kernels.shortest_path import ShortestPath
File ~/.local/share/virtualenvs/GNN/lib64/python3.12/site-packages/grakel/kernels/random_walk.py:10
6 import numpy as np
8 from itertools import product
---> 10 from numpy import ComplexWarning
11 from numpy.linalg import inv
12 from numpy.linalg import eig
ImportError: cannot import name 'ComplexWarning' from 'numpy' (~/.local/share/virtualenvs/GNN/lib64/python3.12/site-packages/numpy/__init__.py)"
}
@edisnord please suggest a fix/pull-request probably a latest version problem. I suggest doing it the following way.
if np.__version__ < 'X':
from numpy import ComplexWarning
else:
from ... # the updated import