Example #1
0
def GroupByLevel(NTree, sdict):
    #Levels = [NTree.subtrees.keys()]
    Levels = EqualLevels(NTree.subtrees.keys(), sdict)
    LowerLevels = [GroupByLevel(t, sdict) for t in NTree.subtrees.values()]
    if len(LowerLevels) > 0:
        h = max([len(l) for l in LowerLevels])
        for i in range(h):
            New = utils.uniqify(utils.listunion([l[i] for l in LowerLevels 
                                                 if len(l) > i]))
            if len(New) > 0:
                Levels += [New]
    return Levels
Example #2
0
def GroupByLevel(NTree, sdict):
    #Levels = [NTree.subtrees.keys()]
    Levels = EqualLevels(NTree.subtrees.keys(), sdict)
    LowerLevels = [GroupByLevel(t, sdict) for t in NTree.subtrees.values()]
    if len(LowerLevels) > 0:
        h = max([len(l) for l in LowerLevels])
        for i in range(h):
            New = utils.uniqify(
                utils.listunion([l[i] for l in LowerLevels if len(l) > i]))
            if len(New) > 0:
                Levels += [New]
    return Levels
Example #3
0
    def deletecols(self, cols):
        """
        Delete columns and/or colors.

        Method wraps::

                tabular.spreadsheet.deletecols(self, cols)

        """
        deletenames = utils.uniqify(utils.listunion([[c] if c in 
        self.dtype.names else self.coloring[c] for c in cols]))
        return spreadsheet.deletecols(self,deletenames)
Example #4
0
    def __getitem__(self, ind):
        """
        Returns a subrectangle of the table.

        The representation of the subrectangle depends on `type(ind)`. Also, 
        whether the returned object represents a new independent copy of the 
        subrectangle, or a "view" into this self object, depends on 
        `type(ind)`.

        *	If you pass the name of an existing coloring, you get a tabarray 
        	consisting of copies of columns in that coloring.

        *	If you pass a list of existing coloring names and/or column names, 
        	you get a tabarray consisting of copies of columns in the list 
        	(name of coloring is equivalent to list of names of columns in that 
        	coloring; duplicate columns are deleted).

        *	If you pass a :class:`numpy.ndarray`, you get a tabarray consisting 
        	a subrectangle of the tabarray, as handled by  
        	:func:`numpy.ndarray.__getitem__`:

                *	if you pass a 1D NumPy ndarray of booleans of `len(self)`,    
                	the rectangle contains copies of the rows for which the 
                	corresponding entry is `True`.

                *	if you pass a list of row numbers, you get a tabarray
                	containing copies of these rows.

        """
        if ind in self.coloring.keys():
            return self[self.coloring[ind]]
        elif isinstance(ind, list) and self.dtype.names and \
            all([a in self.dtype.names or a in self.coloring.keys()
                 for a in ind]) and \
            set(self.coloring.keys()).intersection(ind):
            ns = utils.uniqify(
                utils.listunion(
                    [[a] if a in self.dtype.names else self.coloring[a]
                     for a in ind]))
            return self[ns]
        else:
            D = np.ndarray.__getitem__(self, ind)
            if isinstance(D, np.ndarray) and not (D.dtype.names is None):
                D = D.view(tabarray)
                D.coloring = dict([(
                    k,
                    list(
                        set(self.coloring[k]).intersection(set(D.dtype.names)))
                ) for k in self.coloring.keys() if len(
                    set(self.coloring[k]).intersection(set(D.dtype.names))) > 0
                                   ])
            return D
Example #5
0
    def __getitem__(self, ind):
        """
        Returns a subrectangle of the table.

        The representation of the subrectangle depends on `type(ind)`. Also, 
        whether the returned object represents a new independent copy of the 
        subrectangle, or a "view" into this self object, depends on 
        `type(ind)`.

        *	If you pass the name of an existing coloring, you get a tabarray 
        	consisting of copies of columns in that coloring.

        *	If you pass a list of existing coloring names and/or column names, 
        	you get a tabarray consisting of copies of columns in the list 
        	(name of coloring is equivalent to list of names of columns in that 
        	coloring; duplicate columns are deleted).

        *	If you pass a :class:`numpy.ndarray`, you get a tabarray consisting 
        	a subrectangle of the tabarray, as handled by  
        	:func:`numpy.ndarray.__getitem__`:

                *	if you pass a 1D NumPy ndarray of booleans of `len(self)`,    
                	the rectangle contains copies of the rows for which the 
                	corresponding entry is `True`.

                *	if you pass a list of row numbers, you get a tabarray
                	containing copies of these rows.

        """
        if ind in self.coloring.keys():
            return self[self.coloring[ind]]
        elif isinstance(ind,list) and \
             all([a in self.dtype.names or a in self.coloring.keys() 
                                                           for a in ind]) and \
             set(self.coloring.keys()).intersection(ind):
            ns = utils.uniqify(utils.listunion([[a] if a in self.dtype.names 
                                          else self.coloring[a] for a in ind]))
            return self[ns]
        else:
            D = np.ndarray.__getitem__(self,ind)
            if isinstance(D,np.ndarray) and not D.dtype.names is None:
                D = D.view(tabarray)
                D.coloring = dict([(k, 
                list(set(self.coloring[k]).intersection(set(D.dtype.names)))) 
                for k in self.coloring.keys() if 
                len(set(self.coloring[k]).intersection(set(D.dtype.names))) > 0 
                and len(set(D.dtype.names).difference(self.coloring[k])) > 0])
            return D
Example #6
0
    def __init__(self, names, sdict):

        self.topnodes = set(names).difference(utils.listunion(sdict.values()))

        self.subtrees = {}
        SK = sdict.keys() ; SK.sort()
        done = []
        for (i,s) in enumerate(SK):
            if not any([set(sdict[s]) < set(sdict[ss])  for ss in SK]):
                subsets = [ss for ss in sdict.keys() 
                           if set(sdict[ss]) < set(sdict[s])]
                newsdict = dict([(ss, list(set(sdict[ss]).difference(done))) 
                                 for ss in subsets])
                newnames = list(set(sdict[s]))#.difference(done))
                if len(newnames) > 0:
                    self.subtrees[s] = NameTree(newnames, newsdict)
                    done += newnames

        self.weight = (sum([t.weight for t in self.subtrees.values()]) + 
                       len(self.topnodes))
Example #7
0
def Testlistunion():
    Input = [[2, 3, 4], [4, 5, 6], [6, 4, 2]]
    Output = [2, 3, 4, 4, 5, 6, 6, 4, 2]
    assert (Output == listunion(Input))