@@ -2411,7 +2411,9 @@ def _get_cythonized_result(
2411
2411
Function should return a tuple where the first element is the
2412
2412
values to be passed to Cython and the second element is an optional
2413
2413
type which the values should be converted to after being returned
2414
- by the Cython operation. Raises if `needs_values` is False.
2414
+ by the Cython operation. This function is also responsible for
2415
+ raising a TypeError if the values have an invalid type. Raises
2416
+ if `needs_values` is False.
2415
2417
post_processing : function, default None
2416
2418
Function to be applied to result of Cython function. Should accept
2417
2419
an array of values as the first argument and type inferences as its
@@ -2443,6 +2445,7 @@ def _get_cythonized_result(
2443
2445
output : Dict [base .OutputKey , np .ndarray ] = {}
2444
2446
base_func = getattr (libgroupby , how )
2445
2447
2448
+ error_msg = ""
2446
2449
for idx , obj in enumerate (self ._iterate_slices ()):
2447
2450
name = obj .name
2448
2451
values = obj ._values
@@ -2470,7 +2473,11 @@ def _get_cythonized_result(
2470
2473
if needs_values :
2471
2474
vals = values
2472
2475
if pre_processing :
2473
- vals , inferences = pre_processing (vals )
2476
+ try :
2477
+ vals , inferences = pre_processing (vals )
2478
+ except TypeError as e :
2479
+ error_msg = str (e )
2480
+ continue
2474
2481
if needs_2d :
2475
2482
vals = vals .reshape ((- 1 , 1 ))
2476
2483
vals = vals .astype (cython_dtype , copy = False )
@@ -2502,6 +2509,10 @@ def _get_cythonized_result(
2502
2509
key = base .OutputKey (label = name , position = idx )
2503
2510
output [key ] = result
2504
2511
2512
+ # Note: we don't raise on an frame/series with no rows
2513
+ if len (output ) == 0 and error_msg != "" :
2514
+ raise TypeError (error_msg )
2515
+
2505
2516
if aggregate :
2506
2517
return self ._wrap_aggregated_output (output )
2507
2518
else :
0 commit comments