@@ -189,6 +189,27 @@ cdef class _BaseGrouper:
189
189
190
190
return cached_typ, cached_ityp
191
191
192
+ cdef inline object _apply_to_group(self ,
193
+ object cached_typ, object cached_ityp,
194
+ Slider islider, Slider vslider,
195
+ Py_ssize_t group_size, bint initialized):
196
+ """
197
+ Call self.f on our new group, then update to the next group.
198
+ """
199
+ cached_ityp._engine.clear_mapping()
200
+ res = self .f(cached_typ)
201
+ res = _extract_result(res)
202
+ if not initialized:
203
+ # On the first pass, we check the output shape to see
204
+ # if this looks like a reduction.
205
+ initialized = 1
206
+ _check_result_array(res, len (self .dummy_arr))
207
+
208
+ islider.advance(group_size)
209
+ vslider.advance(group_size)
210
+
211
+ return res, initialized
212
+
192
213
193
214
cdef class SeriesBinGrouper(_BaseGrouper):
194
215
"""
@@ -217,7 +238,7 @@ cdef class SeriesBinGrouper(_BaseGrouper):
217
238
self .typ = series._constructor
218
239
self .ityp = series.index._constructor
219
240
self .index = series.index.values
220
- self .name = getattr ( series, ' name' , None )
241
+ self .name = series. name
221
242
222
243
self .dummy_arr, self .dummy_index = self ._check_dummy(dummy)
223
244
@@ -265,20 +286,12 @@ cdef class SeriesBinGrouper(_BaseGrouper):
265
286
cached_typ, cached_ityp = self ._update_cached_objs(
266
287
cached_typ, cached_ityp, islider, vslider)
267
288
268
- cached_ityp._engine.clear_mapping()
269
- res = self .f(cached_typ)
270
- res = _extract_result(res)
271
- if not initialized:
272
- # On the first pass, we check the output shape to see
273
- # if this looks like a reduction.
274
- initialized = 1
275
- _check_result_array(res, len (self .dummy_arr))
289
+ res, initialized = self ._apply_to_group(cached_typ, cached_ityp,
290
+ islider, vslider,
291
+ group_size, initialized)
276
292
277
293
result[i] = res
278
294
279
- islider.advance(group_size)
280
- vslider.advance(group_size)
281
-
282
295
finally :
283
296
# so we don't free the wrong memory
284
297
islider.reset()
@@ -322,7 +335,7 @@ cdef class SeriesGrouper(_BaseGrouper):
322
335
self .typ = series._constructor
323
336
self .ityp = series.index._constructor
324
337
self .index = series.index.values
325
- self .name = getattr ( series, ' name' , None )
338
+ self .name = series. name
326
339
327
340
self .dummy_arr, self .dummy_index = self ._check_dummy(dummy)
328
341
self .ngroups = ngroups
@@ -367,20 +380,12 @@ cdef class SeriesGrouper(_BaseGrouper):
367
380
cached_typ, cached_ityp = self ._update_cached_objs(
368
381
cached_typ, cached_ityp, islider, vslider)
369
382
370
- cached_ityp._engine.clear_mapping()
371
- res = self .f(cached_typ)
372
- res = _extract_result(res)
373
- if not initialized:
374
- # On the first pass, we check the output shape to see
375
- # if this looks like a reduction.
376
- initialized = 1
377
- _check_result_array(res, len (self .dummy_arr))
383
+ res, initialized = self ._apply_to_group(cached_typ, cached_ityp,
384
+ islider, vslider,
385
+ group_size, initialized)
378
386
379
387
result[lab] = res
380
388
counts[lab] = group_size
381
- islider.advance(group_size)
382
- vslider.advance(group_size)
383
-
384
389
group_size = 0
385
390
386
391
finally :
0 commit comments