<s> import datetime <EOL> from decimal import Decimal <EOL> import warnings <EOL> try : <EOL> import unittest2 as unittest <EOL> except ImportError : <EOL> import unittest <EOL> from agate import Table <EOL> from agate . aggregations import * <EOL> from agate . data_types import * <EOL> from agate . exceptions import * <EOL> from agate . warns import NullCalculationWarning <EOL> class TestSimpleAggregation ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . rows = ( <EOL> ( <NUM_LIT:1> , <NUM_LIT:2> , '<STR_LIT:a>' ) , <EOL> ( <NUM_LIT:2> , <NUM_LIT:3> , '<STR_LIT:b>' ) , <EOL> ( None , <NUM_LIT:4> , '<STR_LIT:c>' ) <EOL> ) <EOL> self . number_type = Number ( ) <EOL> self . text_type = Text ( ) <EOL> self . column_names = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . column_types = [ self . number_type , self . number_type , self . text_type ] <EOL> self . table = Table ( self . rows , self . column_names , self . column_types ) <EOL> def test_summary ( self ) : <EOL> summary = Summary ( '<STR_LIT>' , Boolean ( ) , lambda c : <NUM_LIT:2> in c ) <EOL> self . assertIsInstance ( summary . get_aggregate_data_type ( None ) , Boolean ) <EOL> summary . validate ( self . table ) <EOL> self . assertEqual ( summary . run ( self . table ) , True ) <EOL> def test_has_nulls ( self ) : <EOL> has_nulls = HasNulls ( '<STR_LIT>' ) <EOL> self . assertIsInstance ( has_nulls . get_aggregate_data_type ( None ) , Boolean ) <EOL> has_nulls . validate ( self . table ) <EOL> self . assertEqual ( has_nulls . run ( self . table ) , True ) <EOL> def test_any ( self ) : <EOL> with self . assertRaises ( ValueError ) : <EOL> Any ( '<STR_LIT>' ) . validate ( self . table ) <EOL> Any ( '<STR_LIT>' , lambda d : d ) . validate ( self . table ) <EOL> self . assertIsInstance ( Any ( '<STR_LIT>' ) . get_aggregate_data_type ( None ) , Boolean ) <EOL> self . assertEqual ( Any ( '<STR_LIT>' , lambda d : d == <NUM_LIT:2> ) . run ( self . table ) , True ) <EOL> self . assertEqual ( Any ( '<STR_LIT>' , lambda d : d == <NUM_LIT:5> ) . run ( self . table ) , False ) <EOL> def test_all ( self ) : <EOL> with self . assertRaises ( ValueError ) : <EOL> All ( '<STR_LIT>' ) . validate ( self . table ) <EOL> All ( '<STR_LIT>' , lambda d : d ) . validate ( self . table ) <EOL> self . assertIsInstance ( All ( '<STR_LIT>' ) . get_aggregate_data_type ( None ) , Boolean ) <EOL> self . assertEqual ( All ( '<STR_LIT>' , lambda d : d != <NUM_LIT:5> ) . run ( self . table ) , True ) <EOL> self . assertEqual ( All ( '<STR_LIT>' , lambda d : d == <NUM_LIT:2> ) . run ( self . table ) , False ) <EOL> def test_count ( self ) : <EOL> rows = ( <EOL> ( <NUM_LIT:1> , <NUM_LIT:2> , '<STR_LIT:a>' ) , <EOL> ( <NUM_LIT:2> , <NUM_LIT:3> , '<STR_LIT:b>' ) , <EOL> ( None , <NUM_LIT:4> , '<STR_LIT:c>' ) , <EOL> ( <NUM_LIT:1> , <NUM_LIT:2> , '<STR_LIT:a>' ) , <EOL> ( <NUM_LIT:1> , <NUM_LIT:2> , '<STR_LIT:a>' ) <EOL> ) <EOL> table = Table ( rows , self . column_names , self . column_types ) <EOL> self . assertIsInstance ( Count ( ) . get_aggregate_data_type ( table ) , Number ) <EOL> Count ( ) . validate ( self . table ) <EOL> self . assertEqual ( Count ( ) . run ( table ) , <NUM_LIT:5> ) <EOL> self . assertEqual ( Count ( ) . run ( table ) , <NUM_LIT:5> ) <EOL> def test_count_column ( self ) : <EOL> rows = ( <EOL> ( <NUM_LIT:1> , <NUM_LIT:2> , '<STR_LIT:a>' ) , <EOL> ( <NUM_LIT:2> , <NUM_LIT:3> , '<STR_LIT:b>' ) , <EOL> ( None , <NUM_LIT:4> , '<STR_LIT:c>' ) , <EOL> ( <NUM_LIT:1> , <NUM_LIT:2> , '<STR_LIT:a>' ) , <EOL> ( <NUM_LIT:1> , <NUM_LIT:2> , '<STR_LIT:a>' ) <EOL> ) <EOL> table = Table ( rows , self . column_names , self . column_types ) <EOL> self . assertIsInstance ( Count ( '<STR_LIT>' ) . get_aggregate_data_type ( table ) , Number ) <EOL> Count ( '<STR_LIT>' ) . validate ( self . table ) <EOL> self . assertEqual ( Count ( '<STR_LIT>' ) . run ( table ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( Count ( '<STR_LIT>' ) . run ( table ) , <NUM_LIT:5> ) <EOL> def test_count_value ( self ) : <EOL> rows = ( <EOL> ( <NUM_LIT:1> , <NUM_LIT:2> , '<STR_LIT:a>' ) , <EOL> ( <NUM_LIT:2> , <NUM_LIT:3> , '<STR_LIT:b>' ) , <EOL> ( None , <NUM_LIT:4> , '<STR_LIT:c>' ) , <EOL> ( <NUM_LIT:1> , <NUM_LIT:2> , '<STR_LIT:a>' ) , <EOL> ( <NUM_LIT:1> , <NUM_LIT:2> , '<STR_LIT:a>' ) <EOL> ) <EOL> table = Table ( rows , self . column_names , self . column_types ) <EOL> self . assertIsInstance ( Count ( '<STR_LIT>' , <NUM_LIT:1> ) . get_aggregate_data_type ( table ) , Number ) <EOL> Count ( '<STR_LIT>' , <NUM_LIT:1> ) . validate ( self . table ) <EOL> self . assertEqual ( Count ( '<STR_LIT>' , <NUM_LIT:1> ) . run ( table ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( Count ( '<STR_LIT>' , <NUM_LIT:4> ) . run ( table ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( Count ( '<STR_LIT>' , None ) . run ( table ) , <NUM_LIT:1> ) <EOL> class TestBooleanAggregation ( unittest . TestCase ) : <EOL> def test_any ( self ) : <EOL> rows = [ <EOL> [ True ] , <EOL> [ False ] , <EOL> [ None ] <EOL> ] <EOL> table = Table ( rows , [ '<STR_LIT:test>' ] , [ Boolean ( ) ] ) <EOL> Any ( '<STR_LIT:test>' ) . validate ( table ) <EOL> self . assertEqual ( Any ( '<STR_LIT:test>' ) . run ( table ) , True ) <EOL> rows = [ <EOL> [ False ] , <EOL> [ False ] , <EOL> [ None ] <EOL> ] <EOL> table = Table ( rows , [ '<STR_LIT:test>' ] , [ Boolean ( ) ] ) <EOL> Any ( '<STR_LIT:test>' ) . validate ( table ) <EOL> self . assertEqual ( Any ( '<STR_LIT:test>' ) . run ( table ) , False ) <EOL> def test_all ( self ) : <EOL> rows = [ <EOL> [ True ] , <EOL> [ True ] , <EOL> [ None ] <EOL> ] <EOL> table = Table ( rows , [ '<STR_LIT:test>' ] , [ Boolean ( ) ] ) <EOL> All ( '<STR_LIT:test>' ) . validate ( table ) <EOL> self . assertEqual ( All ( '<STR_LIT:test>' ) . run ( table ) , False ) <EOL> rows = [ <EOL> [ True ] , <EOL> [ True ] , <EOL> [ True ] <EOL> ] <EOL> table = Table ( rows , [ '<STR_LIT:test>' ] , [ Boolean ( ) ] ) <EOL> All ( '<STR_LIT:test>' ) . validate ( table ) <EOL> self . assertEqual ( All ( '<STR_LIT:test>' ) . run ( table ) , True ) <EOL> class TestDateTimeAggregation ( unittest . TestCase ) : <EOL> def test_min ( self ) : <EOL> rows = [ <EOL> [ datetime . datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT> ) ] , <EOL> [ datetime . datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:30> , <NUM_LIT:30> ) ] , <EOL> [ datetime . datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:30> ) ] , <EOL> ] <EOL> table = Table ( rows , [ '<STR_LIT:test>' ] , [ DateTime ( ) ] ) <EOL> self . assertIsInstance ( Min ( '<STR_LIT:test>' ) . get_aggregate_data_type ( table ) , DateTime ) <EOL> Min ( '<STR_LIT:test>' ) . validate ( table ) <EOL> self . assertEqual ( Min ( '<STR_LIT:test>' ) . run ( table ) , datetime . datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:30> ) ) <EOL> def test_max ( self ) : <EOL> rows = [ <EOL> [ datetime . datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT> ) ] , <EOL> [ datetime . datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:30> , <NUM_LIT:30> ) ] , <EOL> [ datetime . datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:30> ) ] , <EOL> ] <EOL> table = Table ( rows , [ '<STR_LIT:test>' ] , [ DateTime ( ) ] ) <EOL> self . assertIsInstance ( Max ( '<STR_LIT:test>' ) . get_aggregate_data_type ( table ) , DateTime ) <EOL> Max ( '<STR_LIT:test>' ) . validate ( table ) <EOL> self . assertEqual ( Max ( '<STR_LIT:test>' ) . run ( table ) , datetime . datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT> ) ) <EOL> class TestNumberAggregation ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . rows = ( <EOL> ( Decimal ( '<STR_LIT>' ) , Decimal ( '<STR_LIT>' ) , '<STR_LIT:a>' ) , <EOL> ( Decimal ( '<STR_LIT>' ) , Decimal ( '<STR_LIT>' ) , '<STR_LIT:b>' ) , <EOL> ( None , Decimal ( '<STR_LIT>' ) , '<STR_LIT:c>' ) , <EOL> ( Decimal ( '<STR_LIT>' ) , Decimal ( '<STR_LIT>' ) , '<STR_LIT:c>' ) <EOL> ) <EOL> self . number_type = Number ( ) <EOL> self . text_type = Text ( ) <EOL> self . column_names = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . column_types = [ self . number_type , self . number_type , self . text_type ] <EOL> self . table = Table ( self . rows , self . column_names , self . column_types ) <EOL> def test_max_precision ( self ) : <EOL> with self . assertRaises ( DataTypeError ) : <EOL> MaxPrecision ( '<STR_LIT>' ) . validate ( self . table ) <EOL> self . assertIsInstance ( MaxPrecision ( '<STR_LIT>' ) . get_aggregate_data_type ( self . table ) , Number ) <EOL> MaxPrecision ( '<STR_LIT>' ) . validate ( self . table ) <EOL> self . assertEqual ( MaxPrecision ( '<STR_LIT>' ) . run ( self . table ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( MaxPrecision ( '<STR_LIT>' ) . run ( self . table ) , <NUM_LIT:2> ) <EOL> def test_sum ( self ) : <EOL> with self . assertRaises ( DataTypeError ) : <EOL> Sum ( '<STR_LIT>' ) . validate ( self . table ) <EOL> Sum ( '<STR_LIT>' ) . validate ( self . table ) <EOL> self . assertEqual ( Sum ( '<STR_LIT>' ) . run ( self . table ) , Decimal ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( Sum ( '<STR_LIT>' ) . run ( self . table ) , Decimal ( '<STR_LIT>' ) ) <EOL> def test_min ( self ) : <EOL> with self . assertRaises ( DataTypeError ) : <EOL> Min ( '<STR_LIT>' ) . validate ( self . table ) <EOL> Min ( '<STR_LIT>' ) . validate ( self . table ) <EOL> self . assertEqual ( Min ( '<STR_LIT>' ) . run ( self . table ) , Decimal ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( Min ( '<STR_LIT>' ) . run ( self . table ) , Decimal ( '<STR_LIT>' ) ) <EOL> def test_max ( self ) : <EOL> with self . assertRaises ( DataTypeError ) : <EOL> Max ( '<STR_LIT>' ) . validate ( self . table ) <EOL> Max ( '<STR_LIT>' ) . validate ( self . table ) <EOL> self . assertEqual ( Max ( '<STR_LIT>' ) . run ( self . table ) , Decimal ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( Max ( '<STR_LIT>' ) . run ( self . table ) , Decimal ( '<STR_LIT>' ) ) <EOL> def test_mean ( self ) : <EOL> warnings . simplefilter ( '<STR_LIT:error>' ) <EOL> with self . assertRaises ( NullCalculationWarning ) : <EOL> Mean ( '<STR_LIT>' ) . validate ( self . table ) <EOL> with self . assertRaises ( DataTypeError ) : <EOL> Mean ( '<STR_LIT>' ) . validate ( self . table ) <EOL> Mean ( '<STR_LIT>' ) . validate ( self . table ) <EOL> self . assertEqual ( Mean ( '<STR_LIT>' ) . run ( self . table ) , Decimal ( '<STR_LIT>' ) ) <EOL> def test_mean_with_nulls ( self ) : <EOL> warnings . simplefilter ( '<STR_LIT:ignore>' ) <EOL> Mean ( '<STR_LIT>' ) . validate ( self . table ) <EOL> self . assertAlmostEqual ( Mean ( '<STR_LIT>' ) . run ( self . table ) , Decimal ( '<STR_LIT>' ) ) <EOL> def test_median ( self ) : <EOL> warnings . simplefilter ( '<STR_LIT:error>' ) <EOL> with self . assertRaises ( NullCalculationWarning ) : <EOL> Median ( '<STR_LIT>' ) . validate ( self . table ) <EOL> with self . assertRaises ( DataTypeError ) : <EOL> Median ( '<STR_LIT>' ) . validate ( self . table ) <EOL> Median ( '<STR_LIT>' ) . validate ( self . table ) <EOL> self . assertIsInstance ( Median ( '<STR_LIT>' ) . get_aggregate_data_type ( self . table ) , Number ) <EOL> self . assertEqual ( Median ( '<STR_LIT>' ) . run ( self . table ) , Decimal ( '<STR_LIT>' ) ) <EOL> def test_mode ( self ) : <EOL> warnings . simplefilter ( '<STR_LIT:error>' ) <EOL> with self . assertRaises ( NullCalculationWarning ) : <EOL> Mode ( '<STR_LIT>' ) . validate ( self . table ) <EOL> with self . assertRaises ( DataTypeError ) : <EOL> Mode ( '<STR_LIT>' ) . validate ( self . table ) <EOL> Mode ( '<STR_LIT>' ) . validate ( self . table ) <EOL> self . assertIsInstance ( Mode ( '<STR_LIT>' ) . get_aggregate_data_type ( self . table ) , Number ) <EOL> self . assertEqual ( Mode ( '<STR_LIT>' ) . run ( self . table ) , Decimal ( '<STR_LIT>' ) ) <EOL> def test_iqr ( self ) : <EOL> warnings . simplefilter ( '<STR_LIT:error>' ) <EOL> with self . assertRaises ( NullCalculationWarning ) : <EOL> IQR ( '<STR_LIT>' ) . validate ( self . table ) <EOL> with self . assertRaises ( DataTypeError ) : <EOL> IQR ( '<STR_LIT>' ) . validate ( self . table ) <EOL> IQR ( '<STR_LIT>' ) . validate ( self . table ) <EOL> self . assertIsInstance ( IQR ( '<STR_LIT>' ) . get_aggregate_data_type ( self . table ) , Number ) <EOL> self . assertEqual ( IQR ( '<STR_LIT>' ) . run ( self . table ) , Decimal ( '<STR_LIT>' ) ) <EOL> def test_variance ( self ) : <EOL> warnings . simplefilter ( '<STR_LIT:error>' ) <EOL> with self . assertRaises ( NullCalculationWarning ) : <EOL> Variance ( '<STR_LIT>' ) . validate ( self . table ) <EOL> with self . assertRaises ( DataTypeError ) : <EOL> Variance ( '<STR_LIT>' ) . validate ( self . table ) <EOL> Variance ( '<STR_LIT>' ) . validate ( self . table ) <EOL> self . assertIsInstance ( Variance ( '<STR_LIT>' ) . get_aggregate_data_type ( self . table ) , Number ) <EOL> self . assertEqual ( <EOL> Variance ( '<STR_LIT>' ) . run ( self . table ) . quantize ( Decimal ( '<STR_LIT>' ) ) , <EOL> Decimal ( '<STR_LIT>' ) <EOL> ) <EOL> def test_population_variance ( self ) : <EOL> warnings . simplefilter ( '<STR_LIT:error>' ) <EOL> with self . assertRaises ( NullCalculationWarning ) : <EOL> PopulationVariance ( '<STR_LIT>' ) . validate ( self . table ) <EOL> with self . assertRaises ( DataTypeError ) : <EOL> PopulationVariance ( '<STR_LIT>' ) . validate ( self . table ) <EOL> PopulationVariance ( '<STR_LIT>' ) . validate ( self . table ) <EOL> self . assertIsInstance ( PopulationVariance ( '<STR_LIT>' ) . get_aggregate_data_type ( self . table ) , Number ) <EOL> self . assertEqual ( <EOL> PopulationVariance ( '<STR_LIT>' ) . run ( self . table ) . quantize ( Decimal ( '<STR_LIT>' ) ) , <EOL> Decimal ( '<STR_LIT>' ) <EOL> ) <EOL> def test_stdev ( self ) : <EOL> warnings . simplefilter ( '<STR_LIT:error>' ) <EOL> with self . assertRaises ( NullCalculationWarning ) : <EOL> StDev ( '<STR_LIT>' ) . validate ( self . table ) <EOL> with self . assertRaises ( DataTypeError ) : <EOL> StDev ( '<STR_LIT>' ) . validate ( self . table ) <EOL> StDev ( '<STR_LIT>' ) . validate ( self . table ) <EOL> self . assertIsInstance ( StDev ( '<STR_LIT>' ) . get_aggregate_data_type ( self . table ) , Number ) <EOL> self . assertAlmostEqual ( <EOL> StDev ( '<STR_LIT>' ) . run ( self . table ) . quantize ( Decimal ( '<STR_LIT>' ) ) , <EOL> Decimal ( '<STR_LIT>' ) <EOL> ) <EOL> def test_population_stdev ( self ) : <EOL> warnings . simplefilter ( '<STR_LIT:error>' ) <EOL> with self . assertRaises ( NullCalculationWarning ) : <EOL> PopulationStDev ( '<STR_LIT>' ) . validate ( self . table ) <EOL> with self . assertRaises ( DataTypeError ) : <EOL> PopulationStDev ( '<STR_LIT>' ) . validate ( self . table ) <EOL> PopulationStDev ( '<STR_LIT>' ) . validate ( self . table ) <EOL> self . assertIsInstance ( PopulationStDev ( '<STR_LIT>' ) . get_aggregate_data_type ( self . table ) , Number ) <EOL> self . assertAlmostEqual ( <EOL> PopulationStDev ( '<STR_LIT>' ) . run ( self . table ) . quantize ( Decimal ( '<STR_LIT>' ) ) , <EOL> Decimal ( '<STR_LIT>' ) <EOL> ) <EOL> def test_mad ( self ) : <EOL> warnings . simplefilter ( '<STR_LIT:error>' ) <EOL> with self . assertRaises ( NullCalculationWarning ) : <EOL> MAD ( '<STR_LIT>' ) . validate ( self . table ) <EOL> with self . assertRaises ( DataTypeError ) : <EOL> MAD ( '<STR_LIT>' ) . validate ( self . table ) <EOL> MAD ( '<STR_LIT>' ) . validate ( self . table ) <EOL> self . assertIsInstance ( MAD ( '<STR_LIT>' ) . get_aggregate_data_type ( self . table ) , Number ) <EOL> self . assertAlmostEqual ( MAD ( '<STR_LIT>' ) . run ( self . table ) , Decimal ( '<STR_LIT:0>' ) ) <EOL> def test_percentiles ( self ) : <EOL> warnings . simplefilter ( '<STR_LIT:error>' ) <EOL> with self . assertRaises ( NullCalculationWarning ) : <EOL> Percentiles ( '<STR_LIT>' ) . validate ( self . table ) <EOL> with self . assertRaises ( DataTypeError ) : <EOL> Percentiles ( '<STR_LIT>' ) . validate ( self . table ) <EOL> Percentiles ( '<STR_LIT>' ) . validate ( self . table ) <EOL> rows = [ ( n , ) for n in range ( <NUM_LIT:1> , <NUM_LIT> ) ] <EOL> table = Table ( rows , [ '<STR_LIT>' ] , [ self . number_type ] ) <EOL> percentiles = Percentiles ( '<STR_LIT>' ) . run ( table ) <EOL> self . assertEqual ( percentiles [ <NUM_LIT:0> ] , Decimal ( '<STR_LIT:1>' ) ) <EOL> self . assertEqual ( percentiles [ <NUM_LIT> ] , Decimal ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( percentiles [ <NUM_LIT:50> ] , Decimal ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( percentiles [ <NUM_LIT> ] , Decimal ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( percentiles [ <NUM_LIT> ] , Decimal ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( percentiles [ <NUM_LIT:100> ] , Decimal ( '<STR_LIT>' ) ) <EOL> def test_percentiles_locate ( self ) : <EOL> rows = [ ( n , ) for n in range ( <NUM_LIT:1> , <NUM_LIT> ) ] <EOL> table = Table ( rows , [ '<STR_LIT>' ] , [ self . number_type ] ) <EOL> percentiles = Percentiles ( '<STR_LIT>' ) . run ( table ) <EOL> self . assertEqual ( percentiles . locate ( <NUM_LIT> ) , Decimal ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( percentiles . locate ( <NUM_LIT> ) , Decimal ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( percentiles . locate ( <NUM_LIT> ) , Decimal ( '<STR_LIT>' ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> percentiles . locate ( <NUM_LIT:0> ) <EOL> with self . assertRaises ( ValueError ) : <EOL> percentiles . locate ( <NUM_LIT> ) <EOL> def test_quartiles ( self ) : <EOL> """<STR_LIT>""" <EOL> warnings . simplefilter ( '<STR_LIT:error>' ) <EOL> with self . assertRaises ( NullCalculationWarning ) : <EOL> Quartiles ( '<STR_LIT>' ) . validate ( self . table ) <EOL> with self . assertRaises ( DataTypeError ) : <EOL> Quartiles ( '<STR_LIT>' ) . validate ( self . table ) <EOL> Quartiles ( '<STR_LIT>' ) . validate ( self . table ) <EOL> rows = [ ( n , ) for n in [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ] <EOL> table = Table ( rows , [ '<STR_LIT>' ] , [ self . number_type ] ) <EOL> quartiles = Quartiles ( '<STR_LIT>' ) . run ( table ) <EOL> for i , v in enumerate ( [ '<STR_LIT:1>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:4>' ] ) : <EOL> self . assertEqual ( quartiles [ i ] , Decimal ( v ) ) <EOL> rows = [ ( n , ) for n in [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ] <EOL> table = Table ( rows , [ '<STR_LIT>' ] , [ self . number_type ] ) <EOL> quartiles = Quartiles ( '<STR_LIT>' ) . run ( table ) <EOL> for i , v in enumerate ( [ '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT:3>' , '<STR_LIT:4>' , '<STR_LIT:5>' ] ) : <EOL> self . assertEqual ( quartiles [ i ] , Decimal ( v ) ) <EOL> rows = [ ( n , ) for n in [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ] <EOL> table = Table ( rows , [ '<STR_LIT>' ] , [ self . number_type ] ) <EOL> quartiles = Quartiles ( '<STR_LIT>' ) . run ( table ) <EOL> for i , v in enumerate ( [ '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT>' , '<STR_LIT:5>' , '<STR_LIT>' ] ) : <EOL> self . assertEqual ( quartiles [ i ] , Decimal ( v ) ) <EOL> rows = [ ( n , ) for n in [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] ] <EOL> table = Table ( rows , [ '<STR_LIT>' ] , [ self . number_type ] ) <EOL> quartiles = Quartiles ( '<STR_LIT>' ) . run ( table ) <EOL> for i , v in enumerate ( [ '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT:4>' , '<STR_LIT>' , '<STR_LIT>' ] ) : <EOL> self . assertEqual ( quartiles [ i ] , Decimal ( v ) ) <EOL> rows = [ ( n , ) for n in [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:4> ] ] <EOL> table = Table ( rows , [ '<STR_LIT>' ] , [ self . number_type ] ) <EOL> quartiles = Quartiles ( '<STR_LIT>' ) . run ( table ) <EOL> for i , v in enumerate ( [ '<STR_LIT:1>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:4>' ] ) : <EOL> self . assertEqual ( quartiles [ i ] , Decimal ( v ) ) <EOL> rows = [ ( n , ) for n in [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:5> ] ] <EOL> table = Table ( rows , [ '<STR_LIT>' ] , [ self . number_type ] ) <EOL> quartiles = Quartiles ( '<STR_LIT>' ) . run ( table ) <EOL> for i , v in enumerate ( [ '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT:3>' , '<STR_LIT:4>' , '<STR_LIT:5>' ] ) : <EOL> self . assertEqual ( quartiles [ i ] , Decimal ( v ) ) <EOL> rows = [ ( n , ) for n in [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:6> ] ] <EOL> table = Table ( rows , [ '<STR_LIT>' ] , [ self . number_type ] ) <EOL> quartiles = Quartiles ( '<STR_LIT>' ) . run ( table ) <EOL> for i , v in enumerate ( [ '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT>' , '<STR_LIT:5>' , '<STR_LIT>' ] ) : <EOL> self . assertEqual ( quartiles [ i ] , Decimal ( v ) ) <EOL> rows = [ ( n , ) for n in [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:7> ] ] <EOL> table = Table ( rows , [ '<STR_LIT>' ] , [ self . number_type ] ) <EOL> quartiles = Quartiles ( '<STR_LIT>' ) . run ( table ) <EOL> for i , v in enumerate ( [ '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT:4>' , '<STR_LIT>' , '<STR_LIT>' ] ) : <EOL> self . assertEqual ( quartiles [ i ] , Decimal ( v ) ) <EOL> def test_quartiles_locate ( self ) : <EOL> """<STR_LIT>""" <EOL> rows = [ ( n , ) for n in [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> ] ] <EOL> table = Table ( rows , [ '<STR_LIT>' ] , [ self . number_type ] ) <EOL> quartiles = Quartiles ( '<STR_LIT>' ) . run ( table ) <EOL> self . assertEqual ( quartiles . locate ( <NUM_LIT:2> ) , Decimal ( '<STR_LIT:0>' ) ) <EOL> self . assertEqual ( quartiles . locate ( <NUM_LIT:4> ) , Decimal ( '<STR_LIT:1>' ) ) <EOL> self . assertEqual ( quartiles . locate ( <NUM_LIT:6> ) , Decimal ( '<STR_LIT:2>' ) ) <EOL> self . assertEqual ( quartiles . locate ( <NUM_LIT:8> ) , Decimal ( '<STR_LIT:3>' ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> quartiles . locate ( <NUM_LIT:0> ) <EOL> with self . assertRaises ( ValueError ) : <EOL> quartiles . locate ( <NUM_LIT:11> ) <EOL> def test_quintiles ( self ) : <EOL> warnings . simplefilter ( '<STR_LIT:error>' ) <EOL> with self . assertRaises ( NullCalculationWarning ) : <EOL> Quintiles ( '<STR_LIT>' ) . validate ( self . table ) <EOL> with self . assertRaises ( DataTypeError ) : <EOL> Quintiles ( '<STR_LIT>' ) . validate ( self . table ) <EOL> Quintiles ( '<STR_LIT>' ) . validate ( self . table ) <EOL> rows = [ ( n , ) for n in range ( <NUM_LIT:1> , <NUM_LIT> ) ] <EOL> table = Table ( rows , [ '<STR_LIT>' ] , [ self . number_type ] ) <EOL> quintiles = Quintiles ( '<STR_LIT>' ) . run ( table ) <EOL> def test_deciles ( self ) : <EOL> warnings . simplefilter ( '<STR_LIT:error>' ) <EOL> with self . assertRaises ( NullCalculationWarning ) : <EOL> Deciles ( '<STR_LIT>' ) . validate ( self . table ) <EOL> with self . assertRaises ( DataTypeError ) : <EOL> Deciles ( '<STR_LIT>' ) . validate ( self . table ) <EOL> Deciles ( '<STR_LIT>' ) . validate ( self . table ) <EOL> rows = [ ( n , ) for n in range ( <NUM_LIT:1> , <NUM_LIT> ) ] <EOL> table = Table ( rows , [ '<STR_LIT>' ] , [ self . number_type ] ) <EOL> deciles = Deciles ( '<STR_LIT>' ) . run ( table ) <EOL> class TestTextAggregation ( unittest . TestCase ) : <EOL> def test_max_length ( self ) : <EOL> rows = [ <EOL> [ '<STR_LIT:a>' ] , <EOL> [ '<STR_LIT>' ] , <EOL> [ '<STR_LIT:w>' ] <EOL> ] <EOL> table = Table ( rows , [ '<STR_LIT:test>' ] , [ Text ( ) ] ) <EOL> MaxLength ( '<STR_LIT:test>' ) . validate ( table ) <EOL> self . assertEqual ( MaxLength ( '<STR_LIT:test>' ) . run ( table ) , <NUM_LIT:6> ) <EOL> self . assertIsInstance ( MaxLength ( '<STR_LIT:test>' ) . run ( table ) , Decimal ) <EOL> def test_max_length_invalid ( self ) : <EOL> rows = [ <EOL> [ <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:3> ] <EOL> ] <EOL> table = Table ( rows , [ '<STR_LIT:test>' ] , [ Number ( ) ] ) <EOL> with self . assertRaises ( DataTypeError ) : <EOL> MaxLength ( '<STR_LIT:test>' ) . validate ( table ) </s>
