56
56
needs_i8_conversion ,
57
57
)
58
58
from pandas .core .dtypes .dtypes import ExtensionDtype
59
- from pandas .core .dtypes .generic import ABCCategoricalIndex
60
59
from pandas .core .dtypes .missing import (
61
60
isna ,
62
61
maybe_fill ,
89
88
grouper ,
90
89
)
91
90
from pandas .core .indexes .api import (
91
+ CategoricalIndex ,
92
92
Index ,
93
93
MultiIndex ,
94
94
ensure_index ,
@@ -676,7 +676,6 @@ def __init__(
676
676
):
677
677
assert isinstance (axis , Index ), axis
678
678
679
- self ._filter_empty_groups = self .compressed = len (groupings ) != 1
680
679
self .axis = axis
681
680
self ._groupings : list [grouper .Grouping ] = list (groupings )
682
681
self .sort = sort
@@ -822,9 +821,7 @@ def apply(self, f: F, data: FrameOrSeries, axis: int = 0):
822
821
@cache_readonly
823
822
def indices (self ):
824
823
""" dict {group name -> group indices} """
825
- if len (self .groupings ) == 1 and isinstance (
826
- self .result_index , ABCCategoricalIndex
827
- ):
824
+ if len (self .groupings ) == 1 and isinstance (self .result_index , CategoricalIndex ):
828
825
# This shows unused categories in indices GH#38642
829
826
return self .groupings [0 ].indices
830
827
codes_list = [ping .codes for ping in self .groupings ]
@@ -913,7 +910,7 @@ def reconstructed_codes(self) -> list[np.ndarray]:
913
910
914
911
@cache_readonly
915
912
def result_index (self ) -> Index :
916
- if not self . compressed and len (self .groupings ) == 1 :
913
+ if len (self .groupings ) == 1 :
917
914
return self .groupings [0 ].result_index .rename (self .names [0 ])
918
915
919
916
codes = self .reconstructed_codes
@@ -924,7 +921,9 @@ def result_index(self) -> Index:
924
921
925
922
@final
926
923
def get_group_levels (self ) -> list [Index ]:
927
- if not self .compressed and len (self .groupings ) == 1 :
924
+ # Note: only called from _insert_inaxis_grouper_inplace, which
925
+ # is only called for BaseGrouper, never for BinGrouper
926
+ if len (self .groupings ) == 1 :
928
927
return [self .groupings [0 ].result_index ]
929
928
930
929
name_list = []
@@ -1091,7 +1090,6 @@ def __init__(
1091
1090
):
1092
1091
self .bins = ensure_int64 (bins )
1093
1092
self .binlabels = ensure_index (binlabels )
1094
- self ._filter_empty_groups = False
1095
1093
self .mutated = mutated
1096
1094
self .indexer = indexer
1097
1095
@@ -1201,10 +1199,9 @@ def names(self) -> list[Hashable]:
1201
1199
1202
1200
@property
1203
1201
def groupings (self ) -> list [grouper .Grouping ]:
1204
- return [
1205
- grouper .Grouping (lvl , lvl , in_axis = False , level = None , name = name )
1206
- for lvl , name in zip (self .levels , self .names )
1207
- ]
1202
+ lev = self .binlabels
1203
+ ping = grouper .Grouping (lev , lev , in_axis = False , level = None , name = lev .name )
1204
+ return [ping ]
1208
1205
1209
1206
def _aggregate_series_fast (
1210
1207
self , obj : Series , func : F
0 commit comments