Skip to content

Commit 5048514

Browse files
authored
feat: support py310 (#155)
* fix: correct 'np.bool' to 'bool' for numpy compatibility * fix: fix adependency versions to resolve compatibility issues * fix: repair cython files all against nogil position deprecation --------- Co-authored-by: 0x79ff <yangff@lamda.nju.edu.cn>
1 parent 96e762b commit 5048514

11 files changed

Lines changed: 56 additions & 56 deletions

File tree

deepforest/_cutils.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ cpdef np.ndarray _c_sample_mask(const INT32_t [:] indices,
4444
SIZE_t n = indices.shape[0]
4545
SIZE_t sample_id
4646
np.ndarray[BOOL, ndim=1] sample_mask = np.zeros((n_samples,),
47-
dtype=np.bool)
47+
dtype=bool)
4848

4949
with nogil:
5050
for i in range(n):

deepforest/tree/_criterion.pxd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ cdef class Criterion:
4646
# Methods
4747
cdef int init(self, const DOUBLE_t[:, ::1] y, DOUBLE_t* sample_weight,
4848
double weighted_n_samples, SIZE_t* samples, SIZE_t start,
49-
SIZE_t end) nogil except -1
50-
cdef int reset(self) nogil except -1
51-
cdef int reverse_reset(self) nogil except -1
52-
cdef int update(self, SIZE_t new_pos) nogil except -1
49+
SIZE_t end) except -1 nogil
50+
cdef int reset(self) except -1 nogil
51+
cdef int reverse_reset(self) except -1 nogil
52+
cdef int update(self, SIZE_t new_pos) except -1 nogil
5353
cdef double node_impurity(self) nogil
5454
cdef void children_impurity(self, double* impurity_left,
5555
double* impurity_right) nogil

deepforest/tree/_criterion.pyx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ cdef class Criterion:
4343

4444
cdef int init(self, const DOUBLE_t[:, ::1] y, DOUBLE_t* sample_weight,
4545
double weighted_n_samples, SIZE_t* samples, SIZE_t start,
46-
SIZE_t end) nogil except -1:
46+
SIZE_t end) except -1 nogil:
4747
"""Placeholder for a method which will initialize the criterion.
4848
4949
Returns -1 in case of failure to allocate memory (and raise MemoryError)
@@ -69,22 +69,22 @@ cdef class Criterion:
6969

7070
pass
7171

72-
cdef int reset(self) nogil except -1:
72+
cdef int reset(self) except -1 nogil:
7373
"""Reset the criterion at pos=start.
7474
7575
This method must be implemented by the subclass.
7676
"""
7777

7878
pass
7979

80-
cdef int reverse_reset(self) nogil except -1:
80+
cdef int reverse_reset(self) except -1 nogil:
8181
"""Reset the criterion at pos=end.
8282
8383
This method must be implemented by the subclass.
8484
"""
8585
pass
8686

87-
cdef int update(self, SIZE_t new_pos) nogil except -1:
87+
cdef int update(self, SIZE_t new_pos) except -1 nogil:
8888
"""Updated statistics by moving samples[pos:new_pos] to the left child.
8989
9090
This updates the collected statistics by moving samples[pos:new_pos]
@@ -268,7 +268,7 @@ cdef class ClassificationCriterion(Criterion):
268268

269269
cdef int init(self, const DOUBLE_t[:, ::1] y,
270270
DOUBLE_t* sample_weight, double weighted_n_samples,
271-
SIZE_t* samples, SIZE_t start, SIZE_t end) nogil except -1:
271+
SIZE_t* samples, SIZE_t start, SIZE_t end) except -1 nogil:
272272
"""Initialize the criterion at node samples[start:end] and
273273
children samples[start:start] and samples[start:end].
274274
@@ -333,7 +333,7 @@ cdef class ClassificationCriterion(Criterion):
333333
self.reset()
334334
return 0
335335

336-
cdef int reset(self) nogil except -1:
336+
cdef int reset(self) except -1 nogil:
337337
"""Reset the criterion at pos=start
338338
339339
Returns -1 in case of failure to allocate memory (and raise MemoryError)
@@ -360,7 +360,7 @@ cdef class ClassificationCriterion(Criterion):
360360
sum_right += self.sum_stride
361361
return 0
362362

363-
cdef int reverse_reset(self) nogil except -1:
363+
cdef int reverse_reset(self) except -1 nogil:
364364
"""Reset the criterion at pos=end
365365
366366
Returns -1 in case of failure to allocate memory (and raise MemoryError)
@@ -387,7 +387,7 @@ cdef class ClassificationCriterion(Criterion):
387387
sum_right += self.sum_stride
388388
return 0
389389

390-
cdef int update(self, SIZE_t new_pos) nogil except -1:
390+
cdef int update(self, SIZE_t new_pos) except -1 nogil:
391391
"""Updated statistics by moving samples[pos:new_pos] to the left child.
392392
393393
Returns -1 in case of failure to allocate memory (and raise MemoryError)
@@ -729,7 +729,7 @@ cdef class RegressionCriterion(Criterion):
729729

