diff --git a/src/modules/array2d.c b/src/modules/array2d.c index 1fcd0648..b44cfd3f 100644 --- a/src/modules/array2d.c +++ b/src/modules/array2d.c @@ -361,8 +361,9 @@ static bool array2d_like__getitem__(int argc, py_Ref argv) { for(int j = 0; j < self->n_rows; j++) { for(int i = 0; i < self->n_cols; i++) { py_Ref item = self->f_get(self, i, j); - if(!py_checkbool(item)) return false; - if(py_tobool(item)) py_list_append(py_retval(), item); + py_Ref cond = mask->f_get(mask, i, j); + if(!py_checkbool(cond)) return false; + if(py_tobool(cond)) py_list_append(py_retval(), item); } } return true; @@ -410,9 +411,9 @@ static bool array2d_like__setitem__(int argc, py_Ref argv) { if(!_array2d_like_check_same_shape(self, mask)) return false; for(int j = 0; j < self->n_rows; j++) { for(int i = 0; i < self->n_cols; i++) { - py_Ref item = self->f_get(self, i, j); - if(!py_checkbool(item)) return false; - if(py_tobool(item)) { + py_Ref cond = mask->f_get(mask, i, j); + if(!py_checkbool(cond)) return false; + if(py_tobool(cond)) { bool ok = self->f_set(self, i, j, value); if(!ok) return false; } diff --git a/tests/90_array2d.py b/tests/90_array2d.py index 902c25ee..a762602a 100644 --- a/tests/90_array2d.py +++ b/tests/90_array2d.py @@ -1,10 +1,13 @@ from array2d import array2d from linalg import vec2i +def exit_on_error(): + raise KeyboardInterrupt + # test error args for __init__ try: a = array2d(0, 0) - exit(0) + exit_on_error() except ValueError: pass @@ -39,7 +42,7 @@ assert a[0, 0] == (0, 0) assert a[1, 3] == (1, 3) try: a[2, 0] - exit(1) + exit_on_error() except IndexError: pass @@ -51,7 +54,7 @@ a[1, 3] = 6 assert a[1, 3] == 6 try: a[0, -1] = 7 - exit(1) + exit_on_error() except IndexError: pass @@ -146,7 +149,7 @@ assert a.get_bounding_rect(0) == (0, 0, 5, 5) try: a.get_bounding_rect(2) - exit(1) + exit_on_error() except ValueError: pass @@ -163,16 +166,10 @@ assert a == array2d(3, 2, default=3) try: a[:, :] = array2d(1, 1) - exit(1) + exit_on_error() except ValueError: pass -try: - a[:, :] = ... - exit(1) -except TypeError: - pass - # test __iter__ a = array2d(3, 4, default=1) for xy, val in a: