(self, data=None)
Set the input dataset to display.
Set the input dataset to display.
Set the input dataset to display .
def set_dataset(self, data=None):
        """Set the input dataset to display."""
        self.closeContext()
        self.clear()
        self.clear_messages()

        if isinstance(data, SqlTable):
            if data.approx_len() < 4000:
                data = Table(data)
            else:
                self.Information.sampled()
                data_sample = data.sample_time(1, no_cache=True)
                data_sample.download_data(2000, partial=True)
                data = Table(data_sample)

        if data is not None and not len(data):
            data = None

        if data is not None and sp.issparse(data.X):
            try:
                data = data.to_dense()
            except MemoryError:
                data = None
                self.Error.not_enough_memory()
            else:
                self.Information.sparse_densified()

        input_data = data

        # Data contains no attributes or meta attributes only
        if data is not None and len(data.domain.attributes) == 0:
            self.Error.no_continuous()
            input_data = data = None

        # Data contains some discrete attributes which must be filtered
        if data is not None and \
                any(var.is_discrete for var in data.domain.attributes):
            ndisc = sum(var.is_discrete for var in data.domain.attributes)
            data = data.transform(
                Domain([var for var in data.domain.attributes
                        if var.is_continuous],
                       data.domain.class_vars,
                       data.domain.metas))
            if not data.domain.attributes:
                self.Error.no_continuous()
                input_data = data = None
            else:
                self.Information.discrete_ignored(
                    ndisc, "s" if ndisc > 1 else "")

        self.data = data
        self.input_data = input_data

        if data is not None:
            self.annotation_model.set_domain(self.input_data.domain)
            self.row_side_color_model.set_domain(self.input_data.domain)
            self.annotation_var = None
            self.annotation_color_var = None
            self.row_split_model.set_domain(data.domain)
            self.col_annot_data = data.transpose(data[:0].transform(Domain(data.domain.attributes)))
            self.col_split_model.set_domain(self.col_annot_data.domain)
            self.col_side_color_model.set_domain(self.col_annot_data.domain)
            if data.domain.has_discrete_class:
                self.split_by_var = data.domain.class_var
            else:
                self.split_by_var = None
            self.split_columns_var = None
            self.column_annotation_color_var = None
            self.openContext(self.input_data)
            if self.split_by_var not in self.row_split_model:
                self.split_by_var = None

            def match(desc: Tuple[str, str], source: Iterable[Variable]):
                for v in source:
                    if desc == (type(v).__name__, v.name):
                        return v
                return None

            def is_variable(obj):
                return isinstance(obj, Variable)

            if self.split_columns_key is not None:
                self.split_columns_var = match(
                    self.split_columns_key,
                    filter(is_variable, self.col_split_model)
                )

            if self.column_annotation_color_key is not None:
                self.column_annotation_color_var = match(
                    self.column_annotation_color_key,
                    filter(is_variable, self.col_side_color_model)
                )

        self.update_heatmaps()
        if data is not None and self.__pending_selection is not None:
            if self.scene.widget is not None:
                self.scene.widget.selectRows(self.__pending_selection)
            self.selected_rows = self.__pending_selection
            self.__pending_selection = None

        self.commit.now()
def set_dataset ( self , data = None ) : self . closeContext ( ) self . clear ( ) self . clear_messages ( ) if isinstance ( data , SqlTable ) : if data . approx_len ( ) < 4000 : data = Table ( data ) else : self . Information . sampled ( ) data_sample = data . sample_time ( 1 , no_cache = True ) data_sample . download_data ( 2000 , partial = True ) data = Table ( data_sample ) if data is not None and not len ( data ) : data = None if data is not None and sp . issparse ( data . X ) : try : data = data . to_dense ( ) except MemoryError : data = None self . Error . not_enough_memory ( ) else : self . Information . sparse_densified ( ) input_data = data # Data contains no attributes or meta attributes only if data is not None and len ( data . domain . attributes ) == 0 : self . Error . no_continuous ( ) input_data = data = None # Data contains some discrete attributes which must be filtered if data is not None and any ( var . is_discrete for var in data . domain . attributes ) : ndisc = sum ( var . is_discrete for var in data . domain . attributes ) data = data . transform ( Domain ( [ var for var in data . domain . attributes if var . is_continuous ] , data . domain . class_vars , data . domain . metas ) ) if not data . domain . attributes : self . Error . no_continuous ( ) input_data = data = None else : self . Information . discrete_ignored ( ndisc , "s" if ndisc > 1 else "" ) self . data = data self . input_data = input_data if data is not None : self . annotation_model . set_domain ( self . input_data . domain ) self . row_side_color_model . set_domain ( self . input_data . domain ) self . annotation_var = None self . annotation_color_var = None self . row_split_model . set_domain ( data . domain ) self . col_annot_data = data . transpose ( data [ : 0 ] . transform ( Domain ( data . domain . attributes ) ) ) self . col_split_model . set_domain ( self . col_annot_data . domain ) self . col_side_color_model . set_domain ( self . col_annot_data . domain ) if data . domain . has_discrete_class : self . split_by_var = data . domain . class_var else : self . split_by_var = None self . split_columns_var = None self . column_annotation_color_var = None self . openContext ( self . input_data ) if self . split_by_var not in self . row_split_model : self . split_by_var = None def match ( desc : Tuple [ str , str ] , source : Iterable [ Variable ] ) : for v in source : if desc == ( type ( v ) . __name__ , v . name ) : return v return None def is_variable ( obj ) : return isinstance ( obj , Variable ) if self . split_columns_key is not None : self . split_columns_var = match ( self . split_columns_key , filter ( is_variable , self . col_split_model ) ) if self . column_annotation_color_key is not None : self . column_annotation_color_var = match ( self . column_annotation_color_key , filter ( is_variable , self . col_side_color_model ) ) self . update_heatmaps ( ) if data is not None and self . __pending_selection is not None : if self . scene . widget is not None : self . scene . widget . selectRows ( self . __pending_selection ) self . selected_rows = self . __pending_selection self . __pending_selection = None self . commit . now ( )