730730
cdef int init(self, const DOUBLE_t[:, ::1] y, DOUBLE_t* sample_weight,
731731
double weighted_n_samples, SIZE_t* samples, SIZE_t start,
732-
SIZE_t end) nogil except -1:
732+
SIZE_t end) except -1 nogil:
733733
"""Initialize the criterion at node samples[start:end] and
734734
children samples[start:start] and samples[start:end]."""
735735
# Initialize fields
@@ -770,7 +770,7 @@ cdef class RegressionCriterion(Criterion):
770770
self.reset()
771771
return 0
772772

773-
cdef int reset(self) nogil except -1:
773+
cdef int reset(self) except -1 nogil:
774774
"""Reset the criterion at pos=start."""
775775
cdef SIZE_t n_bytes = self.n_outputs * sizeof(double)
776776
memset(self.sum_left, 0, n_bytes)
@@ -781,7 +781,7 @@ cdef class RegressionCriterion(Criterion):
781781
self.pos = self.start
782782
return 0
783783

784-
cdef int reverse_reset(self) nogil except -1:
784+
cdef int reverse_reset(self) except -1 nogil:
785785
"""Reset the criterion at pos=end."""
786786
cdef SIZE_t n_bytes = self.n_outputs * sizeof(double)
787787
memset(self.sum_right, 0, n_bytes)
@@ -792,7 +792,7 @@ cdef class RegressionCriterion(Criterion):
792792
self.pos = self.end
793793
return 0
794794

795-
cdef int update(self, SIZE_t new_pos) nogil except -1:
795+
cdef int update(self, SIZE_t new_pos) except -1 nogil:
796796
"""Updated statistics by moving samples[pos:new_pos] to the left."""
797797

798798
cdef double* sum_left = self.sum_left
@@ -1013,7 +1013,7 @@ cdef class MAE(RegressionCriterion):
10131013

10141014
cdef int init(self, const DOUBLE_t[:, ::1] y, DOUBLE_t* sample_weight,
10151015
double weighted_n_samples, SIZE_t* samples, SIZE_t start,
1016-
SIZE_t end) nogil except -1:
1016+
SIZE_t end) except -1 nogil:
10171017
"""Initialize the criterion at node samples[start:end] and
10181018
children samples[start:start] and samples[start:end]."""
10191019

@@ -1061,7 +1061,7 @@ cdef class MAE(RegressionCriterion):
10611061
self.reset()
10621062
return 0
10631063

1064-
cdef int reset(self) nogil except -1:
1064+
cdef int reset(self) except -1 nogil:
10651065
"""Reset the criterion at pos=start
10661066
10671067
Returns -1 in case of failure to allocate memory (and raise MemoryError)
@@ -1093,7 +1093,7 @@ cdef class MAE(RegressionCriterion):
10931093
weight)
10941094
return 0
10951095

1096-
cdef int reverse_reset(self) nogil except -1:
1096+
cdef int reverse_reset(self) except -1 nogil:
10971097
"""Reset the criterion at pos=end
10981098
10991099
Returns -1 in case of failure to allocate memory (and raise MemoryError)
@@ -1122,7 +1122,7 @@ cdef class MAE(RegressionCriterion):
11221122
weight)
11231123
return 0
11241124

1125-
cdef int update(self, SIZE_t new_pos) nogil except -1:
1125+
cdef int update(self, SIZE_t new_pos) except -1 nogil:
11261126
"""Updated statistics by moving samples[pos:new_pos] to the left
11271127
11281128
Returns -1 in case of failure to allocate memory (and raise MemoryError)

deepforest/tree/_splitter.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ cdef class Splitter:
7474
np.ndarray X_idx_sorted=*) except -1
7575

7676
cdef int node_reset(self, SIZE_t start, SIZE_t end,
77-
double* weighted_n_node_samples) nogil except -1
77+
double* weighted_n_node_samples) except -1 nogil
7878

7979
cdef int node_split(self,
8080
double impurity, # Impurity of the node
8181
SplitRecord* split,
82-
SIZE_t* n_constant_features) nogil except -1
82+
SIZE_t* n_constant_features) except -1 nogil
8383

8484
cdef void node_value(self, double* dest) nogil
8585

deepforest/tree/_splitter.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ cdef class Splitter:
169169
return 0
170170

171171
cdef int node_reset(self, SIZE_t start, SIZE_t end,
172-
double* weighted_n_node_samples) nogil except -1:
172+
double* weighted_n_node_samples) except -1 nogil:
173173
"""Reset splitter on node samples[start:end].
174174
175175
Returns -1 in case of failure to allocate memory (and raise MemoryError)
@@ -199,7 +199,7 @@ cdef class Splitter:
199199
return 0
200200

