aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2021-07-22 12:06:17 +0300
committerMuriithi Frederick Muriuki2021-07-22 12:06:17 +0300
commit6561bc76e14e7846beb90442d3fb562a2e0e4fe8 (patch)
treeb555cd58e2d0d16a4eec581831608175a5224185
parent830b4b1f36d46b230544175169262b03526720c1 (diff)
downloadgenenetwork3-6561bc76e14e7846beb90442d3fb562a2e0e4fe8.tar.gz
Check that list and its direct children are not empty
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * Add code to pass the test that the list/tuple passed to `nearest' and its direct children lists/tuples are not empty.
-rw-r--r--gn3/computations/slink.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/gn3/computations/slink.py b/gn3/computations/slink.py
index d6f6028..704a0f4 100644
--- a/gn3/computations/slink.py
+++ b/gn3/computations/slink.py
@@ -12,6 +12,14 @@ def raise_valueerror_if_data_is_not_lists_or_tuples(lists):
if (not is_list_or_tuple(lists)) or (not all(map(is_list_or_tuple, lists))):
raise ValueError("Expected list or tuple")
+def raise_valueerror_if_lists_empty(lists):
+ """Check that the list and its direct children are not empty."""
+ def empty(lst):
+ return len(lst) == 0
+ if (empty(lists)) or not all(map(lambda x: not empty(x), lists)):
+ raise ValueError("List/Tuple should NOT be empty!")
+
def nearest(lists, i, j):
raise_valueerror_if_data_is_not_lists_or_tuples(lists)
+ raise_valueerror_if_lists_empty(lists)
return None