Skip to content

Commit

Permalink
Percentile fixed
Browse files Browse the repository at this point in the history
Added Mode and Percentile tests
  • Loading branch information
jdunkerley committed Mar 8, 2022
1 parent c4e54c3 commit 25de2a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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->
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/Table_Tests/src/Aggregate_Column_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 25de2a0

Please sign in to comment.