Skip to content

API: Rename BaseGrouper.recons_codes to BaseGrouper.reconstructed_codes #29471

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 2 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ def value_counts(
rep = partial(np.repeat, repeats=np.add.reduceat(inc, idx))

# multi-index components
codes = self.grouper.recons_codes
codes = self.grouper.reconstructed_codes
codes = [rep(level_codes) for level_codes in codes] + [llab(lab, inc)]
levels = [ping.group_index for ping in self.grouper.groupings] + [lev]
names = self.grouper.names + [self._selection_name]
Expand Down
22 changes: 11 additions & 11 deletions pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

import collections
from typing import List, Optional, Sequence, Type
from typing import List, Optional, Sequence, Tuple, Type

import numpy as np

Expand Down Expand Up @@ -216,11 +216,11 @@ def indices(self):
return get_indexer_dict(codes_list, keys)

@property
def codes(self):
def codes(self) -> List[np.ndarray]:
return [ping.codes for ping in self.groupings]

@property
def levels(self):
def levels(self) -> List[Index]:
return [ping.group_index for ping in self.groupings]

@property
Expand Down Expand Up @@ -264,16 +264,16 @@ def group_info(self):
return comp_ids, obs_group_ids, ngroups

@cache_readonly
def codes_info(self):
def codes_info(self) -> np.ndarray:
# return the codes of items in original grouped axis
codes, _, _ = self.group_info
if self.indexer is not None:
sorter = np.lexsort((codes, self.indexer))
codes = codes[sorter]
return codes

def _get_compressed_codes(self):
all_codes = [ping.codes for ping in self.groupings]
def _get_compressed_codes(self) -> Tuple[np.ndarray, np.ndarray]:
all_codes = self.codes
if len(all_codes) > 1:
group_index = get_group_index(all_codes, self.shape, sort=True, xnull=True)
return compress_group_index(group_index, sort=self.sort)
Expand All @@ -286,17 +286,17 @@ def ngroups(self) -> int:
return len(self.result_index)

@property
def recons_codes(self):
def reconstructed_codes(self) -> List[np.ndarray]:
codes = self.codes
comp_ids, obs_ids, _ = self.group_info
codes = (ping.codes for ping in self.groupings)
return decons_obs_group_ids(comp_ids, obs_ids, self.shape, codes, xnull=True)

@cache_readonly
def result_index(self):
if not self.compressed and len(self.groupings) == 1:
return self.groupings[0].result_index.rename(self.names[0])

codes = self.recons_codes
codes = self.reconstructed_codes
levels = [ping.result_index for ping in self.groupings]
result = MultiIndex(
levels=levels, codes=codes, verify_integrity=False, names=self.names
Expand All @@ -308,7 +308,7 @@ def get_group_levels(self):
return [self.groupings[0].result_index]

name_list = []
for ping, codes in zip(self.groupings, self.recons_codes):
for ping, codes in zip(self.groupings, self.reconstructed_codes):
codes = ensure_platform_int(codes)
levels = ping.result_index.take(codes)

Expand Down Expand Up @@ -768,7 +768,7 @@ def group_info(self):
)

@cache_readonly
def recons_codes(self):
def reconstructed_codes(self) -> List[np.ndarray]:
# get unique result indices, and prepend 0 as groupby starts from the first
return [np.r_[0, np.flatnonzero(self.bins[1:] != self.bins[:-1]) + 1]]

Expand Down