示例#1
0
def index2permutation(index, lngth, *args):
    '''
        >>> index2permutation(62,5)
        [2, 3, 1, 0, 4]
        >>>
        >>> index2permutation(62,5,['a','b','c','d','e'])
        ['c', 'd', 'b', 'a', 'e']
        >>>
    '''
    rel_indexes = []
    n = lngth - 1
    while (index > 0):
        q = index // math.factorial(n)
        r = index % math.factorial(n)
        rel_indexes.append(q)
        n = n - 1
        index = r
    if (len(args) == 0):
        arr = elel.init_range(0, lngth, 1)
    else:
        arr = args[0]
    rel_indexes = elel.padding(rel_indexes, lngth, 0)
    abs_indexes = _relindex2absindex(rel_indexes)
    rslt = elel.select_seqs(arr, abs_indexes)
    return (rslt)
示例#2
0
def get_inherited_attrs(obj, *whiches):
    '''
        >>> class tst():
        ...     def __init__(self):
        ...         self._u = "_u"
        ...         self.u = "u"
        ...
        >>> t = tst()
        >>>
        >>> get_inherited_attrs(t,0)
        ['_u', 'u']
        >>>
        >>> get_inherited_attrs(t,1)
        ['__dict__', '__module__', '__weakref__']
        >>>
        >>> get_inherited_attrs(t,2)
        ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
        >>>
        >>> get_inherited_attrs(t,0,1)
        ['_u', 'u', '__dict__', '__module__', '__weakref__']
        >>>
    '''
    ownattrs_arr = get_attrs_chain(obj)
    rslt = elel.select_seqs(ownattrs_arr, whiches)
    rslt = elel.reduce_left(rslt, lambda acc, ele: acc + ele, [])
    if (len(rslt) == 1):
        return (rslt[0])
    else:
        return (rslt)
示例#3
0
def _col(df,colname,*args,**kwargs):
    clocs = _cn2clocs(colname,**kwargs)
    args = list(args)
    if(args.__len__()==0):
        pass
    else:
        clocs = elel.select_seqs(clocs,args)
    return(df.iloc[:,clocs])
示例#4
0
def _row(df,rowname,*args,**kwargs):
    rlocs = _rn2rlocs(rowname,**kwargs)
    args = list(args)
    if(args.__len__()==0):
        pass
    else:
        rlocs = elel.select_seqs(rlocs,args)
    return(df.iloc[rlocs])
示例#5
0
def _rmrow(df,rowname,*args,**kwargs):
    df = copy.deepcopy(df)
    rlocs = _rn2rlocs(rowname,**kwargs)
    if(args.__len__()==0):
        whiches = elel.init_range(0,rlocs.__len__(),1)
    else:
        whiches = list(args)
    rlocs = elel.select_seqs(rlocs,whiches)
    all_rlocs = elel.init_range(0,df.index.__len__(),1)
    lefted_rlocs = elel.select_seqs_not(all_rlocs,rlocs)
    return(df.iloc[lefted_rlocs])
示例#6
0
def _rmcol(df,colname,*args,**kwargs):
    df = copy.deepcopy(df)
    clocs = _cn2clocs(colname,**kwargs)
    if(args.__len__()==0):
        whiches = elel.init_range(0,clocs.__len__(),1)
    else:
        whiches = list(args)
    clocs = elel.select_seqs(clocs,whiches)
    all_clocs = elel.init_range(0,df.columns.__len__(),1)
    lefted_clocs = elel.select_seqs_not(all_clocs,clocs)
    return(df.iloc[:,lefted_clocs])
示例#7
0
文件: dtable.py 项目: ihgazni2/dtable
def get_rows(dtb,*args):
    '''
        >>> parr(dtb)
        {'three': 'aa', 'x': 'xx1', 'y': 'yy1'}
        {'three': 'bb', 'x': 'xx2', 'y': 'yy2'}
        {'three': 'cc', 'x': 'xx3', 'y': 'yy3'}
        {'three': 'dd', 'x': 'xx4', 'y': 'yy4'}
        {'three': 'ee', 'x': 'xx5', 'y': 'yy5'}
        >>>
        >>> parr(get_rows(dtb,[0,2,4]))
        {'three': 'aa', 'x': 'xx1', 'y': 'yy1'}
        {'three': 'cc', 'x': 'xx3', 'y': 'yy3'}
        {'three': 'ee', 'x': 'xx5', 'y': 'yy5'}
        >>>
    '''
    whiches = eftl.compatibize_apply_or_call_args(*args)
    return(elel.select_seqs(dtb,whiches))
示例#8
0
文件: dtable.py 项目: ihgazni2/dtable
def rslctr(dtb,cond_func,*oargs):
    '''
        #cond_func(row,*oargs)
        >>> parr(dtb)
        {'one': 3, 'two': 1, 'three': 2, 'four': 4}
        {'one': 8, 'two': 6, 'three': 7, 'four': 9}
        {'one': 13, 'two': 11, 'three': 12, 'four': 14}
        {'one': 18, 'two': 16, 'three': 17, 'four': 19}
        {'one': 23, 'two': 21, 'three': 22, 'four': 24}
        >>>
        >>> ndtb = rslctr(dtb,lambda row:row['two']%2==0)
        >>> parr(ndtb)
        {'one': 8, 'two': 6, 'three': 7, 'four': 9}
        {'one': 18, 'two': 16, 'three': 17, 'four': 19}
        >>>

    '''
    conds = elel.mapv(dtb,cond_func,oargs)
    nseqs = elel.indexes_all(conds,True)
    ndtb = elel.select_seqs(dtb,nseqs)
    return(ndtb)