Skip to content

Commit e25e53d

Browse files
authored
Update to match current sklearn dist_metric.pyx per issue #222
1 parent 486d24c commit e25e53d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

hdbscan/dist_metrics.pyx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,14 @@ cdef class PyFuncDistance(DistanceMetric):
11371137
cdef np.ndarray x2arr
11381138
x1arr = _buffer_to_ndarray(x1, size)
11391139
x2arr = _buffer_to_ndarray(x2, size)
1140-
return self.func(x1arr, x2arr, **self.kwargs)
1140+
d = self.func(x1arr, x2arr, **self.kwargs)
1141+
try:
1142+
# Cython generates code here that results in a TypeError
1143+
# if d is the wrong type.
1144+
return d
1145+
except TypeError:
1146+
raise TypeError("Custom distance function must accept two "
1147+
"vectors and return a float.")
11411148

11421149

11431150
cdef inline double fmax(double a, double b) nogil:

0 commit comments

Comments
 (0)