Skip to content

Commit 0a02156

Browse files
committed
BUG: add test case for integer index failure re: #819
1 parent 094aee0 commit 0a02156

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

pandas/core/groupby.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -1115,14 +1115,13 @@ def aggregate(self, arg, *args, **kwargs):
11151115
raise ValueError('Can only pass dict with axis=0')
11161116

11171117
obj = self._obj_with_exclusions
1118-
# more kludge
1119-
if len(obj.columns) == 1:
1120-
series_obj = Series(obj.ix[:,0])
1121-
series_name = obj.columns[0]
1122-
for col, func in arg.iteritems():
1123-
colg = SeriesGroupBy(series_obj, column=series_name,
1118+
1119+
if self._column is not None:
1120+
series_obj = Series(obj[self._column])
1121+
for fname, func in arg.iteritems():
1122+
colg = SeriesGroupBy(series_obj, column=self._column,
11241123
grouper=self.grouper)
1125-
result[col] = colg.aggregate(func)
1124+
result[fname] = colg.aggregate(func)
11261125
else:
11271126
for col, func in arg.iteritems():
11281127
colg = SeriesGroupBy(obj[col], column=col,

pandas/tests/test_groupby.py

+6
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,12 @@ def test_groupby_as_index_agg(self):
710710
result3 = grouped['C'].agg({'Q' : np.sum})
711711
assert_frame_equal(result3, expected3)
712712

713+
def test_multifunc_select_col_integer_cols(self):
714+
df = self.df
715+
df.columns = np.arange(len(df.columns))
716+
717+
# it works!
718+
result = df.groupby(1, as_index=False)[2].agg({'Q' : np.mean})
713719

714720
def test_as_index_series_return_frame(self):
715721
grouped = self.df.groupby('A', as_index=False)

0 commit comments

Comments
 (0)