Skip to content

Commit

Permalink
Concatenate
Browse files Browse the repository at this point in the history
  • Loading branch information
jdunkerley committed Mar 1, 2022
1 parent 0945b6a commit 446afe2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ type Aggregate_Column
if v.is_nothing then current else v
Sum c _ -> create_closure c col->total->i->
v = col.at i
if v.is_nothing then total else
if v.is_nothing then total else
if total.is_nothing then v else total + v
Average c _ -> create_closure c col->a->i->
v = col.at i
Expand All @@ -157,8 +157,11 @@ type Aggregate_Column
v = col.at i
if v.is_nothing then a else [a.first + 1, a.second + v, (a.at 2) + v*v]
Concatenate c _ j _ _ q -> create_closure c col->text->i->
val=if (col.at i).is_nothing then "" else
text = (col.at i).to_text
v = col.at i
val=if v.is_nothing then "" else
text = case v of
Text -> v
_ -> v.to_text
if text == "" then (q+q) else
if text.contains j then (q+text+q) else text
if i==0 then val else (text + j + val)
Expand Down
10 changes: 8 additions & 2 deletions test/Table_Tests/src/Aggregate_Column_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from Standard.Table.Data.Aggregate_Column import all
import Standard.Test

spec = Test.group "Aggregate Columns" <|
simple_table = Table.new [["count", [1, 2, Nothing, 3, Nothing]], ["is_valid", [Nothing, False, True, False, Nothing]], ["float", [1, 2.1, 3.4, 5.6, Nothing]], ["text", ["A", "", Nothing, "B", Nothing]]]
simple_table = Table.new [["count", [1, 2, Nothing, 3, Nothing]], ["is_valid", [Nothing, False, True, False, Nothing]], ["float", [1, 2.1, 3.4, 5.6, Nothing]], ["text", ["A", "", Nothing, "B,C", Nothing]]]
text_col = simple_table.at "text"
bool_col = simple_table.at "is_valid"
float_col = simple_table.at "float"
Expand Down Expand Up @@ -114,11 +114,17 @@ spec = Test.group "Aggregate Columns" <|
test_aggregator empty_table (Last 0 test_name ignore_nothing=False) test_name Nothing

Test.specify "should be able to compute last of a set of values excluding missing values" <|
test_aggregator simple_table (Last 1) "First is_valid" False
test_aggregator simple_table (Last 1) "Last is_valid" False
test_aggregator simple_table (Last 1 test_name) test_name False
test_aggregator simple_table (Last "is_valid" test_name) test_name False
test_aggregator simple_table (Last bool_col test_name) test_name False
test_aggregator empty_table (Last 0 test_name) test_name Nothing

Test.specify "should be able to concatenate a set of values excluding missing values" <|
test_aggregator simple_table (Concatenate -1 Nothing ',' '[' ']' '"') "Concatenate text" '[A,"",,"B,C",]'
test_aggregator simple_table (Concatenate -1 test_name) test_name 'AB,C'
test_aggregator simple_table (Concatenate "text" test_name ',') test_name 'A,,,B,C,'
test_aggregator simple_table (Concatenate text_col test_name) test_name 'AB,C'
test_aggregator empty_table (Concatenate 0 test_name) test_name Nothing

main = Test.Suite.run_main here.spec

0 comments on commit 446afe2

Please sign in to comment.