def __getitem__(self, key):
        """Summary

        Args:
            predicates (TYPE): Description
            new_value (TYPE): Description

        Returns:
            TYPE: Description
        """
        if isinstance(key, slice):
            start = key.start
            # TODO : We currently do nothing with step
            step = key.step
            stop = key.stop
            if self.index_type is not None:
                index_expr = grizzly_impl.get_field(self.expr, 0)
                column_expr = grizzly_impl.get_field(self.expr, 1)
                zip_expr = grizzly_impl.zip_columns([index_expr, column_expr])
                sliced_expr = grizzly_impl.slice_vec(zip_expr, start, stop)
                unzip_expr = grizzly_impl.unzip_columns(
                    sliced_expr, [self.index_type, self.weld_type])
                return SeriesWeld(unzip_expr, self.weld_type, self.df,
                                  self.column_name, self.index_type,
                                  self.index_name)
            else:
                return SeriesWeld(
                    grizzly_impl.slice_vec(self.expr, start, stop))
        else:
            # By default we return as if the key were predicates to filter by
            return self.filter(key)
    def sort_values(self, ascending=False):
        """ Sorts the values of this series

        """
        if self.index_type is not None:
            index_expr = grizzly_impl.get_field(self.expr, 0)
            column_expr = grizzly_impl.get_field(self.expr, 1)
            zip_expr = grizzly_impl.zip_columns([index_expr, column_expr])
            result_expr = grizzly_impl.sort(zip_expr, 1, self.weld_type,
                                            ascending)
            unzip_expr = grizzly_impl.unzip_columns(
                result_expr, [self.index_type, self.weld_type])
            return SeriesWeld(unzip_expr, self.weld_type, self.df,
                              self.column_name, self.index_type,
                              self.index_name)
        else:
            result_expr = grizzly_impl.sort(self.expr)
 def __getitem__(self, key):
     if isinstance(self.grizzly_obj, SeriesWeld):
         series = self.grizzly_obj
         if isinstance(key, SeriesWeld):
             if series.index_type is not None:
                 index_expr = grizzly_impl.get_field(series.expr, 0)
                 column_expr = grizzly_impl.get_field(series.expr, 1)
                 zip_expr = grizzly_impl.zip_columns(
                     [index_expr, column_expr])
                 predicate_expr = grizzly_impl.isin(index_expr, key.expr,
                                                    series.index_type)
                 filtered_expr = grizzly_impl.filter(
                     zip_expr, predicate_expr)
                 unzip_expr = grizzly_impl.unzip_columns(
                     filtered_expr, [series.index_type, series.weld_type])
                 return SeriesWeld(unzip_expr, series.weld_type, series.df,
                                   series.column_name, series.index_type,
                                   series.index_name)
         # TODO : Need to implement for non-pivot tables
     raise Exception("Cannot invoke getitem on non SeriesWeld object")
    def __sub__(self, other):
        # TODO subtractionw without index variables
        if self.index_type is not None:
            index = grizzly_impl.get_field(self.expr, 0)
            expr1 = grizzly_impl.get_field(self.expr, 1)
        else:
            expr1 = self.expr
        if other.index_type is not None:
            index2 = grizzly_impl.get_field(other.expr, 0)
            expr2 = grizzly_impl.get_field(other.expr, 1)
        else:
            expr2 = other.expr
        index_expr = LazyOpResult(index, self.index_type, 0)
        sub_expr = SeriesWeld(
            grizzly_impl.element_wise_op(expr1, expr2, "-", self.weld_type),
            self.weld_type, self.df, self.column_name)

        index_sub_expr = utils.group([index_expr, sub_expr])
        return SeriesWeld(index_sub_expr.expr, self.weld_type, self.df,
                          self.column_name, self.index_type, self.index_name)
Esempio n. 5
0
    def std(self):
        """Standard deviation

        Note that is by default normalizd by n - 1
        # TODO, what does pandas do for multiple grouping columns?
        # Currently we are just going to use one grouping column
        """
        std_expr = grizzly_impl.groupby_std([self.column], [self.column_type],
                                            self.grouping_columns,
                                            self.grouping_column_types)
        unzipped_columns = grizzly_impl.unzip_columns(
            std_expr,
            self.grouping_column_types + [WeldDouble()],
        )
        index_expr = LazyOpResult(grizzly_impl.get_field(unzipped_columns, 0),
                                  self.grouping_column_types[0], 1)
        column_expr = LazyOpResult(grizzly_impl.get_field(unzipped_columns, 1),
                                   self.grouping_column_types[0], 1)
        group_expr = utils.group([index_expr, column_expr])
        return SeriesWeld(group_expr.expr,
                          WeldDouble(),
                          index_type=self.grouping_column_types[0],
                          index_name=self.grouping_column_names[0])
    def __ge__(self, other):
        """Summary

        Args:
            other (TYPE): Description

        Returns:
            TYPE: Description
        """
        if self.index_type is not None:
            expr = grizzly_impl.get_field(self.expr, 1)
        else:
            expr = self.expr
        return SeriesWeld(
            grizzly_impl.compare(expr, other, ">=", self.weld_type), WeldBit(),
            self.df, self.column_name)
 def index(self):
     if self.index_type is not None:
         return SeriesWeld(grizzly_impl.get_field(self.expr, 0),
                           self.index_type, self.df, self.index_name)
     # TODO : Make all series have a series attribute
     raise Exception("No index present")