(self)
Apply the changes to the input data and send the changed data to output.
Apply the changes to the input data and send the changed data to output.
Apply the changes to the input data and send the changed data to output .
def commit(self):
        """
        Apply the changes to the input data and send the changed data to output.
        """
        self._set_modified(False)
        self.Error.duplicate_var_name.clear()

        data = self.data
        if data is None:
            self.Outputs.data.send(None)
            return
        model = self.variables_model

        def state(i):
            # type: (int) -> Tuple[DataVector, List[Transform]]
            midx = self.variables_model.index(i, 0)
            return (model.data(midx, Qt.EditRole),
                    model.data(midx, TransformRole))

        state = [state(i) for i in range(model.rowCount())]
        input_vars = data.domain.variables + data.domain.metas
        if self.output_table_name in ("", data.name) \
                and not any(requires_transform(var, trs)
                            for var, (_, trs) in zip(input_vars, state)):
            self.Outputs.data.send(data)
            return

        assert all(v_.vtype.name == v.name
                   for v, (v_, _) in zip(input_vars, state))
        output_vars = []
        unlinked_vars = []
        unlink_domain = False
        for (_, tr), v in zip(state, input_vars):
            if tr:
                var = apply_transform(v, data, tr)
                if requires_unlink(v, tr):
                    unlinked_var = var.copy(compute_value=None)
                    unlink_domain = True
                else:
                    unlinked_var = var
            else:
                unlinked_var = var = v
            output_vars.append(var)
            unlinked_vars.append(unlinked_var)

        if len(output_vars) != len({v.name for v in output_vars}):
            self.Error.duplicate_var_name()
            self.Outputs.data.send(None)
            return

        domain = data.domain
        nx = len(domain.attributes)
        ny = len(domain.class_vars)

        def construct_domain(vars_list):
            # Move non primitive Xs, Ys to metas (if they were changed)
            Xs = [v for v in vars_list[:nx] if v.is_primitive()]
            Ys = [v for v in vars_list[nx: nx + ny] if v.is_primitive()]
            Ms = vars_list[nx + ny:] + \
                 [v for v in vars_list[:nx + ny] if not  v.is_primitive()]
            return Orange.data.Domain(Xs, Ys, Ms)

        domain = construct_domain(output_vars)
        new_data = data.transform(domain)
        if unlink_domain:
            unlinked_domain = construct_domain(unlinked_vars)
            new_data = new_data.from_numpy(
                unlinked_domain,
                new_data.X, new_data.Y, new_data.metas, new_data.W,
                new_data.attributes, new_data.ids
            )
        if self.output_table_name:
            new_data.name = self.output_table_name
        self.Outputs.data.send(new_data)
def commit ( self ) : self . _set_modified ( False ) self . Error . duplicate_var_name . clear ( ) data = self . data if data is None : self . Outputs . data . send ( None ) return model = self . variables_model def state ( i ) : # type: (int) -> Tuple[DataVector, List[Transform]] midx = self . variables_model . index ( i , 0 ) return ( model . data ( midx , Qt . EditRole ) , model . data ( midx , TransformRole ) ) state = [ state ( i ) for i in range ( model . rowCount ( ) ) ] input_vars = data . domain . variables + data . domain . metas if self . output_table_name in ( "" , data . name ) and not any ( requires_transform ( var , trs ) for var , ( _ , trs ) in zip ( input_vars , state ) ) : self . Outputs . data . send ( data ) return assert all ( v_ . vtype . name == v . name for v , ( v_ , _ ) in zip ( input_vars , state ) ) output_vars = [ ] unlinked_vars = [ ] unlink_domain = False for ( _ , tr ) , v in zip ( state , input_vars ) : if tr : var = apply_transform ( v , data , tr ) if requires_unlink ( v , tr ) : unlinked_var = var . copy ( compute_value = None ) unlink_domain = True else : unlinked_var = var else : unlinked_var = var = v output_vars . append ( var ) unlinked_vars . append ( unlinked_var ) if len ( output_vars ) != len ( { v . name for v in output_vars } ) : self . Error . duplicate_var_name ( ) self . Outputs . data . send ( None ) return domain = data . domain nx = len ( domain . attributes ) ny = len ( domain . class_vars ) def construct_domain ( vars_list ) : # Move non primitive Xs, Ys to metas (if they were changed) Xs = [ v for v in vars_list [ : nx ] if v . is_primitive ( ) ] Ys = [ v for v in vars_list [ nx : nx + ny ] if v . is_primitive ( ) ] Ms = vars_list [ nx + ny : ] + [ v for v in vars_list [ : nx + ny ] if not v . is_primitive ( ) ] return Orange . data . Domain ( Xs , Ys , Ms ) domain = construct_domain ( output_vars ) new_data = data . transform ( domain ) if unlink_domain : unlinked_domain = construct_domain ( unlinked_vars ) new_data = new_data . from_numpy ( unlinked_domain , new_data . X , new_data . Y , new_data . metas , new_data . W , new_data . attributes , new_data . ids ) if self . output_table_name : new_data . name = self . output_table_name self . Outputs . data . send ( new_data )