Skip to content

Commit 1c91bca

Browse files
committed
BUG: unstack multiple levels bug described in #451
1 parent 3f8961c commit 1c91bca

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

RELEASE.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ pandas 0.6.1
3838
is about 3x faster than df[column][row] by handling fewer cases (GH #437)
3939
- Add Qt table widget to sandbox (PR #435)
4040

41-
4241
**Improvements to existing features**
4342

4443
- Improve memory usage of `DataFrame.describe` (do not copy data
@@ -49,6 +48,7 @@ pandas 0.6.1
4948
- Exclude non-numeric types in DataFrame.{corr, cov}
5049
- Override Index.astype to enable dtype casting (GH #412)
5150
- Use same float formatting function for Series.__repr__ (PR #420)
51+
- Use available console width to output DataFrame columns (PR #453)
5252

5353
**Bug fixes**
5454

@@ -62,6 +62,7 @@ pandas 0.6.1
6262
- Fix groupby exception raised with as_index=False and single column selected
6363
(GH #421)
6464
- Implement DateOffset.__ne__ causing downstream bug (GH #456)
65+
- Fix __doc__-related issue when converting py -> pyo with py2exe
6566

6667
Thanks
6768
------

pandas/core/frame.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2054,8 +2054,12 @@ def unstack(self, level=-1):
20542054
from pandas.core.reshape import unstack
20552055
if isinstance(level, (tuple, list)):
20562056
result = self
2057-
for lev in level:
2057+
to_unstack = level
2058+
while to_unstack:
2059+
lev = to_unstack[0]
20582060
result = unstack(result, lev)
2061+
to_unstack = [other - 1 if other > lev else other
2062+
for other in to_unstack[1:]]
20592063
return result
20602064
else:
20612065
return unstack(self, level)

pandas/tests/test_multilevel.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,16 @@ def test_stack_unstack_multiple(self):
469469
restacked = restacked.sortlevel(0)
470470

471471
assert_frame_equal(restacked, self.ymd)
472-
self.assertEquals(restacked.index.names,
473-
self.ymd.index.names)
472+
self.assertEquals(restacked.index.names, self.ymd.index.names)
473+
474+
# GH #451
475+
unstacked = self.ymd.unstack([1, 2])
476+
expected = self.ymd.unstack(1).unstack(1)
477+
assert_frame_equal(unstacked, expected)
478+
479+
unstacked = self.ymd.unstack([2, 1])
480+
expected = self.ymd.unstack(2).unstack(1)
481+
assert_frame_equal(unstacked, expected)
474482

475483
def test_groupby_transform(self):
476484
s = self.frame['A']

0 commit comments

Comments
 (0)