Changeset 1365:5515c4c64b15 in orange-bioinformatics


Ignore:
Timestamp:
04/11/11 10:40:45 (3 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
a79bd252c022b8e8c9557ed29112e2018740b136
Message:

Show an error message when data has no suitable feature labels.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • widgets/prototypes/OWGenotypeDistances.py

    r1364 r1365  
    214214        self.matrix = None 
    215215         
     216    def get_suitable_keys(self, data): 
     217        """ Return suitable attr label keys from the data where the key has at least 
     218        two unique values in the data. 
     219         
     220        """ 
     221        attrs = [attr.attributes.items() for attr in data.domain.attributes] 
     222        attrs = reduce(set.union, attrs, set()) 
     223        values = defaultdict(set) 
     224        for key, value in attrs: 
     225            values[key].add(value) 
     226        keys = [key for key in values if len(values[key]) > 1] 
     227        return keys 
     228         
    216229    def set_data(self, data=None): 
    217230        """ Set the input example table. 
     
    220233        self.clear() 
    221234        self.data = data 
     235        self.error(0) 
     236        if data and not self.get_suitable_keys(data): 
     237            self.error(0, "Data has no suitable attribute labels.") 
     238            data = None 
     239             
    222240        if data: 
    223241            self.info_box.setText("Table with:\n {0} instances\nand\n {1} features".format(len(data), len(data.domain))) 
     
    341359            attrs = [get_attr(attr_index, i) for i, attr_index in enumerate(indices)] 
    342360            domain = Orange.data.Domain(attrs, None) 
    343             newdata = Orange.data.Table(domain, self.data) 
     361            newdata = Orange.data.Table(domain)#, self.data) 
    344362            split_data.append((keys, newdata)) 
    345363             
Note: See TracChangeset for help on using the changeset viewer.