Skip to content

Commit f6aa7ca

Browse files
committed
TST: groupby unit tests
1 parent 394bb0d commit f6aa7ca

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

pandas/core/groupby.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -690,13 +690,7 @@ def aggregate(self, func_or_funcs, *args, **kwargs):
690690
except Exception:
691691
result = self._aggregate_named(func_or_funcs, *args, **kwargs)
692692

693-
if len(result) > 0:
694-
if isinstance(result.values()[0], Series):
695-
ret = DataFrame(result).T
696-
else:
697-
ret = Series(result)
698-
else:
699-
ret = Series({})
693+
ret = Series(result)
700694

701695
if not self.as_index: # pragma: no cover
702696
print 'Warning, ignoring as_index=True'
@@ -761,7 +755,7 @@ def _aggregate_simple(self, func, *args, **kwargs):
761755
result = {}
762756
for k, v in self.primary.indices.iteritems():
763757
agged = func(values.take(v), *args, **kwargs)
764-
if isinstance(output, np.ndarray):
758+
if isinstance(agged, np.ndarray):
765759
raise Exception('Must produce aggregated value')
766760
result[k] = agged
767761

pandas/tests/test_groupby.py

+5
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ def test_agg_regression1(self):
111111
expected = grouped.mean()
112112
assert_frame_equal(result, expected)
113113

114+
def test_agg_must_add(self):
115+
grouped = self.df.groupby('A')['C']
116+
self.assertRaises(Exception, grouped.agg, lambda x: x.describe())
117+
self.assertRaises(Exception, grouped.agg, lambda x: x.index[:2])
118+
114119
def test_get_group(self):
115120
wp = tm.makePanel()
116121
grouped = wp.groupby(lambda x: x.month, axis='major')

pandas/tests/test_index.py

+3
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,9 @@ def test_diff(self):
950950
result = self.index - self.index.sortlevel(1)[0]
951951
self.assert_(len(result) == 0)
952952

953+
# raise Exception called with non-MultiIndex
954+
self.assertRaises(Exception, first.diff, first.get_tuple_index())
955+
953956
def test_from_tuples(self):
954957
self.assertRaises(Exception, MultiIndex.from_tuples, [])
955958

0 commit comments

Comments
 (0)