From 6561bc76e14e7846beb90442d3fb562a2e0e4fe8 Mon Sep 17 00:00:00 2001 From: Muriithi Frederick Muriuki Date: Thu, 22 Jul 2021 12:06:17 +0300 Subject: 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. --- gn3/computations/slink.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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 -- cgit v1.2.3