Skip to content

ENH: cythonize groupby.count #7016

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 5 commits into from
May 5, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
CLN: EAFP for count
  • Loading branch information
cpcloud committed May 5, 2014
commit a83c186b2ea4b1785346fca5b4b43f025d743ea6
5 changes: 3 additions & 2 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1405,10 +1405,10 @@ def aggregate(self, values, how, axis=0):

if self._filter_empty_groups:
if result.ndim == 2:
if is_numeric:
try:
result = lib.row_bool_subset(
result, (counts > 0).view(np.uint8))
else:
except ValueError:
result = lib.row_bool_subset_object(
result, (counts > 0).view(np.uint8))
else:
Expand Down Expand Up @@ -1442,6 +1442,7 @@ def _aggregate(self, result, counts, values, how, is_numeric):
chunk = chunk.squeeze()
agg_func(result[:, :, i], counts, chunk, comp_ids)
else:
#import ipdb; ipdb.set_trace() # XXX BREAKPOINT
agg_func(result, counts, values, comp_ids)

return trans_func(result)
Expand Down
23 changes: 12 additions & 11 deletions vb_suite/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def f():
"""

groupby_multi_count = Benchmark("df.groupby(['key1', 'key2']).count()",
setup, start_date=datetime(2014, 5, 5))
setup, name='groupby_multi_count',
start_date=datetime(2014, 5, 5))
#----------------------------------------------------------------------
# Series.value_counts

Expand Down Expand Up @@ -180,11 +181,11 @@ def f():
ind2 = np.random.randint(0, 2, size=100000)

df = DataFrame({'key1': fac1.take(ind1),
'key2': fac2.take(ind2),
'key3': fac2.take(ind2),
'value1' : np.random.randn(100000),
'value2' : np.random.randn(100000),
'value3' : np.random.randn(100000)})
'key2': fac2.take(ind2),
'key3': fac2.take(ind2),
'value1' : np.random.randn(100000),
'value2' : np.random.randn(100000),
'value3' : np.random.randn(100000)})
"""

stmt = "df.pivot_table(rows='key1', cols=['key2', 'key3'])"
Expand Down Expand Up @@ -221,13 +222,13 @@ def f():
start_date=datetime(2012, 5, 1))

groupby_first_float32 = Benchmark('data2.groupby(labels).first()', setup,
start_date=datetime(2013, 1, 1))
start_date=datetime(2013, 1, 1))

groupby_last = Benchmark('data.groupby(labels).last()', setup,
start_date=datetime(2012, 5, 1))

groupby_last_float32 = Benchmark('data2.groupby(labels).last()', setup,
start_date=datetime(2013, 1, 1))
start_date=datetime(2013, 1, 1))


#----------------------------------------------------------------------
Expand Down Expand Up @@ -285,9 +286,9 @@ def f():
labels = np.random.randint(0, 2000, size=N)
labels2 = np.random.randint(0, 3, size=N)
df = DataFrame({'key': labels,
'key2': labels2,
'value1': randn(N),
'value2': ['foo', 'bar', 'baz', 'qux'] * (N / 4)})
'key2': labels2,
'value1': randn(N),
'value2': ['foo', 'bar', 'baz', 'qux'] * (N / 4)})
def f(g):
return 1
"""
Expand Down