Commits

Matija Polajnar committed 4f410ed

Make 'save distance file' and 'hierarchical clustering' widgets respect the
label attribute selected in the 'example distance' widget.

Comments (0)

Files changed (2)

Orange/OrangeWidgets/Unsupervised/OWHierarchicalClustering.py

         if self.Annotation == 0:
             labels = [""] * len(items)
         elif self.Annotation == 1:
-            if isinstance(items, ExampleTable):
-                labels = [str(i) for i in range(len(items))]
-            else:
-                try:
-                    labels = [item.name for item in items]
-                except AttributeError:
-                    labels = [str(item) for item in items]
+            try:
+                labels = [item.name for item in items]
+                if not any(labels): raise AttributeError("No labels.")
+            except AttributeError:
+                labels = [str(item) for item in items]
         elif self.Annotation > 1 and isinstance(items, ExampleTable):
             attr = self.labelInd[min(self.Annotation - 2, len(self.labelInd) - 1)]
             labels = [str(ex[attr]) for ex in items]

Orange/OrangeWidgets/Unsupervised/OWSaveDistanceFile.py

     def saveSymMatrix(self, matrix, file):
         fn = open(file, 'w')
         fn.write("%d labeled\n" % matrix.dim)
-        
+
+        hasNames = all(hasattr(ex, "name") for ex in matrix.items) and \
+                   any(ex.name for ex in matrix.items)
         for i in range(matrix.dim):
-            fn.write("%s" % matrix.items[i][0])
+            fn.write("%s" % matrix.items[i].name if hasNames else str(matrix.items[i]))
             for j in range(i+1):
                 fn.write("\t%.6f" % matrix[i,j])
             fn.write("\n")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.