Skip to content

Commit f213cbe

Browse files
committed
__eq__ and __hash__ (TODO)
1 parent a5acdef commit f213cbe

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Orange/clustering/clustering.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ def predict(self, X):
5757
raise NotImplementedError(
5858
"This clustering algorithm does not support predicting.")
5959

60+
def __eq__(self, other):
61+
if self is other:
62+
return True
63+
print(self.labels, other.labels)
64+
return type(self) is type(other) \
65+
and self.projector == other.projector \
66+
and self.domain == other.domain \
67+
and self.original_domain == other.original_domain \
68+
and self.labels == other.labels
69+
70+
def __hash__(self):
71+
# TODO handle labels
72+
return hash((self.projector, self.domain, self.original_domain))
73+
6074

6175
class Clustering(metaclass=WrapperMeta):
6276
"""

Orange/clustering/kmeans.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ def __init__(self, projector):
1919
def predict(self, X):
2020
return self.projector.predict(X)
2121

22+
def __eq__(self, other):
23+
return super().__eq__(other) \
24+
and self.centroids == other.centroids \
25+
and self.k == other.k
26+
27+
def __hash__(self):
28+
# TODO self.centroids
29+
return hash((super().__hash__(), self.k))
30+
2231

2332
class KMeans(Clustering):
2433

0 commit comments

Comments
 (0)