Exemplo n.º 1
0
    def run(self, table):
        """
        :returns:
            :class:`int`
        """
        percentiles = Percentiles(self._column_name).run(table)

        new_column = []

        for row in table.rows:
            new_column.append(percentiles.locate(row[self._column_name]))

        return new_column
    def run(self, table):
        """
        :returns:
            :class:`int`
        """
        percentiles = Percentiles(self._column_name).run(table)

        new_column = []

        for row in table.rows:
            new_column.append(percentiles.locate(row[self._column_name]))

        return new_column
Exemplo n.º 3
0
Arquivo: median.py Projeto: 01-/agate
class Median(Aggregation):
    """
    Calculate the median of a column.

    Median is equivalent to the 50th percentile. See :class:`Percentiles`
    for implementation details.

    :param column_name:
        The name of a column containing :class:`.Number` data.
    """
    def __init__(self, column_name):
        self._column_name = column_name
        self._percentiles = Percentiles(column_name)

    def get_aggregate_data_type(self, table):
        return Number()

    def validate(self, table):
        column = table.columns[self._column_name]

        if not isinstance(column.data_type, Number):
            raise DataTypeError('Median 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)

    def run(self, table):
        percentiles = self._percentiles.run(table)

        return percentiles[50]
Exemplo n.º 4
0
class Median(Aggregation):
    """
    Calculate the median of a column.

    Median is equivalent to the 50th percentile. See :class:`Percentiles`
    for implementation details.

    :param column_name:
        The name of a column containing :class:`.Number` data.
    """
    def __init__(self, column_name):
        self._column_name = column_name
        self._percentiles = Percentiles(column_name)

    def get_aggregate_data_type(self, table):
        return Number()

    def validate(self, table):
        column = table.columns[self._column_name]

        if not isinstance(column.data_type, Number):
            raise DataTypeError(
                'Median 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)

    def run(self, table):
        percentiles = self._percentiles.run(table)

        return percentiles[50]
Exemplo n.º 5
0
Arquivo: iqr.py Projeto: livlab/agate
class IQR(Aggregation):
    """
    Calculate the interquartile range of a column containing
    :class:`.Number` data.
    """
    def __init__(self, column_name):
        self._column_name = column_name
        self._percentiles = Percentiles(column_name)

    def get_aggregate_data_type(self, table):
        return Number()

    def validate(self, table):
        column = table.columns[self._column_name]

        if not isinstance(column.data_type, Number):
            raise DataTypeError('IQR 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)

    def run(self, table):
        percentiles = self._percentiles.run(table)

        return percentiles[75] - percentiles[25]
Exemplo n.º 6
0
class IQR(Aggregation):
    """
    Calculate the interquartile range of a column.

    :param column_name:
        The name of a column containing :class:`.Number` data.
    """
    def __init__(self, column_name):
        self._column_name = column_name
        self._percentiles = Percentiles(column_name)

    def get_aggregate_data_type(self, table):
        return Number()

    def validate(self, table):
        column = table.columns[self._column_name]

        if not isinstance(column.data_type, Number):
            raise DataTypeError('IQR 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)

    def run(self, table):
        percentiles = self._percentiles.run(table)

        return percentiles[75] - percentiles[25]
Exemplo n.º 7
0
    def run(self, table):
        """
        :returns:
            An instance of :class:`Quantiles`.
        """
        percentiles = Percentiles(self._column_name).run(table)

        return Quantiles([percentiles[i] for i in range(0, 101, 25)])
Exemplo n.º 8
0
Arquivo: median.py Projeto: 01-/agate
 def __init__(self, column_name):
     self._column_name = column_name
     self._percentiles = Percentiles(column_name)
Exemplo n.º 9
0
 def __init__(self, column_name):
     self._column_name = column_name
     self._percentiles = Percentiles(column_name)