Skip to content

Commit

Permalink
🐛 fix pyclustering conda imports
Browse files Browse the repository at this point in the history
  • Loading branch information
GiulioRossetti committed Jun 7, 2023
1 parent 8c47d8a commit f9de7ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
13 changes: 12 additions & 1 deletion cdlib/algorithms/overlapping_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from cdlib.algorithms.internal.SLPA_nx import slpa_nx
from cdlib.algorithms.internal.multicom import MultiCom
from cdlib.algorithms.internal.PercoMCV import percoMVC
from cdlib.algorithms.internal.LPAM import LPAM
from cdlib.algorithms.internal.core_exp import findCommunities as core_exp_find
from cdlib.algorithms.internal.weightedCommunity import weightedCommunity
from cdlib.algorithms.internal.LPANNI import LPANNI, GraphGenerator
Expand Down Expand Up @@ -73,6 +72,13 @@
ASLPAw = None
missing_packages.add("ASLPAw")

try:
import pyclustering
from cdlib.algorithms.internal.LPAM import LPAM
except ModuleNotFoundError:
LPAM = None
missing_packages.add("pyclustering")

report_missing_packages(missing_packages)

__all__ = [
Expand Down Expand Up @@ -1519,6 +1525,11 @@ def lpam(
Alexander Ponomarenko, Leonidas Pitsoulis, Marat Shamshetdinov. "Link Partitioning Around Medoids". https://arxiv.org/abs/1907.08731
"""
if LPAM is None:
raise ModuleNotFoundError(
"Optional dependency not satisfied: install pyclustering (pip install pyclustering). Not available in CDlib Conda-based installation."
)

g = convert_graph_formats(g_original, nx.Graph)
return LPAM(graph=g, k=k, threshold=threshold, distance=distance, seed=seed)

Expand Down
18 changes: 12 additions & 6 deletions cdlib/test/test_community_discovery_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
except ModuleNotFoundError:
by = None

try:
from cdlib.algorithms.internal.LPAM import LPAM
except ModuleNotFoundError:
LPAM = None


def get_string_graph():
g = nx.karate_club_graph()
Expand Down Expand Up @@ -778,13 +783,14 @@ def test_lpanni(self):
self.assertEqual(type(coms.communities[0][0]), int)

def test_lpam(self):
G = nx.karate_club_graph()
if LPAM is not None:
G = nx.karate_club_graph()

coms = algorithms.lpam(G, k=2, threshold=0.4, distance="amp")
self.assertEqual(type(coms.communities), list)
if len(coms.communities) > 0:
self.assertEqual(type(coms.communities[0]), list)
self.assertEqual(type(coms.communities[0][0]), int)
coms = algorithms.lpam(G, k=2, threshold=0.4, distance="amp")
self.assertEqual(type(coms.communities), list)
if len(coms.communities) > 0:
self.assertEqual(type(coms.communities[0]), list)
self.assertEqual(type(coms.communities[0][0]), int)

def test_dcs(self):
G = nx.karate_club_graph()
Expand Down

0 comments on commit f9de7ed

Please sign in to comment.