示例#1
0
文件: mad.py 项目: livlab/agate
    def run(self, table):
        column = table.columns[self._column_name]

        data = column.values_without_nulls_sorted()
        m = self._median.run(table)

        return median(tuple(abs(n - m) for n in data))
示例#2
0
    def run(self, table):
        column = table.columns[self._column_name]

        data = column.values_without_nulls_sorted()
        if data:
            m = self._median.run(table)
            return median(tuple(abs(n - m) for n in data))
示例#3
0
    def run(self, column):
        """
        :returns: :class:`decimal.Decimal`.
        """
        if not isinstance(column.data_type, Number):
            raise DataTypeError(
                'MAD can only be applied to columns containing Number data.')

        if column.aggregate(HasNulls()):
            warn_null_calculation(self, column)

        data = column.values_without_nulls_sorted()
        m = column.aggregate(Percentiles())[50]

        return median(tuple(abs(n - m) for n in data))
示例#4
0
    def run(self, table):
        """
        :returns:
            :class:`decimal.Decimal`.
        """
        column = table.columns[self._column_name]

        if not isinstance(column.data_type, Number):
            raise DataTypeError('MAD can only be applied to columns containing Number data.')

        has_nulls = HasNulls(self._column_name).run(table)

        if has_nulls:
            warn_null_calculation(self, column)

        data = column.values_without_nulls_sorted()
        m = Median(self._column_name).run(table)

        return median(tuple(abs(n - m) for n in data))