Ejemplo n.º 1
0
    def run(self, column):
        """
        :returns: :class:`decimal.Decimal`.
        """
        if not isinstance(column, NumberColumn):
            raise UnsupportedAggregationError(self, column)

        return column.sum()
Ejemplo n.º 2
0
    def run(self, column):
        """
        :returns: :class:`int`.
        """
        if not isinstance(column, TextColumn):
            raise UnsupportedAggregationError(self, column)

        return max([len(d) for d in column.get_data_without_nulls()])
Ejemplo n.º 3
0
    def get_aggregate_column_type(self, column):
        if isinstance(column, DateColumn):
            return DateType()
        elif isinstance(column, DateTimeColumn):
            return DateTimeType()
        elif isinstance(column, NumberColumn):
            return NumberType()

        raise UnsupportedAggregationError(self, column)
Ejemplo n.º 4
0
    def run(self, column):
        """
        :returns: :class:`datetime.date`
        """
        supported_columns = (DateColumn, DateTimeColumn, NumberColumn)

        if not any(isinstance(column, t) for t in supported_columns):
            raise UnsupportedAggregationError(self, column)

        return max(column.get_data_without_nulls())
Ejemplo n.º 5
0
    def run(self, column):
        """
        :returns: :class:`decimal.Decimal`.
        """
        super(StDev, self).run(column)

        if not isinstance(column, NumberColumn):
            raise UnsupportedAggregationError(self, column)

        return column._variance().sqrt()
Ejemplo n.º 6
0
    def get_aggregate_data_type(self, table):
        """
        Get the data type that should be used when using this aggregation with
        a :class:`.TableSet` to produce a new column.

        Should raise :class:`.UnsupportedAggregationError` if this column does
        not support aggregation into a :class:`.TableSet`. (For example, if it
        does not return a single value.)
        """
        raise UnsupportedAggregationError()
Ejemplo n.º 7
0
    def run(self, column):
        """
        :returns: :class:`decimal.Decimal`.
        """
        if not isinstance(column, NumberColumn):
            raise UnsupportedAggregationError(self, column)

        if column.has_nulls():
            raise NullCalculationError

        return column.variance().sqrt()
Ejemplo n.º 8
0
    def run(self, column):
        """
        :returns: :class:`decimal.Decimal`.
        """
        super(IQR, self).run(column)

        if not isinstance(column, NumberColumn):
            raise UnsupportedAggregationError(self, column)

        percentiles = column.percentiles()

        return percentiles[75] - percentiles[25]
Ejemplo n.º 9
0
    def run(self, column):
        """
        :returns: :class:`decimal.Decimal`.
        """
        if not isinstance(column, NumberColumn):
            raise UnsupportedAggregationError(self, column)

        if column.has_nulls():
            raise NullCalculationError

        percentiles = column.percentiles()

        return percentiles[75] - percentiles[25]
Ejemplo n.º 10
0
    def run(self, column):
        """
        :returns: :class:`decimal.Decimal`.
        """
        super(MAD, self).run(column)

        if not isinstance(column, NumberColumn):
            raise UnsupportedAggregationError(self, column)

        data = column._data_sorted()
        m = column.percentiles()[50]

        return self._median(tuple(abs(n - m) for n in data))
Ejemplo n.º 11
0
    def run(self, column):
        """
        :returns: :class:`decimal.Decimal`.
        """
        if not isinstance(column, NumberColumn):
            raise UnsupportedAggregationError(self, column)

        if column.has_nulls():
            raise NullCalculationError

        data = column.get_data_sorted()
        m = column.percentiles()[50]

        return self._median(tuple(abs(n - m) for n in data))
Ejemplo n.º 12
0
    def run(self, column):
        """
        :returns: :class:`decimal.Decimal`.
        """
        super(Mode, self).run(column)

        if not isinstance(column, NumberColumn):
            raise UnsupportedAggregationError(self, column)

        data = column._data()
        state = defaultdict(int)

        for n in data:
            state[n] += 1

        return max(state.keys(), key=lambda x: state[x])
Ejemplo n.º 13
0
    def run(self, column):
        """
        :returns: :class:`decimal.Decimal`.
        """
        if not isinstance(column, NumberColumn):
            raise UnsupportedAggregationError(self, column)

        if column.has_nulls():
            raise NullCalculationError

        data = column.get_data()
        state = defaultdict(int)

        for n in data:
            state[n] += 1

        return max(state.keys(), key=lambda x: state[x])