Skip to content

REF: unused group_keys, indexer from BaseGrouper #51214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""

Expand All @@ -692,17 +687,13 @@ 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

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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
--------
Expand Down Expand Up @@ -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
Expand Down