@@ -179,7 +179,26 @@ cdef class Reducer:
179179 return result
180180
181181
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):
183202 """
184203 Performs grouping operation according to bin edges, rather than labels
185204 """
@@ -216,21 +235,6 @@ cdef class SeriesBinGrouper:
216235 else :
217236 self .ngroups = len (bins) + 1
218237
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-
234238 def get_result (self ):
235239 cdef:
236240 ndarray arr, result
@@ -304,7 +308,7 @@ cdef class SeriesBinGrouper:
304308 return result, counts
305309
306310
307- cdef class SeriesGrouper:
311+ cdef class SeriesGrouper(_BaseGrouper) :
308312 """
309313 Performs generic grouping operation while avoiding ndarray construction
310314 overhead
@@ -340,23 +344,6 @@ cdef class SeriesGrouper:
340344 self .dummy_arr, self .dummy_index = self ._check_dummy(dummy)
341345 self .ngroups = ngroups
342346
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-
360347 def get_result (self ):
361348 cdef:
362349 # Define result to avoid UnboundLocalError
0 commit comments