@@ -2411,7 +2411,9 @@ def _get_cythonized_result(
24112411 Function should return a tuple where the first element is the
24122412 values to be passed to Cython and the second element is an optional
24132413 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.
24152417 post_processing : function, default None
24162418 Function to be applied to result of Cython function. Should accept
24172419 an array of values as the first argument and type inferences as its
@@ -2443,6 +2445,7 @@ def _get_cythonized_result(
24432445 output : Dict [base .OutputKey , np .ndarray ] = {}
24442446 base_func = getattr (libgroupby , how )
24452447
2448+ error_msg = ""
24462449 for idx , obj in enumerate (self ._iterate_slices ()):
24472450 name = obj .name
24482451 values = obj ._values
@@ -2470,7 +2473,11 @@ def _get_cythonized_result(
24702473 if needs_values :
24712474 vals = values
24722475 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
24742481 if needs_2d :
24752482 vals = vals .reshape ((- 1 , 1 ))
24762483 vals = vals .astype (cython_dtype , copy = False )
@@ -2502,6 +2509,10 @@ def _get_cythonized_result(
25022509 key = base .OutputKey (label = name , position = idx )
25032510 output [key ] = result
25042511
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+
25052516 if aggregate :
25062517 return self ._wrap_aggregated_output (output )
25072518 else :
0 commit comments