Skip to content

Commit a83c186

Browse files
committed
CLN: EAFP for count
1 parent 5563ea5 commit a83c186

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

pandas/core/groupby.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1405,10 +1405,10 @@ def aggregate(self, values, how, axis=0):
14051405

14061406
if self._filter_empty_groups:
14071407
if result.ndim == 2:
1408-
if is_numeric:
1408+
try:
14091409
result = lib.row_bool_subset(
14101410
result, (counts > 0).view(np.uint8))
1411-
else:
1411+
except ValueError:
14121412
result = lib.row_bool_subset_object(
14131413
result, (counts > 0).view(np.uint8))
14141414
else:
@@ -1442,6 +1442,7 @@ def _aggregate(self, result, counts, values, how, is_numeric):
14421442
chunk = chunk.squeeze()
14431443
agg_func(result[:, :, i], counts, chunk, comp_ids)
14441444
else:
1445+
#import ipdb; ipdb.set_trace() # XXX BREAKPOINT
14451446
agg_func(result, counts, values, comp_ids)
14461447

14471448
return trans_func(result)

vb_suite/groupby.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ def f():
146146
"""
147147

148148
groupby_multi_count = Benchmark("df.groupby(['key1', 'key2']).count()",
149-
setup, start_date=datetime(2014, 5, 5))
149+
setup, name='groupby_multi_count',
150+
start_date=datetime(2014, 5, 5))
150151
#----------------------------------------------------------------------
151152
# Series.value_counts
152153

@@ -180,11 +181,11 @@ def f():
180181
ind2 = np.random.randint(0, 2, size=100000)
181182
182183
df = DataFrame({'key1': fac1.take(ind1),
183-
'key2': fac2.take(ind2),
184-
'key3': fac2.take(ind2),
185-
'value1' : np.random.randn(100000),
186-
'value2' : np.random.randn(100000),
187-
'value3' : np.random.randn(100000)})
184+
'key2': fac2.take(ind2),
185+
'key3': fac2.take(ind2),
186+
'value1' : np.random.randn(100000),
187+
'value2' : np.random.randn(100000),
188+
'value3' : np.random.randn(100000)})
188189
"""
189190

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

223224
groupby_first_float32 = Benchmark('data2.groupby(labels).first()', setup,
224-
start_date=datetime(2013, 1, 1))
225+
start_date=datetime(2013, 1, 1))
225226

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

229230
groupby_last_float32 = Benchmark('data2.groupby(labels).last()', setup,
230-
start_date=datetime(2013, 1, 1))
231+
start_date=datetime(2013, 1, 1))
231232

232233

233234
#----------------------------------------------------------------------
@@ -285,9 +286,9 @@ def f():
285286
labels = np.random.randint(0, 2000, size=N)
286287
labels2 = np.random.randint(0, 3, size=N)
287288
df = DataFrame({'key': labels,
288-
'key2': labels2,
289-
'value1': randn(N),
290-
'value2': ['foo', 'bar', 'baz', 'qux'] * (N / 4)})
289+
'key2': labels2,
290+
'value1': randn(N),
291+
'value2': ['foo', 'bar', 'baz', 'qux'] * (N / 4)})
291292
def f(g):
292293
return 1
293294
"""

0 commit comments

Comments
 (0)