@@ -968,28 +968,28 @@ def _cython_operation(
968
968
)
969
969
970
970
@final
971
- def agg_series (self , obj : Series , func : F ) -> tuple [ ArrayLike , np . ndarray ] :
971
+ def agg_series (self , obj : Series , func : F ) -> ArrayLike :
972
972
# Caller is responsible for checking ngroups != 0
973
973
assert self .ngroups != 0
974
974
975
975
cast_back = True
976
976
if len (obj ) == 0 :
977
977
# SeriesGrouper would raise if we were to call _aggregate_series_fast
978
- result , counts = self ._aggregate_series_pure_python (obj , func )
978
+ result = self ._aggregate_series_pure_python (obj , func )
979
979
980
980
elif not isinstance (obj ._values , np .ndarray ):
981
981
# _aggregate_series_fast would raise TypeError when
982
982
# calling libreduction.Slider
983
983
# In the datetime64tz case it would incorrectly cast to tz-naive
984
984
# TODO: can we get a performant workaround for EAs backed by ndarray?
985
- result , counts = self ._aggregate_series_pure_python (obj , func )
985
+ result = self ._aggregate_series_pure_python (obj , func )
986
986
987
987
elif obj .index ._has_complex_internals :
988
988
# Preempt TypeError in _aggregate_series_fast
989
- result , counts = self ._aggregate_series_pure_python (obj , func )
989
+ result = self ._aggregate_series_pure_python (obj , func )
990
990
991
991
else :
992
- result , counts = self ._aggregate_series_fast (obj , func )
992
+ result = self ._aggregate_series_fast (obj , func )
993
993
cast_back = False
994
994
995
995
npvalues = lib .maybe_convert_objects (result , try_float = False )
@@ -998,11 +998,11 @@ def agg_series(self, obj: Series, func: F) -> tuple[ArrayLike, np.ndarray]:
998
998
out = maybe_cast_pointwise_result (npvalues , obj .dtype , numeric_only = True )
999
999
else :
1000
1000
out = npvalues
1001
- return out , counts
1001
+ return out
1002
+
1003
+ def _aggregate_series_fast (self , obj : Series , func : F ) -> np .ndarray :
1004
+ # -> np.ndarray[object]
1002
1005
1003
- def _aggregate_series_fast (
1004
- self , obj : Series , func : F
1005
- ) -> tuple [ArrayLike , np .ndarray ]:
1006
1006
# At this point we have already checked that
1007
1007
# - obj.index is not a MultiIndex
1008
1008
# - obj is backed by an ndarray, not ExtensionArray
@@ -1017,11 +1017,12 @@ def _aggregate_series_fast(
1017
1017
obj = obj .take (indexer )
1018
1018
ids = ids .take (indexer )
1019
1019
sgrouper = libreduction .SeriesGrouper (obj , func , ids , ngroups )
1020
- result , counts = sgrouper .get_result ()
1021
- return result , counts
1020
+ result , _ = sgrouper .get_result ()
1021
+ return result
1022
1022
1023
1023
@final
1024
- def _aggregate_series_pure_python (self , obj : Series , func : F ):
1024
+ def _aggregate_series_pure_python (self , obj : Series , func : F ) -> np .ndarray :
1025
+ # -> np.ndarray[object]
1025
1026
ids , _ , ngroups = self .group_info
1026
1027
1027
1028
counts = np .zeros (ngroups , dtype = int )
@@ -1046,7 +1047,7 @@ def _aggregate_series_pure_python(self, obj: Series, func: F):
1046
1047
counts [i ] = group .shape [0 ]
1047
1048
result [i ] = res
1048
1049
1049
- return result , counts
1050
+ return result
1050
1051
1051
1052
1052
1053
class BinGrouper (BaseGrouper ):
@@ -1204,16 +1205,17 @@ def groupings(self) -> list[grouper.Grouping]:
1204
1205
ping = grouper .Grouping (lev , lev , in_axis = False , level = None , name = lev .name )
1205
1206
return [ping ]
1206
1207
1207
- def _aggregate_series_fast (
1208
- self , obj : Series , func : F
1209
- ) -> tuple [ ArrayLike , np . ndarray ]:
1208
+ def _aggregate_series_fast (self , obj : Series , func : F ) -> np . ndarray :
1209
+ # -> np.ndarray[object]
1210
+
1210
1211
# At this point we have already checked that
1211
1212
# - obj.index is not a MultiIndex
1212
1213
# - obj is backed by an ndarray, not ExtensionArray
1213
1214
# - ngroups != 0
1214
1215
# - len(self.bins) > 0
1215
1216
sbg = libreduction .SeriesBinGrouper (obj , func , self .bins )
1216
- return sbg .get_result ()
1217
+ result , _ = sbg .get_result ()
1218
+ return result
1217
1219
1218
1220
1219
1221
def _is_indexed_like (obj , axes , axis : int ) -> bool :
0 commit comments