From 830b4b1f36d46b230544175169262b03526720c1 Mon Sep 17 00:00:00 2001 From: Muriithi Frederick Muriuki Date: Thu, 22 Jul 2021 11:43:39 +0300 Subject: Implement check for lists or tuples Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * Implement the code to pass the check that a list of lists is passed to the `nearest' function. --- gn3/computations/slink.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'gn3') diff --git a/gn3/computations/slink.py b/gn3/computations/slink.py index bec8597..d6f6028 100644 --- a/gn3/computations/slink.py +++ b/gn3/computations/slink.py @@ -4,5 +4,14 @@ class LengthError(BaseException): class MirrorError(BaseException): pass +def raise_valueerror_if_data_is_not_lists_or_tuples(lists): + """Check that `lists` is a list of lists: If not, raise an exception.""" + def is_list_or_tuple(item): + return type(item) == type([]) or type(item) == type(tuple) + + if (not is_list_or_tuple(lists)) or (not all(map(is_list_or_tuple, lists))): + raise ValueError("Expected list or tuple") + def nearest(lists, i, j): + raise_valueerror_if_data_is_not_lists_or_tuples(lists) return None -- cgit v1.2.3