@@ -2400,7 +2400,7 @@ def _get_cythonized_result(
2400
2400
signature
2401
2401
needs_2d : bool, default False
2402
2402
Whether the values and result of the Cython call signature
2403
- are at least 2-dimensional.
2403
+ are 2-dimensional.
2404
2404
min_count : int, default None
2405
2405
When not None, min_count for the Cython call
2406
2406
needs_mask : bool, default False
@@ -2416,7 +2416,9 @@ def _get_cythonized_result(
2416
2416
Function should return a tuple where the first element is the
2417
2417
values to be passed to Cython and the second element is an optional
2418
2418
type which the values should be converted to after being returned
2419
- by the Cython operation. Raises if `needs_values` is False.
2419
+ by the Cython operation. This function is also responsible for
2420
+ raising a TypeError if the values have an invalid type. Raises
2421
+ if `needs_values` is False.
2420
2422
post_processing : function, default None
2421
2423
Function to be applied to result of Cython function. Should accept
2422
2424
an array of values as the first argument and type inferences as its
@@ -2448,6 +2450,7 @@ def _get_cythonized_result(
2448
2450
output : Dict [base .OutputKey , np .ndarray ] = {}
2449
2451
base_func = getattr (libgroupby , how )
2450
2452
2453
+ error_msg = ""
2451
2454
for idx , obj in enumerate (self ._iterate_slices ()):
2452
2455
name = obj .name
2453
2456
values = obj ._values
@@ -2474,7 +2477,11 @@ def _get_cythonized_result(
2474
2477
if needs_values :
2475
2478
vals = values
2476
2479
if pre_processing :
2477
- vals , inferences = pre_processing (vals )
2480
+ try :
2481
+ vals , inferences = pre_processing (vals )
2482
+ except TypeError as e :
2483
+ error_msg = str (e )
2484
+ continue
2478
2485
if needs_2d :
2479
2486
vals = vals .reshape ((- 1 , 1 ))
2480
2487
vals = vals .astype (cython_dtype , copy = False )
@@ -2506,6 +2513,10 @@ def _get_cythonized_result(
2506
2513
key = base .OutputKey (label = name , position = idx )
2507
2514
output [key ] = result
2508
2515
2516
+ # error_msg is "" on an frame/series with no rows or columns
2517
+ if len (output ) == 0 and error_msg != "" :
2518
+ raise TypeError (error_msg )
2519
+
2509
2520
if aggregate :
2510
2521
return self ._wrap_aggregated_output (output )
2511
2522
else :
0 commit comments