201201
cdef int node_split(self, double impurity, SplitRecord* split,
202-
SIZE_t* n_constant_features) nogil except -1:
202+
SIZE_t* n_constant_features) except -1 nogil:
203203
"""Find the best split on node samples[start:end].
204204
205205
This is a placeholder method. The majority of computation will be done
@@ -266,7 +266,7 @@ cdef class BestSplitter(BaseDenseSplitter):
266266
self.random_state), self.__getstate__())
267267

268268
cdef int node_split(self, double impurity, SplitRecord* split,
269-
SIZE_t* n_constant_features) nogil except -1:
269+
SIZE_t* n_constant_features) except -1 nogil:
270270
"""Find the best split on node samples[start:end]
271271
272272
Returns -1 in case of failure to allocate memory (and raise MemoryError)
@@ -582,7 +582,7 @@ cdef class RandomSplitter(BaseDenseSplitter):
582582
self.random_state), self.__getstate__())
583583

584584
cdef int node_split(self, double impurity, SplitRecord* split,
585-
SIZE_t* n_constant_features) nogil except -1:
585+
SIZE_t* n_constant_features) except -1 nogil:
586586
"""Find the best random split on node samples[start:end]
587587
588588
Returns -1 in case of failure to allocate memory (and raise MemoryError)
@@ -1100,7 +1100,7 @@ cdef class BestSparseSplitter(BaseSparseSplitter):
11001100
self.random_state), self.__getstate__())
11011101

11021102
cdef int node_split(self, double impurity, SplitRecord* split,
1103-
SIZE_t* n_constant_features) nogil except -1:
1103+
SIZE_t* n_constant_features) except -1 nogil:
11041104
"""Find the best split on node samples[start:end], using sparse features
11051105
11061106
Returns -1 in case of failure to allocate memory (and raise MemoryError)
@@ -1329,7 +1329,7 @@ cdef class RandomSparseSplitter(BaseSparseSplitter):
13291329
self.random_state), self.__getstate__())
13301330

13311331
cdef int node_split(self, double impurity, SplitRecord* split,
1332-
SIZE_t* n_constant_features) nogil except -1:
1332+
SIZE_t* n_constant_features) except -1 nogil:
13331333
"""Find a random split on node samples[start:end], using sparse features
13341334
13351335
Returns -1 in case of failure to allocate memory (and raise MemoryError)

deepforest/tree/_tree.pxd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ cdef class Tree:
4343
cdef SIZE_t value_stride # = n_outputs * max_n_classes
4444

4545
# Methods
46-
cdef SIZE_t _upd_parent(self, SIZE_t parent, bint is_left) nogil except -1
46+
cdef SIZE_t _upd_parent(self, SIZE_t parent, bint is_left) except -1 nogil
4747
cdef SIZE_t _add_node(self, SIZE_t parent, bint is_left, bint is_leaf,
48-
SIZE_t feature, DTYPE_t threshold) nogil except -1
48+
SIZE_t feature, DTYPE_t threshold) except -1 nogil
4949
cdef int _resize(self, SIZE_t internal_capacity,
50-
SIZE_t leaf_capacity) nogil except -1
51-
cdef int _resize_node_c(self, SIZE_t internal_capacity=*) nogil except -1
52-
cdef int _resize_value_c(self, SIZE_t leaf_capacity=*) nogil except -1
50+
SIZE_t leaf_capacity) except -1 nogil
51+
cdef int _resize_node_c(self, SIZE_t internal_capacity=*) except -1 nogil
52+
cdef int _resize_value_c(self, SIZE_t leaf_capacity=*) except -1 nogil
5353

5454
cdef np.ndarray _get_value_ndarray(self)
5555
cdef np.ndarray _get_node_ndarray(self)

deepforest/tree/_tree.pyx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ cdef class Tree:
441441
self.internal_node_count * sizeof(Node))
442442

443443
cdef int _resize(self, SIZE_t internal_capacity,
444-
SIZE_t leaf_capacity) nogil except -1:
444+
SIZE_t leaf_capacity) except -1 nogil:
445445
"""Resize `self.nodes` to `internal_capacity`, and resize `self.value`
446446
to `leaf_capacity`.
447447
@@ -461,7 +461,7 @@ cdef class Tree:
461461
leaf_capacity)
462462

