Skip to content

Commit d20cb18

Browse files
committed
TST: unit test addressing multiindex concatenation buglet described in #615
1 parent 97ad1cf commit d20cb18

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pandas/tools/tests/test_merge.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,21 @@ def test_concat_dict(self):
822822
expected = concat([frames[k] for k in keys], keys=keys)
823823
tm.assert_frame_equal(result, expected)
824824

825+
def test_concat_multiindex_with_keys(self):
826+
index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'],
827+
['one', 'two', 'three']],
828+
labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
829+
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
830+
names=['first', 'second'])
831+
frame = DataFrame(np.random.randn(10, 3), index=index,
832+
columns=Index(['A', 'B', 'C'], name='exp'))
833+
result = concat([frame, frame], keys=[0, 1], names=['iteration'])
834+
835+
self.assertEqual(result.index.names, ['iteration'] + index.names)
836+
tm.assert_frame_equal(result.ix[0], frame)
837+
tm.assert_frame_equal(result.ix[1], frame)
838+
self.assertEqual(result.index.nlevels, 3)
839+
825840
def test_concat_keys_and_levels(self):
826841
df = DataFrame(np.random.randn(1, 3))
827842
df2 = DataFrame(np.random.randn(1, 4))

0 commit comments

Comments
 (0)