Skip to content

Commit

Permalink
region
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Oct 24, 2024
1 parent 5c6c3eb commit 1e22f8e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/hdmf/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions src/hdmf/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,6 +52,7 @@ def __len__(self):
pass


# pragma: no cover
class ListSlicer(RegionSlicer):
"""Implementation of RegionSlicer for slicing Lists and Data"""

Expand Down

0 comments on commit 1e22f8e

Please sign in to comment.