@@ -119,6 +119,59 @@ def group_last_object(ndarray[object, ndim=2] out,
119
119
else :
120
120
out[i, j] = resx[i, j]
121
121
122
+ @ cython.boundscheck (False )
123
+ @ cython.wraparound (False )
124
+ def group_rank_object (ndarray[float64_t , ndim = 2 ] out,
125
+ ndarray[object , ndim = 2 ] values,
126
+ ndarray[int64_t] labels ,
127
+ bint is_datetimelike , **kwargs ):
128
+ """
129
+ Only transforms on axis=0
130
+ """
131
+ cdef:
132
+ int tiebreak
133
+ Py_ssize_t i, j, N, K
134
+ int64_t val_start= 0 , grp_start= 0 , dups= 0 , sum_ranks= 0
135
+ ndarray[int64_t] _as
136
+
137
+ tiebreak = tiebreakers[kwargs[' ties_method' ]]
138
+ N, K = (< object > values).shape
139
+
140
+ _as = np.lexsort((values[:, 0 ], labels))
141
+
142
+ for i in range (N):
143
+ dups += 1
144
+ sum_ranks += i - grp_start + 1
145
+
146
+ if tiebreak == TIEBREAK_AVERAGE:
147
+ for j in range (i - dups + 1 , i + 1 ):
148
+ out[_as[j], 0 ] = sum_ranks / dups
149
+ elif tiebreak == TIEBREAK_MIN:
150
+ for j in range (i - dups + 1 , i + 1 ):
151
+ out[_as[j], 0 ] = i - grp_start - dups + 2
152
+ elif tiebreak == TIEBREAK_MAX:
153
+ for j in range (i - dups + 1 , i + 1 ):
154
+ out[_as[j], 0 ] = i - grp_start + 1
155
+ elif tiebreak == TIEBREAK_FIRST:
156
+ for j in range (i - dups + 1 , i + 1 ):
157
+ out[_as[j], 0 ] = j + 1
158
+ elif tiebreak == TIEBREAK_FIRST_DESCENDING:
159
+ for j in range (i - dups + 1 , i + 1 ):
160
+ out[_as[j], 0 ] = 2 * (i - grp_start) - j - dups + 2
161
+ elif tiebreak == TIEBREAK_DENSE:
162
+ for j in range (i - dups + 1 , i + 1 ):
163
+ out[_as[j], 0 ] = val_start - grp_start
164
+
165
+ if (i == N - 1 or (
166
+ (values[_as[i], 0 ] != values[_as[i+ 1 ], 0 ]) and not
167
+ (values[_as[i], 0 ] is np.nan and values[_as[i+ 1 ], 0 ] is np.nan)
168
+ )):
169
+ dups = sum_ranks = 0
170
+ val_start = i
171
+
172
+ if i == 0 or labels[_as[i]] != labels[_as[i- 1 ]]:
173
+ grp_start = i
174
+
122
175
123
176
cdef inline float64_t median_linear(float64_t* a, int n) nogil:
124
177
cdef int i, j, na_count = 0
0 commit comments