1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
from agate.aggregations.base import Aggregation
from agate.data_types import Boolean
class All(Aggregation):
"""
Check if all values in a column pass a test.
:param column_name:
The name of the column to check.
:param test:
Either a single value that all values in the column are compared against
(for equality) or a function that takes a column value and returns
`True` or `False`.
"""
def __init__(self, column_name, test):
self._column_name = column_name
if callable(test):
self._test = test
else:
self._test = lambda d: d == test
def get_aggregate_data_type(self, table):
return Boolean()
def validate(self, table):
table.columns[self._column_name]
def run(self, table):
"""
:returns:
:class:`bool`
"""
column = table.columns[self._column_name]
data = column.values()
return all(self._test(d) for d in data)
|