(self, var, values, transform=())
Set the variable to edit.

        `values` is needed for categorical features to perform grouping.
Set the variable to edit.
Set the variable to edit .
def set_data_categorical(self, var, values, transform=()):
        # type: (Optional[Categorical], Optional[Sequence[float]], Sequence[Transform]) -> None
        """
        Set the variable to edit.

        `values` is needed for categorical features to perform grouping.
        """
        # pylint: disable=too-many-branches
        super().set_data(var, transform=transform)
        self._values = values
        tr = None  # type: Optional[CategoriesMapping]
        for tr_ in transform:
            if isinstance(tr_, CategoriesMapping):
                tr = tr_

        items = []
        if tr is not None:
            ci_index = {c: i for i, c in enumerate(var.categories)}
            for ci, cj in tr.mapping:
                if ci is None and cj is not None:
                    # level added
                    item = {
                        Qt.EditRole: cj,
                        EditStateRole: ItemEditState.Added,
                        SourcePosRole: None
                    }
                elif ci is not None and cj is None:
                    # ci level dropped
                    item = {
                        Qt.EditRole: ci,
                        EditStateRole: ItemEditState.Dropped,
                        SourcePosRole: ci_index[ci],
                        SourceNameRole: ci
                    }
                elif ci is not None and cj is not None:
                    # rename or reorder
                    item = {
                        Qt.EditRole: cj,
                        EditStateRole: ItemEditState.NoState,
                        SourcePosRole: ci_index[ci],
                        SourceNameRole: ci
                    }
                else:
                    assert False, "invalid mapping: {!r}".format(tr.mapping)
                items.append(item)
        elif var is not None:
            items = [
                {Qt.EditRole: c,
                 EditStateRole: ItemEditState.NoState,
                 SourcePosRole: i,
                 SourceNameRole: c}
                for i, c in enumerate(var.categories)
            ]
        else:
            items = []

        with disconnected(self.values_model.dataChanged,
                          self.on_values_changed):
            self.values_model.clear()
            self.values_model.insertRows(0, len(items))
            for i, item in enumerate(items):
                self.values_model.setItemData(
                    self.values_model.index(i, 0),
                    item
                )

        self.add_new_item.actionGroup().setEnabled(var is not None)
def set_data_categorical ( self , var , values , transform = ( ) ) : # type: (Optional[Categorical], Optional[Sequence[float]], Sequence[Transform]) -> None # pylint: disable=too-many-branches super ( ) . set_data ( var , transform = transform ) self . _values = values tr = None # type: Optional[CategoriesMapping] for tr_ in transform : if isinstance ( tr_ , CategoriesMapping ) : tr = tr_ items = [ ] if tr is not None : ci_index = { c : i for i , c in enumerate ( var . categories ) } for ci , cj in tr . mapping : if ci is None and cj is not None : # level added item = { Qt . EditRole : cj , EditStateRole : ItemEditState . Added , SourcePosRole : None } elif ci is not None and cj is None : # ci level dropped item = { Qt . EditRole : ci , EditStateRole : ItemEditState . Dropped , SourcePosRole : ci_index [ ci ] , SourceNameRole : ci } elif ci is not None and cj is not None : # rename or reorder item = { Qt . EditRole : cj , EditStateRole : ItemEditState . NoState , SourcePosRole : ci_index [ ci ] , SourceNameRole : ci } else : assert False , "invalid mapping: {!r}" . format ( tr . mapping ) items . append ( item ) elif var is not None : items = [ { Qt . EditRole : c , EditStateRole : ItemEditState . NoState , SourcePosRole : i , SourceNameRole : c } for i , c in enumerate ( var . categories ) ] else : items = [ ] with disconnected ( self . values_model . dataChanged , self . on_values_changed ) : self . values_model . clear ( ) self . values_model . insertRows ( 0 , len ( items ) ) for i , item in enumerate ( items ) : self . values_model . setItemData ( self . values_model . index ( i , 0 ) , item ) self . add_new_item . actionGroup ( ) . setEnabled ( var is not None )