(self, domain, data, deduplicate=False)
Create domain (and dataset) from changes made in the widget.

        Returns
        -------

        Args:
            domain (Domain): original domain
            data (Table): original data
            deduplicate (bool): if True, variable names are deduplicated and
               the result contains an additional list with names of renamed
               variables

        Returns:
            (new_domain, [attribute_columns, class_var_columns, meta_columns])
            or
            (new_domain, [attribute_columns, class_var_columns, meta_columns], renamed)
Create domain (and dataset) from changes made in the widget.
Create domain ( and dataset ) from changes made in the widget .
def get_domain(self, domain, data, deduplicate=False):
        """
        Create domain (and dataset) from changes made in the widget.

        Returns
        -------

        Args:
            domain (Domain): original domain
            data (Table): original data
            deduplicate (bool): if True, variable names are deduplicated and
               the result contains an additional list with names of renamed
               variables

        Returns:
            (new_domain, [attribute_columns, class_var_columns, meta_columns])
            or
            (new_domain, [attribute_columns, class_var_columns, meta_columns], renamed)
        """
        # Allow type-checking with type() instead of isinstance() for exact comparison
        # pylint: disable=unidiomatic-typecheck
        variables = self.model().variables
        places = [[], [], []]  # attributes, class_vars, metas
        cols = [[], [], []]  # Xcols, Ycols, Mcols

        def numbers_are_round(var, col_data):
            if type(var) == ContinuousVariable:
                data = np.asarray(col_data.data)  # Works for dense and sparse
                data = data[~np.isnan(data)]
                return (data == data.astype(int)).all()
            return False

        # Exit early with original domain if the user didn't actually change anything
        if all((name == orig_var.name and tpe == type(orig_var) and place == orig_plc)
               for (name, tpe, place, _, _), (orig_var, orig_plc) in
               zip(variables,
                   chain(((at, Place.feature) for at in domain.attributes),
                         ((cl, Place.class_var) for cl in domain.class_vars),
                         ((mt, Place.meta) for mt in domain.metas)))):
            if deduplicate:
                return domain, [data.X, data.Y, data.metas], []
            else:
                return domain, [data.X, data.Y, data.metas]

        relevant_names = [var[0] for var in variables if var[2] != Place.skip]
        if deduplicate:
            renamed_iter = iter(get_unique_names_duplicates(relevant_names))
        else:
            renamed_iter = iter(relevant_names)
        renamed = []
        for (name, tpe, place, _, may_be_numeric), (orig_var, orig_plc) in \
                zip(variables,
                        chain([(at, Place.feature) for at in domain.attributes],
                              [(cl, Place.class_var) for cl in domain.class_vars],
                              [(mt, Place.meta) for mt in domain.metas])):
            if place == Place.skip:
                continue

            new_name = next(renamed_iter)
            if new_name != name and name not in renamed:
                renamed.append(name)

            col_data = self._get_column(data, orig_var, orig_plc)
            is_sparse = sp.issparse(col_data)

            if new_name == orig_var.name and tpe == type(orig_var):
                var = orig_var
            elif tpe == type(orig_var):
                var = orig_var.copy(name=new_name)
            elif tpe == DiscreteVariable:
                values = natural_sorted(
                    list(str(i) for i in unique(col_data)
                         if not self._is_missing(i))
                )
                round_numbers = numbers_are_round(orig_var, col_data)
                col_data = [np.nan if self._is_missing(x) else values.index(str(x))
                            for x in self._iter_vals(col_data)]
                if round_numbers:
                    values = [str(int(float(v))) for v in values]
                var = tpe(new_name, values)
                col_data = self._to_column(col_data, is_sparse)
            elif tpe == StringVariable:
                var = tpe.make(new_name)
                if type(orig_var) in [DiscreteVariable, TimeVariable]:
                    col_data = [orig_var.repr_val(x) if not np.isnan(x) else ""
                                for x in self._iter_vals(col_data)]
                elif type(orig_var) == ContinuousVariable:
                    round_numbers = numbers_are_round(orig_var, col_data)
                    col_data = ['' if np.isnan(x) else
                                str(int(x)) if round_numbers else
                                orig_var.repr_val(x)
                                for x in self._iter_vals(col_data)]
                # don't obey sparsity for StringVariable since they are
                # in metas which are transformed to dense below
                col_data = self._to_column(col_data, False, dtype=object)
            elif tpe == ContinuousVariable and type(orig_var) == DiscreteVariable:
                var = tpe.make(new_name)
                if may_be_numeric:
                    col_data = [np.nan if self._is_missing(x) else float(orig_var.values[int(x)])
                                for x in self._iter_vals(col_data)]
                col_data = self._to_column(col_data, is_sparse)
            else:
                var = tpe(new_name)
            places[place].append(var)
            cols[place].append(col_data)

        # merge columns for X, Y and metas
        feats = cols[Place.feature]
        X = self._merge(feats) if feats else np.empty((len(data), 0))
        Y = self._merge(cols[Place.class_var], force_dense=True)
        m = self._merge(cols[Place.meta], force_dense=True)
        domain = Domain(*places)
        if deduplicate:
            return domain, [X, Y, m], renamed
        else:
            return domain, [X, Y, m]
def get_domain ( self , domain , data , deduplicate = False ) : # Allow type-checking with type() instead of isinstance() for exact comparison # pylint: disable=unidiomatic-typecheck variables = self . model ( ) . variables places = [ [ ] , [ ] , [ ] ] # attributes, class_vars, metas cols = [ [ ] , [ ] , [ ] ] # Xcols, Ycols, Mcols def numbers_are_round ( var , col_data ) : if type ( var ) == ContinuousVariable : data = np . asarray ( col_data . data ) # Works for dense and sparse data = data [ ~ np . isnan ( data ) ] return ( data == data . astype ( int ) ) . all ( ) return False # Exit early with original domain if the user didn't actually change anything if all ( ( name == orig_var . name and tpe == type ( orig_var ) and place == orig_plc ) for ( name , tpe , place , _ , _ ) , ( orig_var , orig_plc ) in zip ( variables , chain ( ( ( at , Place . feature ) for at in domain . attributes ) , ( ( cl , Place . class_var ) for cl in domain . class_vars ) , ( ( mt , Place . meta ) for mt in domain . metas ) ) ) ) : if deduplicate : return domain , [ data . X , data . Y , data . metas ] , [ ] else : return domain , [ data . X , data . Y , data . metas ] relevant_names = [ var [ 0 ] for var in variables if var [ 2 ] != Place . skip ] if deduplicate : renamed_iter = iter ( get_unique_names_duplicates ( relevant_names ) ) else : renamed_iter = iter ( relevant_names ) renamed = [ ] for ( name , tpe , place , _ , may_be_numeric ) , ( orig_var , orig_plc ) in zip ( variables , chain ( [ ( at , Place . feature ) for at in domain . attributes ] , [ ( cl , Place . class_var ) for cl in domain . class_vars ] , [ ( mt , Place . meta ) for mt in domain . metas ] ) ) : if place == Place . skip : continue new_name = next ( renamed_iter ) if new_name != name and name not in renamed : renamed . append ( name ) col_data = self . _get_column ( data , orig_var , orig_plc ) is_sparse = sp . issparse ( col_data ) if new_name == orig_var . name and tpe == type ( orig_var ) : var = orig_var elif tpe == type ( orig_var ) : var = orig_var . copy ( name = new_name ) elif tpe == DiscreteVariable : values = natural_sorted ( list ( str ( i ) for i in unique ( col_data ) if not self . _is_missing ( i ) ) ) round_numbers = numbers_are_round ( orig_var , col_data ) col_data = [ np . nan if self . _is_missing ( x ) else values . index ( str ( x ) ) for x in self . _iter_vals ( col_data ) ] if round_numbers : values = [ str ( int ( float ( v ) ) ) for v in values ] var = tpe ( new_name , values ) col_data = self . _to_column ( col_data , is_sparse ) elif tpe == StringVariable : var = tpe . make ( new_name ) if type ( orig_var ) in [ DiscreteVariable , TimeVariable ] : col_data = [ orig_var . repr_val ( x ) if not np . isnan ( x ) else "" for x in self . _iter_vals ( col_data ) ] elif type ( orig_var ) == ContinuousVariable : round_numbers = numbers_are_round ( orig_var , col_data ) col_data = [ '' if np . isnan ( x ) else str ( int ( x ) ) if round_numbers else orig_var . repr_val ( x ) for x in self . _iter_vals ( col_data ) ] # don't obey sparsity for StringVariable since they are # in metas which are transformed to dense below col_data = self . _to_column ( col_data , False , dtype = object ) elif tpe == ContinuousVariable and type ( orig_var ) == DiscreteVariable : var = tpe . make ( new_name ) if may_be_numeric : col_data = [ np . nan if self . _is_missing ( x ) else float ( orig_var . values [ int ( x ) ] ) for x in self . _iter_vals ( col_data ) ] col_data = self . _to_column ( col_data , is_sparse ) else : var = tpe ( new_name ) places [ place ] . append ( var ) cols [ place ] . append ( col_data ) # merge columns for X, Y and metas feats = cols [ Place . feature ] X = self . _merge ( feats ) if feats else np . empty ( ( len ( data ) , 0 ) ) Y = self . _merge ( cols [ Place . class_var ] , force_dense = True ) m = self . _merge ( cols [ Place . meta ] , force_dense = True ) domain = Domain ( * places ) if deduplicate : return domain , [ X , Y , m ] , renamed else : return domain , [ X , Y , m ]