Changeset 243


Ignore:
Timestamp:
Oct 29, 2009, 9:58:08 AM (10 years ago)
Author:
marchulsman
Message:

Adding map operation and bugfix for empty containers

Location:
container
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • container/opcon.py

    r238 r243  
    423423class MapCon(OpCon):
    424424    def __init__(self,source,mappable,restype):
    425         self.source = (source,mappable)
     425        self._source = (source,mappable)
    426426        if(source._invar.register(self,restype)):
    427427            restype = tuple(utility.ensure_seq(restype));
    428             f = itypes_py.createFields(["result%d" % colnr for colnr in range(len(restype))],restype)
    429             self._fields = f
    430             self._invar.update['_fields'] = f
    431             if(len(restype) == source.ncol):
    432                 self.deriveMultipleProps((source,),(None,),(0,),len(restype),False,True)
    433             else:
    434                 self.deriveMultipleProps((source,),(None,),(-1,),len(restype),False,True)
    435        
     428            fs = [itypes_py.Field("result%d" % colnr,restype) for colnr,rtype in enumerate(restype)]
     429            self._fields = fs
     430            self._actidx = range(len(fs))
     431            sids = [f.id for f in source._activefields]
     432            tids = [f.id for f in fs]
     433            self._segments = (SegmentInFix(0,sids),SegmentOutFix(attr=tids))
     434            self._props,active = self._inheritProps(source,None,True)
     435            self._actidx_props = self._activateProps(source._props,active,True)
     436            self._set_props_class()
     437 
    436438
    437439class RealizeOpCon(OpCon):
  • container/qg_translate.py

    r227 r243  
    5757    compatRoot=compatible
    5858    compatScalarSrcCon=compatible
     59    compatMapCon=compatible
    5960
    6061    compatPySrcCon=compatible
     
    463464        return leftop
    464465               
     466    def funcMapCon(self,node,sources):
     467        (source,mappable) = sources
     468        source = source.copy()
     469        ndata = []
     470        for elems in zip(*source.data):
     471            ndata.append(mappable(*elems))
     472        source.data = (xnumpy.dimarray(ndata,itypes_py.to_numpy(node.fields[0].type)[0]),)
     473        source.ncol = 1
     474        return source
    465475
    466476    def funcMergeCon(self,node,sources):
  • container/srccon.py

    r218 r243  
    5555        if(not data is None):
    5656            self._result = QueryResult(data,len(data[0]),len(data))
     57        else:
     58            data = tuple((xnumpy.dimarray(tuple(),itypes_py.to_numpy(field.type)) for field in fields))
     59            self._result = QueryResult(data,0,0)
    5760
    5861        if(not modifiable):
    59             if(not data):
    60                 data = tuple((xnumpy.dimarray(tuple(),itypes_py.to_numpy(type)) for type in fields.type))
    61                 self._result = QueryResult(data,0,0)
    6262            self._result.cacheable = True
    6363            self.__class__ = NoModPySrcCon
  • container/user_if.py

    r150 r243  
    6262        else:
    6363            raise RuntimeError, "Only list,tuples,numpy.ndarray types supported"
    64        
     64
     65    print fields,data,modifiable
     66
    6567    return srccon.PySrcCon(fields,data,modifiable)
    6668
Note: See TracChangeset for help on using the changeset viewer.