Skip to content

Commit 8d3a39a

Browse files
committed
Merge pull request #8417 from jreback/mi_grouping
BUG: regression in groupby with a pass thru multiindex on axis=1 (GH7997)
2 parents 4074957 + 4802d0f commit 8d3a39a

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

doc/source/v0.15.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ Internal Refactoring
549549

550550
In 0.15.0 ``Index`` has internally been refactored to no longer sub-class ``ndarray``
551551
but instead subclass ``PandasObject``, similarly to the rest of the pandas objects. This change allows very easy sub-classing and creation of new index types. This should be
552-
a transparent change with only very limited API implications (:issue:`5080`, :issue:`7439`, :issue:`7796`, :issue:`8024`, :issue:`8367`)
552+
a transparent change with only very limited API implications (:issue:`5080`, :issue:`7439`, :issue:`7796`, :issue:`8024`, :issue:`8367`, :issue:`7997`)
553553

554554
- you may need to unpickle pandas version < 0.15.0 pickles using ``pd.read_pickle`` rather than ``pickle.load``. See :ref:`pickle docs <io.pickle>`
555555
- when plotting with a ``PeriodIndex``. The ``matplotlib`` internal axes will now be arrays of ``Period`` rather than a ``PeriodIndex``. (this is similar to how a ``DatetimeIndex`` passes arrays of ``datetimes`` now)

pandas/core/groupby.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3233,7 +3233,8 @@ def _reindex_output(self, result):
32333233

32343234
levels_list = [ ping._group_index for ping in groupings ]
32353235
index = MultiIndex.from_product(levels_list, names=self.grouper.names)
3236-
return result.reindex(**{ self.obj._get_axis_name(self.axis) : index, 'copy' : False }).sortlevel()
3236+
d = { self.obj._get_axis_name(self.axis) : index, 'copy' : False }
3237+
return result.reindex(**d).sortlevel(axis=self.axis)
32373238

32383239
def _iterate_column_groupbys(self):
32393240
for i, colname in enumerate(self._selected_obj.columns):

pandas/tests/test_groupby.py

+10
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,16 @@ def test_groupby_as_index_agg(self):
14951495
result3 = grouped['C'].agg({'Q': np.sum})
14961496
assert_frame_equal(result3, expected3)
14971497

1498+
def test_mulitindex_passthru(self):
1499+
1500+
# GH 7997
1501+
# regression from 0.14.1
1502+
df = pd.DataFrame([[1,2,3],[4,5,6],[7,8,9]])
1503+
df.columns = pd.MultiIndex.from_tuples([(0,1),(1,1),(2,1)])
1504+
1505+
result = df.groupby(axis=1, level=[0,1]).first()
1506+
assert_frame_equal(result, df)
1507+
14981508
def test_multifunc_select_col_integer_cols(self):
14991509
df = self.df
15001510
df.columns = np.arange(len(df.columns))

0 commit comments

Comments
 (0)