diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Aggregate_Column.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Aggregate_Column.enso index 6754cd44965e7..bf1c22d828833 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Aggregate_Column.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Aggregate_Column.enso @@ -52,7 +52,7 @@ type Aggregate_Column Arguments: - percentile: Percentage to compute from 0-1 inclusive. - type Percentile (column:Column|Text|Integer) (name:Text|Nothing=Nothing) (percentile:Decimal=0.25) + type Percentile (percentile:Decimal) (column:Column|Text|Integer) (name:Text|Nothing=Nothing) ## Creates a new column with the mode of values (ignoring missing values) of the specified column within each group. @@ -123,7 +123,7 @@ type Aggregate_Column Sum c _ -> "Sum " + (get_name c) Average c _ -> "Average " + (get_name c) Median c _ -> "Median " + (get_name c) - Percentile c _ p -> (p*100).floor.to_text + "%-ile" + (get_name c) + Percentile p c _ -> (p*100).floor.to_text + "%-ile" + (get_name c) Mode c _ -> "Mode " + (get_name c) Standard_Deviation c _ _ -> "Standard Deviation " + (get_name c) Concatenate c _ _ _ _ _ -> "Concatenate " + (get_name c) @@ -221,7 +221,7 @@ type Aggregate_Column Median c _ -> create_closure c col->map->i-> val = col.at i if val.is_nothing then map else (map.insert val (1 + (map.get_or_else val 0))) - Percentile c _ _ -> create_closure c col->map->i-> + Percentile p c _ -> create_closure c col->map->i-> val = col.at i if val.is_nothing then map else (map.insert val (1 + (map.get_or_else val 0))) Mode c _ -> create_closure c col->map->i-> @@ -257,7 +257,7 @@ type Aggregate_Column case this of Count_Distinct _ _ _ -> value.size Median _ _ -> percentile 0.5 value - Percentile _ _ p -> percentile p value + Percentile p _ _ -> percentile p value Mode _ _ -> (value.fold_with_key (Pair 0 Nothing) p->k->v-> if v>(p.first) then (Pair v k) else p) . second Average _ _ -> if value.first == 0 then Nothing else (value.second / value.first) Standard_Deviation _ _ p -> if value.first == 0 then Nothing else diff --git a/test/Table_Tests/src/Aggregate_Column_Spec.enso b/test/Table_Tests/src/Aggregate_Column_Spec.enso index 6940d55f67adc..021009aa0a415 100644 --- a/test/Table_Tests/src/Aggregate_Column_Spec.enso +++ b/test/Table_Tests/src/Aggregate_Column_Spec.enso @@ -176,4 +176,13 @@ spec = Test.group "Aggregate Columns" <| test_aggregator mode_table (Mode -1 test_name) test_name 2 test_aggregator empty_table (Mode 0 test_name) test_name Nothing + Test.specify "should be able to get the percentile of a set of numbers" <| + percentile_table = Table.new [["tests", [67,23,56,93,36,47,45,1,88,44,49,13,74,76,4,97,49,81,81,37]]] + test_aggregator percentile_table (Percentile 0 0) "0%-ile tests" 1 + test_aggregator percentile_table (Percentile 0 -1 test_name) test_name 1 + test_aggregator percentile_table (Percentile 0.15 0) "15%-ile tests" 21.5 + test_aggregator percentile_table (Percentile 0.25 0) "25%-ile tests" 36.75 + test_aggregator percentile_table (Percentile 0.66 0) "66%-ile tests" 70.78 + test_aggregator empty_table (Mode 0 test_name) test_name Nothing + main = Test.Suite.run_main here.spec