This commit is contained in:
Willi Richert 2016-05-23 20:23:53 +02:00
Родитель 4a3e8da082
Коммит bdb12716f7
2 изменённых файлов: 10 добавлений и 6 удалений

Просмотреть файл

@ -132,8 +132,11 @@ class ComputationNode(object):
# Case 2: e.g. data[2:4] -> key will be a slice object
if key.step is not None:
raise TypeError('step argument is not supported')
if isinstance(so.start, int) and isinstance(so.stop, int):
if so.stop<=so.start:
if not isinstance(key.stop, int):
raise TypeError('end index has to be of type int, not "%s"'%type(key.stop))
if isinstance(key.start, int):
if key.stop<=key.start:
raise ValueError('end index has to be greater than start index')
return ops.slice(self, key.start or 0, key.stop or 0, axis=0)

Просмотреть файл

@ -45,12 +45,13 @@ def test_overload_types(root_node, expected):
def test_overload_exception():
with pytest.raises(ValueError):
C(range(0, 10))[:]
c = C(list(range(0, 10)))
with pytest.raises(ValueError):
C(range(0, 10))[0:3:2]
with pytest.raises(TypeError):
c[:]
with pytest.raises(TypeError):
c[0:3:2]
def _to_list(desc):
return [line.strip() for line in desc.split('\n')]