16
16
Callable ,
17
17
FrozenSet ,
18
18
Iterable ,
19
+ List ,
19
20
Mapping ,
20
21
Sequence ,
22
+ Tuple ,
21
23
Type ,
22
24
Union ,
23
25
cast ,
@@ -993,25 +995,25 @@ def _iterate_slices(self) -> Iterable[Series]:
993
995
def _cython_agg_general (
994
996
self , how : str , alt = None , numeric_only : bool = True , min_count : int = - 1
995
997
) -> DataFrame :
996
- agg_items , agg_blocks = self ._cython_agg_blocks (
998
+ agg_blocks , agg_items = self ._cython_agg_blocks (
997
999
how , alt = alt , numeric_only = numeric_only , min_count = min_count
998
1000
)
999
1001
return self ._wrap_agged_blocks (agg_blocks , items = agg_items )
1000
1002
1001
1003
def _cython_agg_blocks (
1002
1004
self , how : str , alt = None , numeric_only : bool = True , min_count : int = - 1
1003
- ):
1005
+ ) -> "Tuple[List[Block], Index]" :
1004
1006
# TODO: the actual managing of mgr_locs is a PITA
1005
1007
# here, it should happen via BlockManager.combine
1006
1008
1007
- data = self ._get_data_to_aggregate ()
1009
+ data : BlockManager = self ._get_data_to_aggregate ()
1008
1010
1009
1011
if numeric_only :
1010
1012
data = data .get_numeric_data (copy = False )
1011
1013
1012
- new_blocks = []
1013
- new_items = []
1014
- deleted_items = []
1014
+ agg_blocks : List [ Block ] = []
1015
+ new_items : List [ np . ndarray ] = []
1016
+ deleted_items : List [ np . ndarray ] = []
1015
1017
no_result = object ()
1016
1018
for block in data .blocks :
1017
1019
# Avoid inheriting result from earlier in the loop
@@ -1077,20 +1079,20 @@ def _cython_agg_blocks(
1077
1079
# reshape to be valid for non-Extension Block
1078
1080
result = result .reshape (1 , - 1 )
1079
1081
1080
- newb = block .make_block (result )
1082
+ agg_block : Block = block .make_block (result )
1081
1083
1082
1084
new_items .append (locs )
1083
- new_blocks .append (newb )
1085
+ agg_blocks .append (agg_block )
1084
1086
1085
- if len ( new_blocks ) == 0 :
1087
+ if not agg_blocks :
1086
1088
raise DataError ("No numeric types to aggregate" )
1087
1089
1088
1090
# reset the locs in the blocks to correspond to our
1089
1091
# current ordering
1090
1092
indexer = np .concatenate (new_items )
1091
- new_items = data .items .take (np .sort (indexer ))
1093
+ agg_items = data .items .take (np .sort (indexer ))
1092
1094
1093
- if len ( deleted_items ) :
1095
+ if deleted_items :
1094
1096
1095
1097
# we need to adjust the indexer to account for the
1096
1098
# items we have removed
@@ -1103,12 +1105,12 @@ def _cython_agg_blocks(
1103
1105
indexer = (ai - mask .cumsum ())[indexer ]
1104
1106
1105
1107
offset = 0
1106
- for b in new_blocks :
1107
- loc = len (b .mgr_locs )
1108
- b .mgr_locs = indexer [offset : (offset + loc )]
1108
+ for blk in agg_blocks :
1109
+ loc = len (blk .mgr_locs )
1110
+ blk .mgr_locs = indexer [offset : (offset + loc )]
1109
1111
offset += loc
1110
1112
1111
- return new_items , new_blocks
1113
+ return agg_blocks , agg_items
1112
1114
1113
1115
def _aggregate_frame (self , func , * args , ** kwargs ) -> DataFrame :
1114
1116
if self .grouper .nkeys != 1 :
@@ -1615,7 +1617,7 @@ def _wrap_frame_output(self, result, obj) -> DataFrame:
1615
1617
else :
1616
1618
return DataFrame (result , index = obj .index , columns = result_index )
1617
1619
1618
- def _get_data_to_aggregate (self ):
1620
+ def _get_data_to_aggregate (self ) -> BlockManager :
1619
1621
obj = self ._obj_with_exclusions
1620
1622
if self .axis == 1 :
1621
1623
return obj .T ._data
0 commit comments