diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index dc109f6b30d5c..28e104ec1bc0e 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -677,11 +677,6 @@ class BaseGrouper: for example for grouper list to groupby, need to pass the list sort : bool, default True whether this grouper will give sorted result or not - group_keys : bool, default True - indexer : np.ndarray[np.intp], optional - the indexer created by Grouper - some groupers (TimeGrouper) will sort its axis and its - group_info is also sorted, so need the indexer to reorder """ @@ -692,8 +687,6 @@ def __init__( axis: Index, groupings: Sequence[grouper.Grouping], sort: bool = True, - group_keys: bool = True, - indexer: npt.NDArray[np.intp] | None = None, dropna: bool = True, ) -> None: assert isinstance(axis, Index), axis @@ -701,8 +694,6 @@ def __init__( self.axis = axis self._groupings: list[grouper.Grouping] = list(groupings) self._sort = sort - self.group_keys = group_keys - self.indexer = indexer self.dropna = dropna @property @@ -886,14 +877,10 @@ def group_info(self) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp], int]: return comp_ids, obs_group_ids, ngroups - @final @cache_readonly def codes_info(self) -> npt.NDArray[np.intp]: # return the codes of items in original grouped axis ids, _, _ = self.group_info - if self.indexer is not None: - sorter = np.lexsort((ids, self.indexer)) - ids = ids[sorter] return ids @final @@ -1047,7 +1034,10 @@ class BinGrouper(BaseGrouper): ---------- bins : the split index of binlabels to group the item of axis binlabels : the label list - indexer : np.ndarray[np.intp] + indexer : np.ndarray[np.intp], optional + the indexer created by Grouper + some groupers (TimeGrouper) will sort its axis and its + group_info is also sorted, so need the indexer to reorder Examples -------- @@ -1101,6 +1091,15 @@ def nkeys(self) -> int: # still matches len(self.groupings), but we can hard-code return 1 + @cache_readonly + def codes_info(self) -> npt.NDArray[np.intp]: + # return the codes of items in original grouped axis + ids, _, _ = self.group_info + if self.indexer is not None: + sorter = np.lexsort((ids, self.indexer)) + ids = ids[sorter] + return ids + def get_iterator(self, data: NDFrame, axis: AxisInt = 0): """ Groupby iterator