Esempio n. 1
0
File: tfunc.py Progetto: liam2/liam2
    def compute(self, context, expr):
        entity = context.entity

        baseperiod = entity.base_period
        period = context.period - 1

        typemap = {bool: int, int: int, float: float}
        res_type = typemap[getdtype(expr, context)]
        res_size = len(entity.array)

        sum_values = np.zeros(res_size, dtype=res_type)
        id_to_rownum = context.id_to_rownum
        while period >= baseperiod:
            ids, values = self.value_for_period(expr, period, context,
                                                fill=None)

            # filter out lines which are present because there was a value for
            # that individual at that period but not for that column
            acceptable_rows = hasvalue(values)
            acceptable_ids = ids[acceptable_rows]
            if len(acceptable_ids):
                acceptable_values = values[acceptable_rows]

                value_rows = id_to_rownum[acceptable_ids]

                period_value = np.zeros(res_size, dtype=np.float)
                safe_put(period_value, value_rows, acceptable_values)

                sum_values += period_value
            period -= 1
        return sum_values
Esempio n. 2
0
    def compute(self, context, expr):
        entity = context.entity

        baseperiod = entity.base_period
        period = context.period - 1

        typemap = {bool: int, int: int, float: float}
        res_type = typemap[getdtype(expr, context)]
        res_size = len(entity.array)

        sum_values = np.zeros(res_size, dtype=res_type)
        id_to_rownum = context.id_to_rownum
        while period >= baseperiod:
            ids, values = self.value_for_period(expr,
                                                period,
                                                context,
                                                fill=None)

            # filter out lines which are present because there was a value for
            # that individual at that period but not for that column
            acceptable_rows = hasvalue(values)
            acceptable_ids = ids[acceptable_rows]
            if len(acceptable_ids):
                acceptable_values = values[acceptable_rows]

                value_rows = id_to_rownum[acceptable_ids]

                period_value = np.zeros(res_size, dtype=np.float)
                safe_put(period_value, value_rows, acceptable_values)

                sum_values += period_value
            period -= 1
        return sum_values
Esempio n. 3
0
    def compute(self, context, expr, filter=None, weights=None, skip_na=True):
        filter_expr = self._getfilter(context, filter)
        if filter_expr is not None:
            expr = BinaryOp('*', expr, filter_expr)
        if weights is not None:
            expr_dtype = getdtype(expr, context)
            # missing (-1) * weight should be missing (-1)
            if skip_na and np.issubdtype(expr_dtype, np.integer):
                # expr = where(expr != -1, expr * weights, -1)
                missing_int = missing_values[int]
                expr = exprmisc.Where(ComparisonOp('!=', expr, missing_int),
                                      BinaryOp('*', expr, weights),
                                      missing_int)
            else:
                # expr = expr * weights
                expr = BinaryOp('*', expr, weights)

        values = expr_eval(expr, context)
        values = np.asarray(values)
        return na_sum(values) if skip_na else np.sum(values)
Esempio n. 4
0
    def compute(self, context, expr, filter=None, weights=None, skip_na=True):
        filter_expr = self._getfilter(context, filter)
        if filter_expr is not None:
            expr = BinaryOp('*', expr, filter_expr)
        if weights is not None:
            expr_dtype = getdtype(expr, context)
            # missing (-1) * weight should be missing (-1)
            if skip_na and np.issubdtype(expr_dtype, np.integer):
                # expr = where(expr != -1, expr * weights, -1)
                missing_int = missing_values[int]
                expr = exprmisc.Where(ComparisonOp('!=', expr, missing_int),
                                      BinaryOp('*', expr, weights),
                                      missing_int)
            else:
                # expr = expr * weights
                expr = BinaryOp('*', expr, weights)

        values = expr_eval(expr, context)
        values = np.asarray(values)
        return na_sum(values) if skip_na else np.sum(values)
Esempio n. 5
0
 def _getfilter(context, filter):
     ctx_filter = context.filter_expr
     # FIXME: this is a hack and shows that the not_hashable filter_expr in
     #  context is not really a good solution. We should rather add a flag
     # in the context "ishardsubset" or something like that.
     if filter is not_hashable:
         filter_expr = ctx_filter
     elif ctx_filter is not_hashable:
         filter_expr = filter
     elif filter is not None and ctx_filter is not None:
         filter_expr = LogicalOp('&', ctx_filter, filter)
     elif filter is not None:
         filter_expr = filter
     elif ctx_filter is not None:
         filter_expr = ctx_filter
     else:
         filter_expr = None
     if filter_expr is not None and \
             getdtype(filter_expr, context) is not bool:
         raise Exception("filter must be a boolean expression")
     return filter_expr
Esempio n. 6
0
File: links.py Progetto: liam2/liam2
 def dtype(self, context):
     target_context = self.target_context(context)
     return getdtype(self.target_expr, target_context)
Esempio n. 7
0
 def dtype(self, context):
     target_context = self.target_context(context)
     return getdtype(self.target_expr, target_context)
Esempio n. 8
0
 def add_filter(expr, filter):
     if filter is not None:
         missing_value = missing_values[getdtype(expr, None)]
         return Where(filter, expr, missing_value)
     else:
         return expr
Esempio n. 9
0
 def add_filter(expr, filter):
     if filter is not None:
         missing_value = missing_values[getdtype(expr, None)]
         return Where(filter, expr, missing_value)
     else:
         return expr
Esempio n. 10
0
 def dtype(self, context):
     assert getdtype(self.cond, context) == bool
     return coerce_types(context, self.iftrue, self.iffalse)
Esempio n. 11
0
 def dtype(self, context):
     # TODO: merge this typemap with tsum's
     typemap = {bool: int, int: int, float: float}
     return typemap[getdtype(self.args[0], context)]
Esempio n. 12
0
 def dtype(self, context):
     # TODO: merge this typemap with tsum's
     typemap = {bool: int, int: int, float: float}
     return typemap[getdtype(self.args[0], context)]
Esempio n. 13
0
 def dtype(self, context):
     assert getdtype(self.cond, context) == bool
     return coerce_types(context, self.iftrue, self.iffalse)
Esempio n. 14
0
File: tfunc.py Progetto: liam2/liam2
 def dtype(self, context):
     assert getdtype(self.args[0], context) == bool
     return int
Esempio n. 15
0
 def dtype(self, context):
     assert getdtype(self.args[0], context) == bool
     return int