Changeset 10738:4f410edd688e in orange


Ignore:
Timestamp:
04/04/12 09:46:36 (2 years ago)
Author:
Matija Polajnar <matija.polajnar@…>
Branch:
default
Message:

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

Location:
Orange/OrangeWidgets/Unsupervised
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeWidgets/Unsupervised/OWHierarchicalClustering.py

    r9671 r10738  
    311311            labels = [""] * len(items) 
    312312        elif self.Annotation == 1: 
    313             if isinstance(items, ExampleTable): 
    314                 labels = [str(i) for i in range(len(items))] 
    315             else: 
    316                 try: 
    317                     labels = [item.name for item in items] 
    318                 except AttributeError: 
    319                     labels = [str(item) for item in items] 
     313            try: 
     314                labels = [item.name for item in items] 
     315                if not any(labels): raise AttributeError("No labels.") 
     316            except AttributeError: 
     317                labels = [str(item) for item in items] 
    320318        elif self.Annotation > 1 and isinstance(items, ExampleTable): 
    321319            attr = self.labelInd[min(self.Annotation - 2, len(self.labelInd) - 1)] 
  • Orange/OrangeWidgets/Unsupervised/OWSaveDistanceFile.py

    r10466 r10738  
    6969        fn = open(file, 'w') 
    7070        fn.write("%d labeled\n" % matrix.dim) 
    71          
     71 
     72        hasNames = all(hasattr(ex, "name") for ex in matrix.items) and \ 
     73                   any(ex.name for ex in matrix.items) 
    7274        for i in range(matrix.dim): 
    73             fn.write("%s" % matrix.items[i][0]) 
     75            fn.write("%s" % matrix.items[i].name if hasNames else str(matrix.items[i])) 
    7476            for j in range(i+1): 
    7577                fn.write("\t%.6f" % matrix[i,j]) 
Note: See TracChangeset for help on using the changeset viewer.