aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-07-12 16:02:51 +0300
committerFrederick Muriuki Muriithi2023-07-12 16:02:51 +0300
commitf05f90a60f561e24312a4e7db5dbcc34d69c8cdc (patch)
tree744cce6eb43e4c90225854558f05838c99e89614
parent477c3f34f8af919592c722cc1a71b2602cb7ac82 (diff)
downloadgenenetwork2-f05f90a60f561e24312a4e7db5dbcc34d69c8cdc.tar.gz
Fix check for numeric values
The `str.isnumeric()` function returns false for numbers such as '9.99', '88.8' etc. This commit provides a slightly more robust check for strings that are numbers. It will fail for numbers with exponents though.
-rw-r--r--wqflask/wqflask/metadata_edits.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py
index 69732dfe..9f744909 100644
--- a/wqflask/wqflask/metadata_edits.py
+++ b/wqflask/wqflask/metadata_edits.py
@@ -1,3 +1,4 @@
+import re
import datetime
import json
import os
@@ -814,6 +815,10 @@ def approve_data(resource_id: str, file_name: str):
)
return redirect(url_for("metadata_edit.list_diffs"))
+def is_a_number(value: str):
+ """Check whether the string is a number"""
+ return bool(re.search(r"^[0-9]+\.*[0-9]*$", value))
+
def create_delta_csv(base_csv, form_data, sample_list):
base_csv_lines = base_csv.split("\n")
delta_csv_lines = [base_csv_lines[0]]
@@ -825,9 +830,10 @@ def create_delta_csv(base_csv, form_data, sample_list):
if sample['name'] in key:
new_line_items = [sample['name']]
for field in ["value", "error", "n_cases"]:
- if form_data.get(field + ":" + sample['name']):
- if form_data.get(field + ":" + sample['name']).isnumeric():
- new_line_items.append(form_data.get(field + ":" + sample['name']))
+ the_value = form_data.get(f"{field}:{sample['name']}")
+ if the_value:
+ if is_a_number(the_value):
+ new_line_items.append(the_value)
continue
new_line_items.append(sample[field])
delta_csv_lines.append(",".join(new_line_items))