@@ -393,6 +393,40 @@ def get_func(fname):
393
393
394
394
return func
395
395
396
+ def _get_cython_func_and_vals (
397
+ self , kind : str , how : str , values : np .ndarray , is_numeric : bool
398
+ ):
399
+ """
400
+ Find the appropriate cython function, casting if necessary.
401
+
402
+ Parameters
403
+ ----------
404
+ kind : sttr
405
+ how : srt
406
+ values : np.ndarray
407
+ is_numeric : bool
408
+
409
+ Returns
410
+ -------
411
+ func : callable
412
+ values : np.ndarray
413
+ """
414
+ try :
415
+ func = self ._get_cython_function (kind , how , values , is_numeric )
416
+ except NotImplementedError :
417
+ if is_numeric :
418
+ try :
419
+ values = ensure_float64 (values )
420
+ except TypeError :
421
+ if lib .infer_dtype (values , skipna = False ) == "complex" :
422
+ values = values .astype (complex )
423
+ else :
424
+ raise
425
+ func = self ._get_cython_function (kind , how , values , is_numeric )
426
+ else :
427
+ raise
428
+ return func , values
429
+
396
430
def _cython_operation (
397
431
self , kind : str , values , how : str , axis : int , min_count : int = - 1 , ** kwargs
398
432
):
@@ -466,20 +500,7 @@ def _cython_operation(
466
500
)
467
501
out_shape = (self .ngroups ,) + values .shape [1 :]
468
502
469
- try :
470
- func = self ._get_cython_function (kind , how , values , is_numeric )
471
- except NotImplementedError :
472
- if is_numeric :
473
- try :
474
- values = ensure_float64 (values )
475
- except TypeError :
476
- if lib .infer_dtype (values , skipna = False ) == "complex" :
477
- values = values .astype (complex )
478
- else :
479
- raise
480
- func = self ._get_cython_function (kind , how , values , is_numeric )
481
- else :
482
- raise
503
+ func , values = self ._get_cython_func_and_vals (kind , how , values , is_numeric )
483
504
484
505
if how == "rank" :
485
506
out_dtype = "float"
0 commit comments