From 8ce08d15503c0e5189422b75ee07c4d6201acfbb Mon Sep 17 00:00:00 2001 From: richard Date: Tue, 31 Oct 2023 22:00:37 -0400 Subject: [PATCH] Refinements --- pandas/core/groupby/groupby.py | 6 +++--- pandas/core/groupby/grouper.py | 8 +------- pandas/core/groupby/ops.py | 4 ---- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index e7e077e611359..bcdc67f612873 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -4439,13 +4439,13 @@ def post_processor( pass_qs = None ids, ngroups = self.grouper.group_info - # TODO: Is this hit? - ids = ids[ids >= 0] + if self.dropna: + ids = ids[ids >= 0] nqs = len(qs) func = partial( libgroupby.group_quantile, - labels=ids[ids >= 0], + labels=ids, qs=qs, interpolation=interpolation, starts=starts, diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index ff249e24d0c49..a9abcc787e774 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -735,10 +735,6 @@ def _codes_and_uniques(self) -> tuple[npt.NDArray[np.signedinteger], ArrayLike]: codes = np.where(codes >= na_code, codes + 1, codes) codes = np.where(na_mask, na_code, codes) - # TODO: Can this be removed? - if not self._observed: - uniques = uniques.reorder_categories(self._orig_cats) - return codes, uniques elif isinstance(self.grouping_vector, ops.BaseGrouper): @@ -998,9 +994,7 @@ def is_in_obj(gpr) -> bool: groupings.append(Grouping(Index([], dtype="int"), np.array([], dtype=np.intp))) # create the internals grouper - grouper = ops.BaseGrouper( - group_axis, groupings, sort=sort, dropna=dropna, observed=observed - ) + grouper = ops.BaseGrouper(group_axis, groupings, sort=sort, dropna=dropna) return grouper, frozenset(exclusions), obj diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index 3d1ca78f70a8c..e2e9be685bcc9 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -579,8 +579,6 @@ def __init__( groupings: Sequence[grouper.Grouping], sort: bool = True, dropna: bool = True, - # TODO: Is this still needed? - observed: bool = True, ) -> None: assert isinstance(axis, Index), axis @@ -588,7 +586,6 @@ def __init__( self._groupings: list[grouper.Grouping] = list(groupings) self._sort = sort self.dropna = dropna - self.observed = observed @property def groupings(self) -> list[grouper.Grouping]: @@ -859,7 +856,6 @@ def result_index_and_ids(self) -> tuple[Index, np.ndarray]: return result_index, ids - # TODO: How is this different from .levels? @final def get_group_levels(self) -> list[Index]: # Note: only called from _insert_inaxis_grouper, which