463463
cdef int _resize_node_c(self,
464-
SIZE_t internal_capacity=SIZE_MAX) nogil except -1:
464+
SIZE_t internal_capacity=SIZE_MAX) except -1 nogil:
465465
"""Resize `self.nodes` to `internal_capacity`.
466466
467467
Returns -1 in case of failure to allocate memory (and raise
@@ -486,7 +486,7 @@ cdef class Tree:
486486
return 0
487487

488488
cdef int _resize_value_c(self,
489-
SIZE_t leaf_capacity=SIZE_MAX) nogil except -1:
489+
SIZE_t leaf_capacity=SIZE_MAX) except -1 nogil:
490490
"""Resize `self.value` to `leaf_capacity`.
491491
492492
Returns -1 in case of failure to allocate memory (and raise
@@ -516,7 +516,7 @@ cdef class Tree:
516516
self.leaf_capacity = leaf_capacity
517517
return 0
518518

519-
cdef SIZE_t _upd_parent(self, SIZE_t parent, bint is_left) nogil except -1:
519+
cdef SIZE_t _upd_parent(self, SIZE_t parent, bint is_left) except -1 nogil:
520520
"""Add a leaf node to the tree and connect it with its parent. Notice
521521
that `self.nodes` does not store any information on leaf nodes except
522522
the id of leaf nodes. In addition, the id of leaf nodes are multiplied
@@ -543,7 +543,7 @@ cdef class Tree:
543543
return node_id
544544

545545
cdef SIZE_t _add_node(self, SIZE_t parent, bint is_left, bint is_leaf,
546-
SIZE_t feature, DTYPE_t threshold) nogil except -1:
546+
SIZE_t feature, DTYPE_t threshold) except -1 nogil:
547547
"""Add an internal node to the tree.
548548
549549
The new node registers itself as the child of its parent.

deepforest/tree/_utils.pxd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ctypedef fused realloc_ptr:
3737
(StackRecord*)
3838
(PriorityHeapRecord*)
3939

40-
cdef realloc_ptr safe_realloc(realloc_ptr* p, size_t nelems) nogil except *
40+
cdef realloc_ptr safe_realloc(realloc_ptr* p, size_t nelems) except * nogil
4141

4242

4343
cdef np.ndarray sizet_ptr_to_ndarray(SIZE_t* data, SIZE_t size)
@@ -75,7 +75,7 @@ cdef class Stack:
7575
cdef bint is_empty(self) nogil
7676
cdef int push(self, SIZE_t start, SIZE_t end, SIZE_t depth, SIZE_t parent,
7777
bint is_left, double impurity,
78-
SIZE_t n_constant_features) nogil except -1
78+
SIZE_t n_constant_features) except -1 nogil
7979
cdef int pop(self, StackRecord* res) nogil
8080

8181

@@ -107,7 +107,7 @@ cdef class PriorityHeap:
107107
cdef int push(self, SIZE_t node_id, SIZE_t start, SIZE_t end, SIZE_t pos,
108108
SIZE_t depth, bint is_leaf, double improvement,
109109
double impurity, double impurity_left,
110-
double impurity_right) nogil except -1
110+
double impurity_right) except -1 nogil
111111
cdef int pop(self, PriorityHeapRecord* res) nogil
112112

113113
# =============================================================================
@@ -125,9 +125,9 @@ cdef class WeightedPQueue:
125125
cdef WeightedPQueueRecord* array_
126126

127127
cdef bint is_empty(self) nogil
128-
cdef int reset(self) nogil except -1
128+
cdef int reset(self) except -1 nogil
129129
cdef SIZE_t size(self) nogil
130-
cdef int push(self, DOUBLE_t data, DOUBLE_t weight) nogil except -1
130+
cdef int push(self, DOUBLE_t data, DOUBLE_t weight) except -1 nogil
131131
cdef int remove(self, DOUBLE_t data, DOUBLE_t weight) nogil
132132
cdef int pop(self, DOUBLE_t* data, DOUBLE_t* weight) nogil
133133
cdef int peek(self, DOUBLE_t* data, DOUBLE_t* weight) nogil
@@ -148,8 +148,8 @@ cdef class WeightedMedianCalculator:
148148
# = w[0] + w[1] + ... + w[k-1]
149149

150150
cdef SIZE_t size(self) nogil
151-
cdef int push(self, DOUBLE_t data, DOUBLE_t weight) nogil except -1
152-
cdef int reset(self) nogil except -1
151+
cdef int push(self, DOUBLE_t data, DOUBLE_t weight) except -1 nogil
152+
cdef int reset(self) except -1 nogil
153153
cdef int update_median_parameters_post_push(
154154
self, DOUBLE_t data, DOUBLE_t weight,
155155
DOUBLE_t original_median) nogil

0 commit comments

Comments
 (0)