Commit 0296be39 authored by Philippe Veber's avatar Philippe Veber
Browse files

tk/Dataframe: added make

parent 38b176d9
......@@ -16,6 +16,27 @@ type t = {
cols : (string * column) list ;
}
let column_length = function
| Ints xs -> Array.length xs
| Int_opts xs -> Array.length xs
| Floats xs -> Array.length xs
| Float_opts xs -> Array.length xs
| Strings xs -> Array.length xs
| String_opts xs -> Array.length xs
let make = function
| [] -> Error (`Msg "empty dataframe")
| (_, first_col) :: t as cols ->
let nrows = column_length first_col in
if not (List.for_all t ~f:(fun (_, col) -> column_length col = nrows)) then
Error (`Msg "columns with different lengths")
else
match List.(find_a_dup ~compare:String.compare (map cols ~f:fst)) with
| Some l -> Rresult.R.error_msgf "duplicate label %S" l
| None ->
let ncols = List.length cols in
Ok { nrows ; ncols ; cols }
let columns df = df.cols
let nrows t = t.nrows
......
......@@ -17,6 +17,8 @@ val get_col_by_name : t -> string -> column option
val columns : t -> (string * column) list
val make : (string * column) list -> (t, [> `Msg of string]) result
val from_file :
?header:[`Read_in_file | `Expect of string list | `Use of string list] ->
string ->
......
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