Skip to content

Commit f932878

Browse files
committed
catch import error in tests
1 parent a4b846d commit f932878

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

fast_hdbscan/branches.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def fit(self, clusterer, labels=None, probabilities=None, sample_weight=None):
116116
self.probabilities_,
117117
self.cluster_probabilities_,
118118
self.cluster_points_,
119-
self.linkage_trees_,
119+
self._linkage_trees,
120120
label_sides_as_branches=self.label_sides_as_branches,
121121
)
122122
self.branch_labels_ = self.sub_cluster_labels_
@@ -135,7 +135,7 @@ def propagated_labels(self, label_sides_as_branches=None):
135135
np.zeros_like(self.probabilities_),
136136
np.zeros_like(self.probabilities_),
137137
self.cluster_points_,
138-
self.linkage_trees_,
138+
self._linkage_trees,
139139
label_sides_as_branches=label_sides_as_branches,
140140
)
141141
return labels, branch_labels

fast_hdbscan/tests/test_branches.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
from sklearn.exceptions import NotFittedError
88
from fast_hdbscan import HDBSCAN, BranchDetector, find_branch_sub_clusters
99

10+
try:
11+
from hdbscan.plots import ApproximationGraph, CondensedTree, SingleLinkageTree
12+
13+
HAVE_HDBSCAN = True
14+
except ModuleNotFoundError:
15+
HAVE_HDBSCAN = False
16+
1017

1118
def make_branches(points_per_branch=30):
1219
# Control points for line segments that merge three clusters
@@ -59,22 +66,15 @@ def check_detected_groups(c, n_clusters=3, n_branches=6, overridden=False):
5966
# --- Detecting Branches
6067

6168

69+
@pytest.mark.skipif(not HAVE_HDBSCAN, reason='Requires HDBSCAN')
6270
def test_attributes():
63-
def check_attributes():
64-
b = BranchDetector().fit(c)
65-
check_detected_groups(b, n_clusters=2, n_branches=5)
66-
assert len(b.linkage_trees_) == 2
67-
assert len(b.condensed_trees_) == 2
68-
assert isinstance(b.condensed_trees_[0], CondensedTree)
69-
assert isinstance(b.linkage_trees_[0], SingleLinkageTree)
70-
assert isinstance(b.approximation_graph_, ApproximationGraph)
71-
72-
try:
73-
from hdbscan.plots import ApproximationGraph, CondensedTree, SingleLinkageTree
74-
75-
check_attributes()
76-
except ImportError:
77-
pass
71+
b = BranchDetector().fit(c)
72+
check_detected_groups(b, n_clusters=2, n_branches=5)
73+
assert len(b.linkage_trees_) == 2
74+
assert len(b.condensed_trees_) == 2
75+
assert isinstance(b.condensed_trees_[0], CondensedTree)
76+
assert isinstance(b.linkage_trees_[0], SingleLinkageTree)
77+
assert isinstance(b.approximation_graph_, ApproximationGraph)
7878

7979

8080
def test_selection_method():

fast_hdbscan/tests/test_sub_clusters.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
from fast_hdbscan.branches import compute_centrality
77
from fast_hdbscan.sub_clusters import SubClusterDetector, find_sub_clusters
88

9+
try:
10+
from hdbscan.plots import ApproximationGraph, CondensedTree, SingleLinkageTree
11+
12+
HAVE_HDBSCAN = True
13+
except ModuleNotFoundError:
14+
HAVE_HDBSCAN = False
15+
916

1017
def make_branches(points_per_branch=30):
1118
# Control points for line segments that merge three clusters
@@ -59,22 +66,15 @@ def check_detected_groups(c, n_clusters=3, n_subs=6, overridden=False):
5966
# --- Detecting SubClusters
6067

6168

69+
@pytest.mark.skipif(not HAVE_HDBSCAN, reason='Requires HDBSCAN')
6270
def test_attributes():
63-
def check_attributes():
64-
b = SubClusterDetector(lens_values=centrality).fit(c)
65-
check_detected_groups(b, n_clusters=2, n_subs=7)
66-
assert len(b.linkage_trees_) == 2
67-
assert len(b.condensed_trees_) == 2
68-
assert isinstance(b.condensed_trees_[0], CondensedTree)
69-
assert isinstance(b.linkage_trees_[0], SingleLinkageTree)
70-
assert isinstance(b.approximation_graph_, ApproximationGraph)
71-
72-
try:
73-
from hdbscan.plots import ApproximationGraph, CondensedTree, SingleLinkageTree
74-
75-
check_attributes()
76-
except ImportError:
77-
pass
71+
b = SubClusterDetector(lens_values=centrality).fit(c)
72+
check_detected_groups(b, n_clusters=2, n_subs=7)
73+
assert len(b.linkage_trees_) == 2
74+
assert len(b.condensed_trees_) == 2
75+
assert isinstance(b.condensed_trees_[0], CondensedTree)
76+
assert isinstance(b.linkage_trees_[0], SingleLinkageTree)
77+
assert isinstance(b.approximation_graph_, ApproximationGraph)
7878

7979

8080
def test_selection_method():

0 commit comments

Comments
 (0)