From 495e02be4e3264c07e4ae89ccd2bc747bf2b6b59 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 29 Sep 2022 04:22:29 +0300 Subject: Remove empty rows, and conversion for output Remove any rows that do not have values since they are not useful to the computations and only lead to errors. Remove the conversion to output format here: only convert the values for output at the point of output, and not earlier. --- wqflask/wqflask/correlation/rust_correlation.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/correlation/rust_correlation.py b/wqflask/wqflask/correlation/rust_correlation.py index d9193459..8d32aaba 100644 --- a/wqflask/wqflask/correlation/rust_correlation.py +++ b/wqflask/wqflask/correlation/rust_correlation.py @@ -250,11 +250,15 @@ def __compute_sample_corr__( target_dataset.get_trait_data(list(sample_data.keys())) - target_data = [] - for (key, val) in target_dataset.trait_data.items(): - lts = [key] + [str(x) for x in val if x is not None] - r = ",".join(lts) - target_data.append(r) + + def __merge_key_and_values__(rows, current): + wo_nones = [value for value in current[1] if value is not None] + if len(wo_nones) > 0: + return rows + [[current[0]] + wo_nones] + return rows + + target_data = reduce( + __merge_key_and_values__, target_dataset.trait_data.items(), []) if len(target_data) == 0: return {} -- cgit v1.2.3