-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
PERF: improves performance in SeriesGroupBy.count #10946
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
Conversation
65e2142
to
5f96530
Compare
index=level_index).__finalize__(self) | ||
mask = lab == -1 | ||
if mask.any(): | ||
lab[mask] = cnt = len(lev) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than adding this almost identical code, doesnt it make sense to:
return self.groupby(level=level).count().__finalize__(self)
?
for the level not None
case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just removing the bug from current implementation. i don't think having an optional level
argument would be useful here as it is basically equivalent to groupby
on level. that said, groupby
removes nulls from keys:
In [5]: ts
Out[5]:
a 1 0
2 1
b 2 2
NaN 3
c 1 4
2 5
dtype: int64
In [6]: ts.groupby(level=1).count()
Out[6]:
1 2
2 3
dtype: int64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure I understand. the expression I gave above is equivalent to what you wrote, yes? its is just dispatching to the groupby impl. (which is how all of the other stat functions which accept level
work).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the expression I gave above is equivalent to what you wrote, yes?
yes, if index does not include nan.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my point is why we having a special case implementation, when simply using s.groupby(level=level).count()
is acceptable?
and this is what all of the other make_stat_*
functions do.
Since this was a bug nothing is even being eliminated.
5f96530
to
a6bc569
Compare
@behzadnouri pls rebase and make the changes as above |
a6bc569
to
169a8f0
Compare
BUG: closes bug in Series.count when index has nulls
169a8f0
to
ca00c4d
Compare
@behzadnouri can you update according to comments |
@jreback the added test will fail if i change it what u suggest. |
@behzadnouri I just don't think its worth it to support this kind of behavior in Series.count which is inconsitent with all other stat functions on how they handle levels, they just dispatch to groupby. |
then plz go ahead and change it |
#443 would fix this, e.g. we need an option like:
|
hmm, looks like my way would break some existing tests....ok will merge as is, and when we eventually add nan group handling in groupby can simplify this code. |
need rebase? |
BUG: closes bug in Series.count when index has nulls
I just did it. thxs. |
merged via 33723f9 |
BUG: closes bug in Series.count when index has nulls
BUG: closes bug in Series.count when index has nulls
on branch: