コード例 #1
0
    def as_string(self, context):
        tmp_varname = get_tmp_varname()
        result = expr_eval(self, context)
        if isinstance(result, dict):
            indices = result['indices']
            values = result['values']
        else:
            indices = None

        if indices is not None:
            if isinstance(values, np.ndarray):
                res_type = values.dtype.type
            else:
                res_type = type(values)
            result = np.zeros(context_length(context), dtype=res_type)
            np.put(result, indices, values)
        context[tmp_varname] = result
        return tmp_varname
コード例 #2
0
ファイル: aggregates.py プロジェクト: chenyuyou/liam2
    def evaluate(self, context):
        expr = self.expr

        #FIXME: either take "contextual filter" into account here (by using
        # self._getfilter), or don't do it in sum & gini
        if self.filter is not None:
            filter_values = expr_eval(self.filter, context)
            tmp_varname = get_tmp_varname()
            context = context.copy()
            context[tmp_varname] = filter_values
            if getdtype(expr, context) is bool:
                # convert expr to int because mul_bbb is not implemented in
                # numexpr
                expr *= 1
            expr *= Variable(tmp_varname)
        else:
            filter_values = True

        values = expr_eval(expr, context)
        values = np.asarray(values)

        if self.skip_na:
            # we should *not* use an inplace operation because filter_values
            # can be a simple variable
            filter_values = filter_values & ispresent(values)

        if filter_values is True:
            numrows = len(values)
        else:
            numrows = np.sum(filter_values)

        if numrows:
            if self.skip_na:
                return na_sum(values) / float(numrows)
            else:
                return np.sum(values) / float(numrows)
        else:
            return float('nan')
コード例 #3
0
 def evaluate(self, context):
     expr = self.expr
     #FIXME: either take "contextual filter" into account here (by using
     # self._getfilter), or don't do it in grpsum (& grpgini?)
     if self.filter is not None:
         filter_values = expr_eval(self.filter, context)
         tmp_varname = get_tmp_varname()
         context = context.copy()
         context[tmp_varname] = filter_values
         if dtype(expr, context) is bool:
             # convert expr to int because mul_bbb is not implemented in
             # numexpr
             expr *= 1
         expr *= Variable(tmp_varname)
     else:
         filter_values = True
     values = expr_eval(expr, context)
     filter_values &= np.isfinite(values)
     numrows = np.sum(filter_values)
     if numrows:
         return np.nansum(values) / float(numrows)
     else:
         return float('nan')
コード例 #4
0
 def __init__(self, expr):
     CompoundExpression.__init__(self)
     self.expr = expr
     self.u_varname = get_tmp_varname()