Skip to content

Commit 9489cb2

Browse files
committed
BUG: Fix issue pandas-dev#14848 groupby().describe() on indices containing all tuples
1 parent 0fe491d commit 9489cb2

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ Bug Fixes
351351
- Bug in converting object elements of array-like objects to unsigned 64-bit integers (:issue:`4471`, :issue:`14982`)
352352
- Bug in ``pd.pivot_table()`` where no error was raised when values argument was not in the columns (:issue:`14938`)
353353

354+
- Bug in ``DataFrame.groupby().describe()`` when grouping on ``Index`` containing tuples (:issue:`14848`)
354355

355356

356357

pandas/tests/groupby/test_groupby.py

+13
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,19 @@ def test_frame_describe_multikey(self):
14901490
for name, group in groupedT:
14911491
assert_frame_equal(result[name], group.describe())
14921492

1493+
# GH #14848
1494+
def test_frame_describe_tupleindex(self):
1495+
df1 = DataFrame({'x': [1, 2, 3, 4, 5] * 3,
1496+
'y': [10, 20, 30, 40, 50] * 3,
1497+
'z': [100, 200, 300, 400, 500] * 3})
1498+
df1['k'] = [(0, 0, 1), (0, 1, 0), (1, 0, 0)] * 5
1499+
df2 = df1.rename(columns={'k': 'key'})
1500+
des1 = df1.groupby('k').describe()
1501+
des2 = df2.groupby('key').describe()
1502+
if len(des1) > 0:
1503+
des2.index.set_names(des1.index.names, inplace=True)
1504+
assert_frame_equal(des1, des2)
1505+
14931506
def test_frame_groupby(self):
14941507
grouped = self.tsframe.groupby(lambda x: x.weekday())
14951508

pandas/tools/merge.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1626,7 +1626,11 @@ def __init__(self, objs, axis=0, join='outer', join_axes=None,
16261626
clean_objs.append(v)
16271627
objs = clean_objs
16281628
name = getattr(keys, 'name', None)
1629-
keys = Index(clean_keys, name=name)
1629+
# GH 14848
1630+
# Don't pass name when creating index (# GH 14252)
1631+
# So that if keys are tuples, name isn't checked
1632+
keys = Index(clean_keys)
1633+
keys.name = name
16301634

16311635
if len(objs) == 0:
16321636
raise ValueError('All objects passed were None')

0 commit comments

Comments
 (0)