diff options
author | Frederick Muriuki Muriithi | 2021-11-12 03:56:01 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2021-11-12 03:56:01 +0300 |
commit | d895eea22ab908c11f4ebb77f99518367879b1f6 (patch) | |
tree | 340c45791be8d9952bfd477e909066456c52e041 /tests | |
parent | eec4cd566c1aceb5bd3e392595c38893bde8192b (diff) | |
download | genenetwork3-d895eea22ab908c11f4ebb77f99518367879b1f6.tar.gz |
Pass in parser function for flexibility
Issue:
https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi
* To improve the usefulness of already existing code, provide the parser
function as an argument to the `parse_input_line` function.
This was found to be useful when writing code to compare the `pcor.test`
function in GN1 and the `pingouin.partial_corr` function.
The format of the data generated when getting results for the `pcor.test`
function shared a lot with that of the `pcor.rec` function, but it was
different in a few, places, and the differences were non-trivial, needing
different parsing processes.
In such a case, it was found necessary to just pass in the function to do
the actual parsing, rather than create code with the same form as the
existing one, save for the function being called.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/computations/test_partial_correlations.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/tests/unit/computations/test_partial_correlations.py b/tests/unit/computations/test_partial_correlations.py index e702f6e..7cf8cd8 100644 --- a/tests/unit/computations/test_partial_correlations.py +++ b/tests/unit/computations/test_partial_correlations.py @@ -161,7 +161,7 @@ def parse_result(key_value): return (key, float(value)) return key_value -parser_function = compose( +parse_for_rec = compose( parse_result, parse_rm, parse_xyz, @@ -170,7 +170,7 @@ parser_function = compose( lambda k_v: tuple(item.strip("\n\t ") for item in k_v), lambda s: s.split(":")) -def parse_input_line(line): +def parse_input_line(line, parser_function): return tuple( parser_function(item) for item in line if not item.startswith("------")) @@ -183,10 +183,10 @@ def merge_z(item): "z", tuple(val for key, val in item.items() if key.startswith("z")))} -def parse_input(lines): +def parse_input(lines, parser_function): return tuple( merge_z(dict(item)) - for item in (parse_input_line(line) for line in lines) + for item in (parse_input_line(line, parser_function) for line in lines) if len(item) != 0) def parse_test_data(filename): @@ -195,7 +195,7 @@ def parse_test_data(filename): lambda s: s.startswith("------"), (line.strip("\n\t ") for line in fl.readlines())) - return parse_input(input_lines) + return parse_input(input_lines, parse_for_rec) class TestPartialCorrelations(TestCase): """Class for testing partial correlations computation functions""" |