Skip to content

Commit f7ca4ba

Browse files
committed
PEP8 fixes (no code change).
1 parent 537267a commit f7ca4ba

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

cluster/method/hierarchical.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def __init__(self, data, distance_function, linkage=None):
4949
"""
5050
if not linkage:
5151
linkage = 'single'
52-
logger.info("Initializing HierarchicalClustering object with linkage method %s",
53-
linkage)
52+
logger.info("Initializing HierarchicalClustering object with linkage "
53+
"method %s", linkage)
5454
BaseClusterMethod.__init__(self, data, distance_function)
5555
self.set_linkage_method(linkage)
5656
self.__cluster_created = False
@@ -73,7 +73,7 @@ def set_linkage_method(self, method):
7373
self.linkage = self.uclus_distance
7474
else:
7575
raise ValueError('distance method must be one of single, '
76-
'complete, average of uclus')
76+
'complete, average of uclus')
7777

7878
def uclus_distance(self, x, y):
7979
"""
@@ -228,7 +228,7 @@ def cluster(self, matrix=None, level=None, sequence=None):
228228
# if we are not on the diagonal (which is always 0)
229229
# and if this cell represents a new minimum...
230230
if ((rowindex != cellindex) and
231-
(cell < mindistance or smallestpair is None)):
231+
(cell < mindistance or smallestpair is None)):
232232
smallestpair = (rowindex, cellindex)
233233
mindistance = cell
234234
cellindex += 1
@@ -237,7 +237,7 @@ def cluster(self, matrix=None, level=None, sequence=None):
237237
sequence += 1
238238
level = matrix[smallestpair[1]][smallestpair[0]]
239239
cluster = Cluster(level, self._data[smallestpair[0]],
240-
self._data[smallestpair[1]])
240+
self._data[smallestpair[1]])
241241

242242
# maintain the data, by combining the the two most similar items
243243
# in the list we use the min and max functions to ensure the
@@ -247,9 +247,9 @@ def cluster(self, matrix=None, level=None, sequence=None):
247247
# value of the second "remove" call, but we don't know the order
248248
# in which they come. The max and min approach clarifies that
249249
self._data.remove(self._data[max(smallestpair[0],
250-
smallestpair[1])]) # remove item 1
250+
smallestpair[1])]) # remove item 1
251251
self._data.remove(self._data[min(smallestpair[0],
252-
smallestpair[1])]) # remove item 2
252+
smallestpair[1])]) # remove item 2
253253
self._data.append(cluster) # append item 1 and 2 combined
254254

255255
# all the data is in one single cluster. We return that and stop
@@ -277,4 +277,4 @@ def getlevel(self, threshold):
277277
if not self.__cluster_created:
278278
self.cluster()
279279

280-
return self._data[0].getlevel(threshold)
280+
return self._data[0].getlevel(threshold)

cluster/method/kmeans.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ def __init__(self, data, distance=None, equality=None):
5757
for item in data[1:]:
5858
if len(item) != control_length:
5959
raise ValueError("Each item in the data list must have "
60-
"the same amount of dimensions. Item %r was out "
61-
"of line!" % (item,))
60+
"the same amount of dimensions. Item "
61+
"%r was out of line!" % (item,))
6262
# now check if we need and have a distance function
6363
if (len(data) > 1 and not isinstance(data[0], tuple) and
6464
distance is None):
6565
raise ValueError("You supplied non-standard items but no "
66-
"distance function! We cannot continue!")
66+
"distance function! We cannot continue!")
6767
# we now know that we have tuples, and assume therefore that it's
6868
# items are numeric
6969
elif distance is None:
@@ -81,7 +81,8 @@ def getclusters(self, count):
8181
# only proceed if we got sensible input
8282
if count <= 1:
8383
raise ClusteringError("When clustering, you need to ask for at "
84-
"least two clusters! You asked for %d" % count)
84+
"least two clusters! "
85+
"You asked for %d" % count)
8586

8687
# return the data straight away if there is nothing to cluster
8788
if (self.__data == [] or len(self.__data) == 1 or
@@ -90,9 +91,10 @@ def getclusters(self, count):
9091

9192
# It makes no sense to ask for more clusters than data-items available
9293
if count > self.__initial_length:
93-
raise ClusteringError("Unable to generate more clusters than "
94-
"items available. You supplied %d items, and asked for "
95-
"%d clusters." % (self.__initial_length, count) )
94+
raise ClusteringError(
95+
"Unable to generate more clusters than "
96+
"items available. You supplied %d items, and asked for "
97+
"%d clusters." % (self.__initial_length, count))
9698

9799
self.initialise_clusters(self.__data, count)
98100

@@ -119,8 +121,8 @@ def assign_item(self, item, origin):
119121
"""
120122
closest_cluster = origin
121123
for cluster in self.__clusters:
122-
if self.distance(item, centroid(cluster)) < self.distance(item,
123-
centroid(closest_cluster)):
124+
if self.distance(item, centroid(cluster)) < self.distance(
125+
item, centroid(closest_cluster)):
124126
closest_cluster = cluster
125127

126128
if id(closest_cluster) != id(origin):

0 commit comments

Comments
 (0)