Commit 0ba1aada authored by Philippe Veber's avatar Philippe Veber
Browse files

tk/Dataframe: added test and fixed bug

parent c1e496c1
......@@ -8,6 +8,7 @@ type column =
| Maybe_float of float option array
| String of string array
| Maybe_string of string option array
[@@deriving show]
type t = {
nrows : int ;
......@@ -55,7 +56,7 @@ let rev_convert_col col =
else
try Int (conv Int.of_string) with _ ->
try Float (conv Float.of_string) with _ ->
String (Array.of_list col)
String (Array.of_list_rev col)
let parse_lines ncols lines =
let open Result.Monad_infix in
......@@ -68,6 +69,24 @@ let parse_lines ncols lines =
) >>| fun (nrows, cols) ->
nrows, List.map cols ~f:rev_convert_col
type parse_result = (int * column list, [`Msg of string]) result
[@@deriving show]
let%expect_test "Dataframe.parse_line ex1" =
let got =
parse_lines 3 [
"a\t1.2\tNA" ;
"a\t1.2\t2" ;
"c\t-1.2\tNA" ;
]
in
print_endline (show_parse_result got) ;
[%expect {|
(Ok (3,
[(Dataframe.String [|"a"; "a"; "c"|]);
(Dataframe.Float [|1.2; 1.2; -1.2|]);
(Dataframe.Maybe_int [|None; (Some 2); None|])])) |}]
let from_file path =
let open Result.Monad_infix in
match In_channel.read_lines path with
......
......@@ -5,4 +5,4 @@
(inline_tests
(deps ../../tests/data/gemma_output.tsv ../../tests/data/gemma_alignment.fa))
(preprocess
(pps ppx_jane ppx_inline_test)))
(pps ppx_jane ppx_inline_test ppx_deriving.show)))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment