Skip to content

BUG: value_counts can handle the case even with empty groups (#28479) #28634

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 31 commits into from
Nov 7, 2019
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b28456a
BUG: value_counts can handle the case even with empty groups (#28479)
dongho-jung Sep 25, 2019
3ef5e8a
.
dongho-jung Sep 26, 2019
40475e8
removing consecutive duplicates was the same as just unique
dongho-jung Sep 27, 2019
f1f104a
get the performance while handling the exception explicitly
dongho-jung Sep 28, 2019
6fbaaa6
get rid of try-except
dongho-jung Oct 3, 2019
be018a0
Merge branch 'master' of https://github.com/pandas-dev/pandas into fi…
dongho-jung Oct 3, 2019
3a7f71e
make test more idiomatic
dongho-jung Oct 3, 2019
e045290
Merge remote-tracking branch 'upstream/master' into fix-GH28479-1
dongho-jung Oct 14, 2019
d101a73
Merge origin/master into fix-GH28479-1
dongho-jung Oct 14, 2019
31461d2
solve merge confilcts
dongho-jung Oct 14, 2019
11df012
Merge remote-tracking branch 'upstream/master' into fix-GH28479-1
andrew-buzzni Oct 18, 2019
8005603
move the logic into the BinGrouper.recons_labels
dongho-jung Oct 19, 2019
b507259
Merge remote-tracking branch 'upstream/master' into fix-GH28479-1
dongho-jung Oct 19, 2019
67847ff
checkout unrelated files to master
dongho-jung Oct 19, 2019
66a96e3
checkout sorting.py to upstream/master not origin/master
dongho-jung Oct 19, 2019
9390d21
accept TomAugspurger requests
dongho-jung Oct 24, 2019
a75843f
Merge remote-tracking branch 'upstream/master' into fix-GH28479-1
dongho-jung Oct 24, 2019
d8da75a
use deterministic values instead of random values
dongho-jung Oct 24, 2019
6f6371c
undo adding recons_labels method
dongho-jung Oct 25, 2019
82e5153
move a change returning unique comp ids
dongho-jung Oct 25, 2019
3cf850e
Merge branch 'master' into fix-GH28479-1
dongho-jung Nov 1, 2019
97adfa6
Merge remote-tracking branch 'origin/fix-GH28479-1' into fix-GH28479-1
andrew-buzzni Nov 4, 2019
49514aa
Merge remote-tracking branch 'upstream/master' into fix-GH28479-1
andrew-buzzni Nov 4, 2019
df6454b
add recons_labels under the BinGrouper
andrew-buzzni Nov 4, 2019
28ee287
fix indexing in recons_labels
andrew-buzzni Nov 4, 2019
a1049fd
add an exact reproduction of the original issue
andrew-buzzni Nov 4, 2019
3436dda
Merge remote-tracking branch 'upstream/master' into fix-GH28479-1
dongho-jung Nov 5, 2019
961a72c
add a comment under recons_labels
andrew-buzzni Nov 6, 2019
b45527c
Merge remote-tracking branch 'upstream/master' into fix-GH28479-1
dongho-jung Nov 7, 2019
a364ac6
Merge branch 'fix-GH28479-1' of https://github.com/0xF4D3C0D3/pandas …
dongho-jung Nov 7, 2019
368311c
rename from recons_labels to recons_codes
dongho-jung Nov 7, 2019
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
Prev Previous commit
Next Next commit
get rid of try-except
  • Loading branch information
dongho-jung committed Oct 3, 2019
commit 6fbaaa6b13f257d26f6522ddbc4b2af7f4c7af9b
12 changes: 5 additions & 7 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,14 +1260,12 @@ def value_counts(
rep = partial(np.repeat, repeats=np.add.reduceat(inc, idx))

# multi-index components
try:
if isinstance(self.grouper, BinGrouper) and (
len(self.grouper.binlabels) != len(self.grouper.indices)
):
labels = list(map(rep, [np.unique(ids)])) + [llab(lab, inc)]
else:
labels = list(map(rep, self.grouper.recons_labels)) + [llab(lab, inc)]
except ValueError:
# If applying rep to recons_labels go fail and that's because empty periods,
is_len_different = len(self.grouper.binlabels) != len(self.grouper.indices)
if isinstance(self.grouper, BinGrouper) and is_len_different:
# then use unidue ids instead of self.grouper.recons_labels
labels = list(map(rep, [np.unique(ids)])) + [llab(lab, inc)]
levels = [ping.group_index for ping in self.grouper.groupings] + [lev]
names = self.grouper.names + [self._selection_name]

Expand Down