Skip to content

Commit 7a93706

Browse files
authored
fix the np.delete bug (#653)
* fix the `np.delete` bug * fix the `np.delete` bug, add unittest code * increment the version number and update the change log * update the expected file `delete.py.exp`
1 parent e329206 commit 7a93706

File tree

5 files changed

+64
-1
lines changed

5 files changed

+64
-1
lines changed

code/numpy/transform.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ static mp_obj_t transform_delete(size_t n_args, const mp_obj_t *pos_args, mp_map
204204
mp_raise_TypeError(MP_ERROR_TEXT("wrong index type"));
205205
}
206206
index_len = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(indices));
207+
if (index_len == 0){
208+
// if the second positional argument is empty
209+
// return the original array
210+
return MP_OBJ_FROM_PTR(ndarray);
211+
}
207212
}
208213

209214
if(index_len > axis_len) {

code/ulab.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "user/user.h"
3434
#include "utils/utils.h"
3535

36-
#define ULAB_VERSION 6.4.2
36+
#define ULAB_VERSION 6.4.3
3737
#define xstr(s) str(s)
3838
#define str(s) #s
3939

docs/ulab-change-log.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Mon, 25 Dec 2023
2+
3+
version 6.4.3
4+
5+
fix the 'np.delete' error that occurs when passing an empty iterable object as the second positional argument (#653)
6+
17
Thu, 11 Dec 2023
28

39
version 6.4.2

tests/2d/numpy/delete.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
a = np.array(range(25), dtype=dtype).reshape((5,5))
1212
print(np.delete(a, [1, 2], axis=0))
1313
print(np.delete(a, [1, 2], axis=1))
14+
print(np.delete(a, [], axis=1))
1415
print(np.delete(a, [1, 5, 10]))
16+
print(np.delete(a, []))
1517

1618
for dtype in dtypes:
1719
a = np.array(range(25), dtype=dtype).reshape((5,5))

tests/2d/numpy/delete.py.exp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ array([[0, 3, 4],
66
[10, 13, 14],
77
[15, 18, 19],
88
[20, 23, 24]], dtype=uint8)
9+
array([[0, 1, 2, 3, 4],
10+
[5, 6, 7, 8, 9],
11+
[10, 11, 12, 13, 14],
12+
[15, 16, 17, 18, 19],
13+
[20, 21, 22, 23, 24]], dtype=uint8)
914
array([0, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], dtype=uint8)
15+
array([[0, 1, 2, 3, 4],
16+
[5, 6, 7, 8, 9],
17+
[10, 11, 12, 13, 14],
18+
[15, 16, 17, 18, 19],
19+
[20, 21, 22, 23, 24]], dtype=uint8)
1020
array([[0, 1, 2, 3, 4],
1121
[15, 16, 17, 18, 19],
1222
[20, 21, 22, 23, 24]], dtype=int8)
@@ -15,7 +25,17 @@ array([[0, 3, 4],
1525
[10, 13, 14],
1626
[15, 18, 19],
1727
[20, 23, 24]], dtype=int8)
28+
array([[0, 1, 2, 3, 4],
29+
[5, 6, 7, 8, 9],
30+
[10, 11, 12, 13, 14],
31+
[15, 16, 17, 18, 19],
32+
[20, 21, 22, 23, 24]], dtype=int8)
1833
array([0, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], dtype=int8)
34+
array([[0, 1, 2, 3, 4],
35+
[5, 6, 7, 8, 9],
36+
[10, 11, 12, 13, 14],
37+
[15, 16, 17, 18, 19],
38+
[20, 21, 22, 23, 24]], dtype=int8)
1939
array([[0, 1, 2, 3, 4],
2040
[15, 16, 17, 18, 19],
2141
[20, 21, 22, 23, 24]], dtype=uint16)
@@ -24,7 +44,17 @@ array([[0, 3, 4],
2444
[10, 13, 14],
2545
[15, 18, 19],
2646
[20, 23, 24]], dtype=uint16)
47+
array([[0, 1, 2, 3, 4],
48+
[5, 6, 7, 8, 9],
49+
[10, 11, 12, 13, 14],
50+
[15, 16, 17, 18, 19],
51+
[20, 21, 22, 23, 24]], dtype=uint16)
2752
array([0, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], dtype=uint16)
53+
array([[0, 1, 2, 3, 4],
54+
[5, 6, 7, 8, 9],
55+
[10, 11, 12, 13, 14],
56+
[15, 16, 17, 18, 19],
57+
[20, 21, 22, 23, 24]], dtype=uint16)
2858
array([[0, 1, 2, 3, 4],
2959
[15, 16, 17, 18, 19],
3060
[20, 21, 22, 23, 24]], dtype=int16)
@@ -33,7 +63,17 @@ array([[0, 3, 4],
3363
[10, 13, 14],
3464
[15, 18, 19],
3565
[20, 23, 24]], dtype=int16)
66+
array([[0, 1, 2, 3, 4],
67+
[5, 6, 7, 8, 9],
68+
[10, 11, 12, 13, 14],
69+
[15, 16, 17, 18, 19],
70+
[20, 21, 22, 23, 24]], dtype=int16)
3671
array([0, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], dtype=int16)
72+
array([[0, 1, 2, 3, 4],
73+
[5, 6, 7, 8, 9],
74+
[10, 11, 12, 13, 14],
75+
[15, 16, 17, 18, 19],
76+
[20, 21, 22, 23, 24]], dtype=int16)
3777
array([[0.0, 1.0, 2.0, 3.0, 4.0],
3878
[15.0, 16.0, 17.0, 18.0, 19.0],
3979
[20.0, 21.0, 22.0, 23.0, 24.0]], dtype=float64)
@@ -42,7 +82,17 @@ array([[0.0, 3.0, 4.0],
4282
[10.0, 13.0, 14.0],
4383
[15.0, 18.0, 19.0],
4484
[20.0, 23.0, 24.0]], dtype=float64)
85+
array([[0.0, 1.0, 2.0, 3.0, 4.0],
86+
[5.0, 6.0, 7.0, 8.0, 9.0],
87+
[10.0, 11.0, 12.0, 13.0, 14.0],
88+
[15.0, 16.0, 17.0, 18.0, 19.0],
89+
[20.0, 21.0, 22.0, 23.0, 24.0]], dtype=float64)
4590
array([0.0, 2.0, 3.0, 4.0, 6.0, 7.0, 8.0, 9.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0], dtype=float64)
91+
array([[0.0, 1.0, 2.0, 3.0, 4.0],
92+
[5.0, 6.0, 7.0, 8.0, 9.0],
93+
[10.0, 11.0, 12.0, 13.0, 14.0],
94+
[15.0, 16.0, 17.0, 18.0, 19.0],
95+
[20.0, 21.0, 22.0, 23.0, 24.0]], dtype=float64)
4696
array([[0, 1, 2, 3, 4],
4797
[5, 6, 7, 8, 9],
4898
[15, 16, 17, 18, 19],

0 commit comments

Comments
 (0)