diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 9c695148a75c0..c162b929f7cd2 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -2896,7 +2896,7 @@ def _get_cythonized_result( grouper = self.grouper ids, _, ngroups = grouper.group_info - output: dict[base.OutputKey, np.ndarray] = {} + output: dict[base.OutputKey, ArrayLike] = {} base_func = getattr(libgroupby, how) base_func = partial(base_func, labels=ids) @@ -2946,16 +2946,20 @@ def blk_func(values: ArrayLike) -> ArrayLike: result = result.reshape(-1) if result_is_index: - result = algorithms.take_nd(values, result) + # Incompatible types in assignment (expression has type + # "Union[ExtensionArray, ndarray[Any, Any]]", variable has + # type "ndarray[Any, Any]") + result = algorithms.take_nd(values, result) # type: ignore[assignment] + out = result if post_processing: pp_kwargs = {} if needs_nullable: pp_kwargs["nullable"] = isinstance(values, BaseMaskedArray) - result = post_processing(result, inferences, **pp_kwargs) + out = post_processing(out, inferences, **pp_kwargs) - return result + return out error_msg = "" for idx, obj in enumerate(self._iterate_slices()):