Skip to content

Commit

Permalink
Add mktbl, use from json.tbl
Browse files Browse the repository at this point in the history
  • Loading branch information
semperos committed Oct 30, 2024
1 parent 22fffe4 commit 7a59057
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ari.goal
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/ Shape
istbl:{and["d"=@x;&/"s"=@'!x;&/{(@'x)¿"ANSI"}x;&/(*ls)=ls:#'x]} / is x a dictionary-as-table
mktbl:{ks:!*x; vs:@[;ks]'x; ks!+vs} / given list of dicts, create dictionary-as-table
shape:{-1_#:'*:\x} / Implementation by John Earnest, shared on k-tree
depths:{[ind;l]?[(@l)~"A";,/o[ind+1]'l; (@l)¿"NSI";(#l)#ind; ind-1]} / list depths
zero:..[i:0;n:0.0;s:"";r:rx//;d:()!();f:(:);A:()] / handle, error don't fill
Expand Down Expand Up @@ -37,7 +38,7 @@ csv.tbl:{(*'x)!(1_'x)} / table from csv parsing, assumes header
json.tbl:{ / table from parsing json array of like objects
?["d"~@x
?[istbl x;:x;:error"dict is not a table: $x"]
[ks:!*x; vs:@[;ks]'x; ks!+vs]]}
mktbl@x]}
/ Interactive Tools
ac:{gs:,/rt.get'!"! kw";ms:?["s"=@x;(..p.x%p.gs)#gs;[([email protected])#gs]]; ms@<_ms } / auto-complete
/ Test Framework
Expand Down
4 changes: 2 additions & 2 deletions testing/table-test.goal
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
f:(path.dir abspath FILE)+"/data/starwars.csv"
t:csv.tbl ","csv 'read f
tt.t{87=#*t}; tt.t{14=#t}
tt.t{istbl t}; tt.t{87=#*t}; tt.t{14=#t}
t:json.tbl@json rq/[{"a":1,"b":2},{"a":10,"b":20},{"a":100,"b":200}]/
tt.t{t~..[a:(1 10 100);b:(2 20 200)]}
tt.t{3=#*t}; tt.t{(1 10 100)~t"a"}
/ BUG to be fixed
/ BUG to be fixed, the zero values should be uniform by column.
t:json.tbl@json rq/[{"a":1,"b":2},{"a":10},{"a":100,"b":200}]/
tt.t{t~..[a:(1.0 10.0 100.0);b:(2.0 0.0 200.0)]}
t:json.tbl@json rq/[{"a":"one","b":2},{"b":20},{"a":"hundred","b":200}]/
Expand Down

0 comments on commit 7a59057

Please sign in to comment.