From 1e22f8e329122c06f8c7fec9ae7232796079e7bc Mon Sep 17 00:00:00 2001 From: mavaylon1 Date: Thu, 24 Oct 2024 08:11:07 -0700 Subject: [PATCH] region --- src/hdmf/array.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++ src/hdmf/region.py | 2 ++ 2 files changed, 60 insertions(+) diff --git a/src/hdmf/array.py b/src/hdmf/array.py index ee4c21bcf..a684572e4 100644 --- a/src/hdmf/array.py +++ b/src/hdmf/array.py @@ -93,6 +93,64 @@ def __sort(a): else: return a + def __eq__(self, other): + if isinstance(other, list): + ret = list() + for i in other: + eq = self == i + ret.append(eq) + ret = sorted(ret, key=self.__sort) + tmp = list() + for i in range(1, len(ret)): + a, b = ret[i - 1], ret[i] + if isinstance(a, tuple): + if isinstance(b, tuple): + if a[1] >= b[0]: + b[0] = a[0] + else: + tmp.append(slice(*a)) + else: + if b > a[1]: + tmp.append(slice(*a)) + elif b == a[1]: + a[1] == b + 1 + else: + ret[i] = a + else: + if isinstance(b, tuple): + if a < b[0]: + tmp.append(a) + else: + if b - a == 1: + ret[i] = (a, b) + else: + tmp.append(a) + if isinstance(ret[-1], tuple): + tmp.append(slice(*ret[-1])) + else: + tmp.append(ret[-1]) + ret = tmp + return ret + elif isinstance(other, tuple): + ge = self >= other[0] + ge = ge.start + lt = self < other[1] + lt = lt.stop + if ge == lt: + return ge + else: + return slice(ge, lt) + else: + lower = self.__lower(other) + upper = self.__upper(other) + d = upper - lower + if d == 1: + return lower + elif d == 0: + return None + else: + return slice(lower, upper) + def __ne__(self, other): eq = self == other if isinstance(eq, tuple): diff --git a/src/hdmf/region.py b/src/hdmf/region.py index 9feeba401..40df3170a 100644 --- a/src/hdmf/region.py +++ b/src/hdmf/region.py @@ -5,6 +5,7 @@ from .utils import docval, getargs +# pragma: no cover class RegionSlicer(DataRegion, metaclass=ABCMeta): ''' A abstract base class to control getting using a region @@ -51,6 +52,7 @@ def __len__(self): pass +# pragma: no cover class ListSlicer(RegionSlicer): """Implementation of RegionSlicer for slicing Lists and Data"""