Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
VEBER Philippe
codepi
Commits
0ba1aada
Commit
0ba1aada
authored
Nov 03, 2020
by
Philippe Veber
Browse files
tk/Dataframe: added test and fixed bug
parent
c1e496c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
2 deletions
+21
-2
lib/toolbox/dataframe.ml
lib/toolbox/dataframe.ml
+20
-1
lib/toolbox/dune
lib/toolbox/dune
+1
-1
No files found.
lib/toolbox/dataframe.ml
View file @
0ba1aada
...
...
@@ -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
\t
1.2
\t
NA"
;
"a
\t
1.2
\t
2"
;
"c
\t
-1.2
\t
NA"
;
]
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
...
...
lib/toolbox/dune
View file @
0ba1aada
...
...
@@ -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
)))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment