@@ -179,7 +179,26 @@ cdef class Reducer:
179
179
return result
180
180
181
181
182
- cdef class SeriesBinGrouper:
182
+ cdef class _BaseGrouper:
183
+ cdef _check_dummy(self , dummy):
184
+ # both values and index must be an ndarray!
185
+
186
+ values = dummy.values
187
+ # GH 23683: datetimetz types are equivalent to datetime types here
188
+ if (dummy.dtype != self .arr.dtype
189
+ and values.dtype != self .arr.dtype):
190
+ raise ValueError (' Dummy array must be same dtype' )
191
+ if util.is_array(values) and not values.flags.contiguous:
192
+ # e.g. Categorical has no `flags` attribute
193
+ values = values.copy()
194
+ index = dummy.index.values
195
+ if not index.flags.contiguous:
196
+ index = index.copy()
197
+
198
+ return values, index
199
+
200
+
201
+ cdef class SeriesBinGrouper(_BaseGrouper):
183
202
"""
184
203
Performs grouping operation according to bin edges, rather than labels
185
204
"""
@@ -216,21 +235,6 @@ cdef class SeriesBinGrouper:
216
235
else :
217
236
self .ngroups = len (bins) + 1
218
237
219
- cdef _check_dummy(self , dummy):
220
- # both values and index must be an ndarray!
221
-
222
- values = dummy.values
223
- if values.dtype != self .arr.dtype:
224
- raise ValueError (' Dummy array must be same dtype' )
225
- if util.is_array(values) and not values.flags.contiguous:
226
- # e.g. Categorical has no `flags` attribute
227
- values = values.copy()
228
- index = dummy.index.values
229
- if not index.flags.contiguous:
230
- index = index.copy()
231
-
232
- return values, index
233
-
234
238
def get_result (self ):
235
239
cdef:
236
240
ndarray arr, result
@@ -304,7 +308,7 @@ cdef class SeriesBinGrouper:
304
308
return result, counts
305
309
306
310
307
- cdef class SeriesGrouper:
311
+ cdef class SeriesGrouper(_BaseGrouper) :
308
312
"""
309
313
Performs generic grouping operation while avoiding ndarray construction
310
314
overhead
@@ -340,23 +344,6 @@ cdef class SeriesGrouper:
340
344
self .dummy_arr, self .dummy_index = self ._check_dummy(dummy)
341
345
self .ngroups = ngroups
342
346
343
- cdef _check_dummy(self , dummy):
344
- # both values and index must be an ndarray!
345
-
346
- values = dummy.values
347
- # GH 23683: datetimetz types are equivalent to datetime types here
348
- if (dummy.dtype != self .arr.dtype
349
- and values.dtype != self .arr.dtype):
350
- raise ValueError (' Dummy array must be same dtype' )
351
- if util.is_array(values) and not values.flags.contiguous:
352
- # e.g. Categorical has no `flags` attribute
353
- values = values.copy()
354
- index = dummy.index.values
355
- if not index.flags.contiguous:
356
- index = index.copy()
357
-
358
- return values, index
359
-
360
347
def get_result (self ):
361
348
cdef:
362
349
# Define result to avoid UnboundLocalError
0 commit comments