diff --git a/ari.goal b/ari.goal index 151c4f6..544ddd9 100644 --- a/ari.goal +++ b/ari.goal @@ -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 @@ -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;[(..p.x@p.gs)#gs]]; ms@<_ms } / auto-complete / Test Framework diff --git a/testing/table-test.goal b/testing/table-test.goal index 7b23e4f..32ae3dc 100644 --- a/testing/table-test.goal +++ b/testing/table-test.goal @@ -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}]/