Skip to content

Commit 5a2519c

Browse files
committed
Merge branch 'github-issue-20'
2 parents bfcd9f9 + c5c548a commit 5a2519c

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

cluster/linkage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def newfun(a, b, distance_function):
2828
def single(a, b, distance_function):
2929
"""
3030
Given two collections ``a`` and ``b``, this will return the distance of the
31-
points which are closest togetger. ``distance_function`` is used to
31+
points which are closest together. ``distance_function`` is used to
3232
determine the distance between two elements.
3333
3434
Example::

cluster/matrix.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def worker(self):
5757
tasks_completed = 0
5858
for task in iter(self.task_queue.get, 'STOP'):
5959
col_index, item, item2 = task
60-
if not hasattr(item, '__iter__'):
60+
if not hasattr(item, '__iter__') or isinstance(item, tuple):
6161
item = [item]
62-
if not hasattr(item2, '__iter__'):
62+
if not hasattr(item2, '__iter__') or isinstance(item2, tuple):
6363
item2 = [item2]
6464
result = (col_index, self.combinfunc(item, item2))
6565
self.done_queue.put(result)
@@ -123,9 +123,9 @@ def genmatrix(self, num_processes=1):
123123
num_tasks_completed += 1
124124
else:
125125
# Otherwise do it here, in line
126-
if not hasattr(item, '__iter__'):
126+
if not hasattr(item, '__iter__') or isinstance(item, tuple):
127127
item = [item]
128-
if not hasattr(item2, '__iter__'):
128+
if not hasattr(item2, '__iter__') or isinstance(item2, tuple):
129129
item2 = [item2]
130130
row[col_index] = self.combinfunc(item, item2)
131131

cluster/test/test_hierarchical.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"""
2727

2828
from difflib import SequenceMatcher
29+
from math import sqrt
2930
from sys import hexversion
3031
import unittest
3132

@@ -219,6 +220,25 @@ def testUnmodifiedData(self):
219220
self.assertEqual(sorted(new_data), sorted(self.__data))
220221

221222

223+
class HClusterTuplesTestCase(Py23TestCase):
224+
'''
225+
Test case to cover the case where the data contains tuple-items
226+
227+
See Github issue #20
228+
'''
229+
230+
def testSingleLinkage(self):
231+
"Basic Hierarchical Clustering test with integers"
232+
233+
def euclidian_distance(a, b):
234+
return sqrt(sum([pow(z[0] - z[1], 2) for z in zip(a, b)]))
235+
236+
self.__data = [(1, 1), (1, 2), (1, 3)]
237+
cl = HierarchicalClustering(self.__data, euclidian_distance)
238+
result = cl.getlevel(40)
239+
self.assertIsNotNone(result)
240+
241+
222242
if __name__ == '__main__':
223243
suite = unittest.TestSuite((
224244
unittest.makeSuite(HClusterIntegerTestCase),

cluster/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3.0
1+
1.3.1

0 commit comments

Comments
 (0)