示例#1
0
def _repl_cols(df,poses,*args,**kwargs):
    df = copy.deepcopy(df)
    args = list(args)
    if(isinstance(args[0],dict)):
        kl,vl = eded.d2kvlist(args[0])
    else:
        if(isinstance(args[1],list)):
            kl =  elel.select_evens(args)
            vl =  elel.select_odds(args)
        else:
            kl,vl = elel.brkl2kvlist(args,df.index.__len__()+1)
    if(isinstance(poses[0],int)):
        pass
    else:
        colnames = poses 
        clocs_array = []
        for i in range(colnames.__len__()):
            clocs = _cn2clocs(colnames[i],**kwargs)
            clocs_array.append((clocs,i))
        if("whiches" in kwargs):
            whiches = kwargs['whiches']
            clocs_array = elel.mapv(clocs_array,lambda ele:ele[0])
            clocs = elel.batexec(lambda clocs,which:clocs[which],clocs_array,whiches)
            poses = clocs
        else:
            #by default replace all
            nkl = []
            nvl = []
            nclocs = []
            for i in range(clocs_array.__len__()):
                clocs = clocs_array[i][0]
                index = clocs_array[i][1]
                tmpkl = elel.init(clocs.__len__(),kl[i])
                tmpvl = elel.init(clocs.__len__(),vl[i])
                nkl = elel.concat(nkl,tmpkl)
                nvl = elel.concat(nvl,tmpvl)
                nclocs = elel.concat(nclocs,clocs)
            #batsort
            poses = nclocs
            kl,vl = elel.batsorted(nclocs,nkl,nvl)
    poses = elel.mapv(poses,lambda pos:pos+1)
    poses.sort()
    for i in range(0,poses.__len__()):
        pos = poses[i]
        df.insert(pos,kl[i],vl[i],kwargs['allow_duplicates'])
        pos = pos -1
        all_clocs = elel.init_range(0,df.columns.__len__(),1)
        all_clocs.remove(pos)
        df = df.iloc[:,all_clocs]
    return(df)
示例#2
0
文件: catimg.py 项目: ihgazni/catimg
def img2ansi256indexes(img, c):
    lines = elel.init(img.__len__(), [])
    for i in range(lines.__len__()):
        line = img[i]
        line = list(map(find_index, line))
        line = elel.join(linefill(line, c), "")
        lines[i] = line
    return (lines)
示例#3
0
文件: ndarr.py 项目: ihgazni2/qtable
def creat_action_list(func_list, **kwargs):
    if ("other_args_list" in kwargs):
        other_args_list = kwargs['other_args_list']
    else:
        other_args_list = elel.init(func_list.__len__(), [])
    actions = elel.mapvo(func_list,
                         creat_action,
                         map_func_args_array=other_args_list)
    return (actions)
示例#4
0
def edfspls2plmat(edfspls):
    groups = edfspls2groups(edfspls)
    mat =[]
    size = max(list(groups.keys()))
    mat = elel.init(size,[])
    for k in groups:
        depth = k - 1
        layer = groups[k]
        mat[depth].extend(layer)
    return(mat)
示例#5
0
文件: utils.py 项目: ihgazni2/ematmap
def init_mat(layer_length_list,**kwargs):
    '''
        from xdict.jprint import pobj,pdir,parr
        init_mat([1,3,2])
        parr(init_mat([1,3,2]))
        >>> parr(init_mat([1,3,2]))
        [None]
        [None, None, None]
        [None, None]
        >>>
    '''
    value = eftl.dflt_kwargs("value",None,**kwargs)
    dcp = eftl.dflt_kwargs("deepcopy",False,**kwargs)
    value = copy.deepcopy(value) if (dcp) else value
    depth = len(layer_length_list)
    m = elel.init(depth,[])
    for i in range(depth):
        layer_lngth = layer_length_list[i]
        m[i]  = elel.init(layer_lngth,value)
    return(m)
示例#6
0
文件: araq.py 项目: ihgazni2/conjugar
def de_cond_or_engine(ele,*args):
    args = list(args)
    conds = args[0]
    lngth = conds.__len__()
    if(args.__len__()>1):
        funcs = args[1]
        if(isinstance(funcs,list)):
            pass
        else:
            func = funcs
            funcs = elel.init(lngth,func)
    else:
        func = lambda cond,ele:(cond == ele)
        funcs = elel.init(lngth,func)
    for i  in range(0,lngth):
        each = conds[i]
        tmp = funcs[i](each,ele)
        if(tmp):
            return(True)
        else:
            pass
    return(False)
