Skip to content

Commit

Permalink
Merge pull request #586 from martinfleis/isomorph
Browse files Browse the repository at this point in the history
avoid could_be_isomorphic on nx 3.2
  • Loading branch information
martinfleis committed Oct 21, 2023
2 parents b9b58e3 + 88630b8 commit 0ea928a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions libpysal/graph/_set_ops.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np
import pandas

from packaging.version import Version

from ._utils import _resolve_islands


Expand Down Expand Up @@ -189,16 +191,19 @@ def isomorphic(self, right):
can be found to convert one graph into the other graph. Requires networkx.
"""
try:
from networkx.algorithms import isomorphism as iso
import networkx as nx
except ImportError:
raise ImportError("NetworkX is required to check for graph isomorphism")

nxleft = self.to_networkx()
nxright = right.to_networkx()

if not iso.faster_could_be_isomorphic(nxleft, nxright):
if not nx.faster_could_be_isomorphic(nxleft, nxright):
return False
elif not iso.could_be_isomorphic(nxleft, nxright):
elif not nx.could_be_isomorphic(nxleft, nxright):
# https://github.com/networkx/networkx/issues/7038
if Version(nx.__version__) == Version("3.2"):
return nx.is_isomorphic(nxleft, nxright)
return False
else:
return iso.is_isomorphic(nxleft, nxright)
return nx.is_isomorphic(nxleft, nxright)

0 comments on commit 0ea928a

Please sign in to comment.