aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorBonfaceKilz2022-03-18 15:39:19 +0300
committerBonfaceKilz2022-03-18 15:50:00 +0300
commit490a9c2306d9b05e132b1fcef6cd65a985a14b71 (patch)
treed39a582509e4e26c8481324f75d79a793b3620cd /gn3
parent16367dab9248d3aa2660e0b5cafdce25e8f7067c (diff)
downloadgenenetwork3-490a9c2306d9b05e132b1fcef6cd65a985a14b71.tar.gz
Create new function for cleaning individual fields in csv text
* gn3/csvcmp.py (clean_csv_text): New function. * tests/unit/test_csvcmp.py: Import "csv_text". (test_clean_csv_text): Test case for the above.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/csvcmp.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/gn3/csvcmp.py b/gn3/csvcmp.py
index 975814a..10c5d3e 100644
--- a/gn3/csvcmp.py
+++ b/gn3/csvcmp.py
@@ -48,6 +48,15 @@ def remove_insignificant_edits(diff_data, epsilon=0.001):
return diff_data
+def clean_csv_text(csv_text: str) -> str:
+ """Remove extra white space elements in all elements of the CSV file"""
+ _csv_text = []
+ for line in csv_text.strip().split("\n"):
+ _csv_text.append(
+ ",".join([el.strip() for el in line.split(",")]))
+ return "\n".join(_csv_text)
+
+
def csv_diff(base_csv, delta_csv, tmp_dir="/tmp") -> dict:
"""Diff 2 csv strings"""
base_csv_list = base_csv.strip().split("\n")