File tree 2 files changed +11
-10
lines changed
2 files changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,12 @@ including other versions of pandas.
21
21
Enhancements
22
22
^^^^^^^^^^^^
23
23
24
+ .. _whatsnew_0241.performance :
25
+
26
+ Performance Improvements
27
+ ~~~~~~~~~~~~~~~~~~~~~~~~
28
+ - Significant speedup in `SparseArray ` initialization that benefits most operations, fixing performance regression introduced in v0.20.0
29
+
24
30
25
31
.. _whatsnew_0241.bug_fixes :
26
32
Original file line number Diff line number Diff line change @@ -72,9 +72,6 @@ cdef class IntIndex(SparseIndex):
72
72
A ValueError is raised if any of these conditions is violated.
73
73
"""
74
74
75
- cdef:
76
- int32_t index, prev = - 1
77
-
78
75
if self .npoints > self .length:
79
76
msg = (" Too many indices. Expected "
80
77
" {exp} but found {act}" ).format(
@@ -86,17 +83,15 @@ cdef class IntIndex(SparseIndex):
86
83
if self .npoints == 0 :
87
84
return
88
85
89
- if min ( self .indices) < 0 :
86
+ if self .indices.min( ) < 0 :
90
87
raise ValueError (" No index can be less than zero" )
91
88
92
- if max ( self .indices) >= self .length:
89
+ if self .indices.max( ) >= self .length:
93
90
raise ValueError (" All indices must be less than the length" )
94
91
95
- for index in self .indices:
96
- if prev != - 1 and index <= prev:
97
- raise ValueError (" Indices must be strictly increasing" )
98
-
99
- prev = index
92
+ monotonic = np.all(self .indices[:- 1 ] < self .indices[1 :])
93
+ if not monotonic:
94
+ raise ValueError (" Indices must be strictly increasing" )
100
95
101
96
def equals (self , other ):
102
97
if not isinstance (other, IntIndex):
You can’t perform that action at this time.
0 commit comments