diff options
author | Muriithi Frederick Muriuki | 2021-07-22 11:43:39 +0300 |
---|---|---|
committer | Muriithi Frederick Muriuki | 2021-07-22 12:05:43 +0300 |
commit | 830b4b1f36d46b230544175169262b03526720c1 (patch) | |
tree | 7c7c2d1c0a31d418c19b44a330d483c0b8d6c4af /gn3/computations/slink.py | |
parent | a5d4868c6d2f38d3e6fd0409e08413c3569ce356 (diff) | |
download | genenetwork3-830b4b1f36d46b230544175169262b03526720c1.tar.gz |
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.
Diffstat (limited to 'gn3/computations/slink.py')
-rw-r--r-- | gn3/computations/slink.py | 9 |
1 files changed, 9 insertions, 0 deletions
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 |