Skip to content

Commit 873409d

Browse files
committed
BUG: fix sum over level failure with MultiIndex of length 1, close #1568
1 parent b061260 commit 873409d

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

RELEASE.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pandas 0.8.1
6060
- Fix DataFrame.rank error on integer data (#1589)
6161
- Selection of multiple SparseDataFrame columns by list in __getitem__ (#1585)
6262
- Override Index.tolist for compatibility with MultiIndex (#1576)
63+
- Fix hierarchical summing bug with MultiIndex of length 1 (#1568)
6364

6465
pandas 0.8.0
6566
============

pandas/core/groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True):
10831083

10841084
if (not any_callable and not all_in_columns
10851085
and not any_arraylike and match_axis_length
1086-
and not level):
1086+
and level is None):
10871087
keys = [com._asarray_tuplesafe(keys)]
10881088

10891089
if isinstance(level, (tuple, list)):

pandas/tests/test_multilevel.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,13 @@ def aggf(x):
10021002

10031003
assert_frame_equal(leftside, rightside)
10041004

1005+
def test_stat_op_corner(self):
1006+
obj = Series([10.0], index=MultiIndex.from_tuples([(2, 3)]))
1007+
1008+
result = obj.sum(level=0)
1009+
expected = Series([10.0], index=[2])
1010+
assert_series_equal(result, expected)
1011+
10051012
def test_frame_any_all_group(self):
10061013
df = DataFrame({'data': [False, False, True, False, True, False, True]},
10071014
index=[['one', 'one', 'two', 'one', 'two', 'two', 'two'],

0 commit comments

Comments
 (0)