示例#7
0
def cntnt2cil(content, for_display=False):
    ####for comments
    if (content == None):
        return ([])
    else:
        pass
    ####
    content = cntnt_fmt_norecur(content)
    rslt = elel.init(content.__len__())
    unhandled = cntnt_init_unhandled(content)
    while (unhandled.__len__() > 0):
        next_unhandled = []
        for i in range(0, unhandled.__len__()):
            ele = unhandled[i]
            data = ele['data']
            ppl = ele['pl']
            cond = cntnt_is_leaf(data)
            rpl = elel.remove_all(ppl, 'content')
            if (cond):
                s = encd_one(data)
                rslt = elel.setitem_via_pathlist(rslt, s, rpl)
            else:
                # treat square_blk as a leaf
                if (data['type'] == '[] block'):
                    s = encd_square_blk(data, for_display)
                    rslt = elel.setitem_via_pathlist(rslt, s, rpl)
                # treat paren_blk as a leaf
                elif (data['type'] == '() block'):
                    s = encd_paren_blk(data)
                    rslt = elel.setitem_via_pathlist(rslt, s, rpl)
                else:
                    children = cntnt_get_children(data, ppl)
                    dummy = elel.init(children.__len__())
                    rslt = elel.setitem_via_pathlist(rslt, dummy, rpl)
                    next_unhandled = elel.concat(next_unhandled, children)
        unhandled = next_unhandled
    return (rslt)
示例#8
0
文件: dtable.py 项目: ihgazni2/dtable
def cvl2col(ckey,cvl):
    '''
        ckey = 'three'
        cvl = ['aa', 'bb', 'cc', 'dd', 'ee']
        >>> parr(cvl2col(ckey,cvl))
        {'three': 'aa'}
        {'three': 'bb'}
        {'three': 'cc'}
        {'three': 'dd'}
        {'three': 'ee'}
        >>>
    '''
    ckl = elel.init(len(cvl),ckey)
    tl = tltl.kvlists2tl(ckl,cvl)
    col = tltl.tlist2dlist(tl)
    return(col)
示例#9
0
def _reindex_rows(df,*index,**kwargs):
    df = copy.deepcopy(df)
    index = list(index)
    if(isinstance(index[0],list)):
        index = index[0]
    else:
        pass
    rlocs_array = []
    for i in range(index.__len__()):
        rlocs = _rn2rlocs(index[i],**kwargs)
        rlocs_array.append(rlocs)
    if("whiches" in kwargs):
        whiches = kwargs['whiches']
    else:
        whiches = elel.init(rlocs_array.__len__(),0)
    rlocs = elel.batexec(lambda rlocs,which:rlocs[which],rlocs_array,whiches)
    return(df.iloc[rlocs])
示例#10
0
def _reindex_cols(df,*columns,**kwargs):
    df = copy.deepcopy(df)
    columns = list(columns)
    if(isinstance(columns[0],list)):
        columns = columns[0]
    else:
        pass
    clocs_array = []
    for i in range(columns.__len__()):
        clocs = _cn2clocs(columns[i],**kwargs)
        clocs_array.append(clocs)
    if("whiches" in kwargs):
        whiches = kwargs['whiches']
    else:
        whiches = elel.init(clocs_array.__len__(),0)
    clocs = elel.batexec(lambda clocs,which:clocs[which],clocs_array,whiches)
    return(df.iloc[:,clocs])
示例#11
0
def creat_tru_fls_dtb(cnl, *args):
    '''
        >>> cnl
        ['A', 'B', 'C']
        >>>
        >>> parr(creat_tru_fls_dtb(cnl))
        {'A': True, 'B': True, 'C': True, '@RSLT@': None}
        {'A': False, 'B': True, 'C': True, '@RSLT@': None}
        {'A': False, 'B': True, 'C': True, '@RSLT@': None}
        {'A': False, 'B': False, 'C': True, '@RSLT@': None}
        {'A': False, 'B': True, 'C': True, '@RSLT@': None}
        {'A': False, 'B': False, 'C': True, '@RSLT@': None}
        {'A': False, 'B': False, 'C': True, '@RSLT@': None}
        {'A': False, 'B': False, 'C': False, '@RSLT@': None}
        >>>
    '''
    dtb = dtdt.init_dtb(creat_tru_fls_mat(cnl), cnl)
    dtb = dtdt.add_col(dtb, "@RSLT@", elel.init(len(dtb), None))
    return (dtb)
示例#12
0
文件: dtable.py 项目: ihgazni2/dtable
def get_col(dtb,colname):
    '''
        >>> 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_col(dtb,'x'))
        {'three': 'xx1'}
        {'three': 'xx2'}
        {'three': 'xx3'}
        {'three': 'xx4'}
        {'three': 'xx5'}
        >>>
        
    '''
    cvl = get_cvl(dtb,colname)
    ckl = elel.init(len(cvl),colname)
    return(cvl2col(ckey,cvl))
示例#13
0
def cntnt_rm_whitespace(content):
    content = cntnt_fmt_norecur(content)
    rslt = elel.init(content.__len__())
    unhandled = cntnt_init_unhandled(content)
    while (unhandled.__len__() > 0):
        next_unhandled = []
        for i in range(0, unhandled.__len__()):
            ele = unhandled[i]
            data = ele['data']
            ppl = ele['pl']
            cond = cntnt_is_leaf(data)
            if (cond):
                rslt = elel.setitem_via_pathlist(rslt, data, ppl)
            else:
                children = cntnt_get_children(data, ppl)
                rchildren = elel.array_map(children,
                                           lambda child: child['data'])
                dummy = copy.deepcopy(data)
                dummy['content'] = rchildren
                rslt = elel.setitem_via_pathlist(rslt, dummy, ppl)
                next_unhandled = elel.concat(next_unhandled, children)
        unhandled = next_unhandled
    return (rslt)