support slices in FeaturesArray and KeysArray
This commit is contained in:
parent
2d338ffbfb
commit
b99ccdf612
|
@ -182,7 +182,7 @@ class FeaturesArray(object):
|
|||
|
||||
def __getitem__(self, index):
|
||||
if self._check():
|
||||
assert type(index) == int
|
||||
if isinstance(index, int):
|
||||
if index < 0 or index >= len(self.features):
|
||||
raise IndexError(index)
|
||||
|
||||
|
@ -194,6 +194,10 @@ class FeaturesArray(object):
|
|||
|
||||
return self.features[index]
|
||||
|
||||
elif isinstance(index, slice):
|
||||
indices = index.indices(len(self.features))
|
||||
return [self.__getitem__(i) for i in range(*indices)]
|
||||
|
||||
def __contains__(self, value):
|
||||
if self._check():
|
||||
ivalue = int(value)
|
||||
|
@ -262,7 +266,7 @@ class KeysArray(object):
|
|||
self.keys = [None] * count
|
||||
|
||||
def __getitem__(self, index):
|
||||
assert type(index) == int
|
||||
if isinstance(index, int):
|
||||
if index < 0 or index >= len(self.keys):
|
||||
raise IndexError(index)
|
||||
|
||||
|
@ -274,6 +278,10 @@ class KeysArray(object):
|
|||
|
||||
return self.keys[index]
|
||||
|
||||
elif isinstance(index, slice):
|
||||
indices = index.indices(len(self.keys))
|
||||
return [self.__getitem__(i) for i in range(*indices)]
|
||||
|
||||
def index(self, value):
|
||||
for index, k in enumerate(self.keys):
|
||||
if k is not None and int(value) == int(k.key):
|
||||
|
|
Loading…
Reference in New Issue