Skip to content

Commit 0f38f43

Browse files
committed
fix MultiIndex initiation from np.nan
1 parent 8d75c55 commit 0f38f43

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

pandas/tools/tests/test_pivot.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,19 +1094,22 @@ def test_margin_dropna(self):
10941094

10951095
actual = pd.crosstab(a, [b, c], rownames=['a'],
10961096
colnames=['b', 'c'], margins=True, dropna=False)
1097-
m = MultiIndex.from_arrays([[np.nan, np.nan, 'one', 'one', 'two', 'two', 'All'],
1098-
['dull', 'shiny', 'dull', 'shiny', 'dull', 'shiny', '']],
1099-
names=['b', 'c'])
1097+
1098+
m = MultiIndex(levels = [Index(['All', np.nan, 'one', 'two']),
1099+
Index(['', 'dull', 'shiny'])], labels = [[1, 1, 2, 2, 3, 3, 0],
1100+
[1, 2, 1, 2, 1, 2, 0]], names=['b', 'c'])
11001101
expected = DataFrame([[0, 0, 1, 0, 1, 0, 2], [0, 1, 2, 0, 1, 1, 5],
11011102
[0, 1, 3, 0, 2, 1, 7]], columns=m)
11021103
expected.index = Index(['bar', 'foo', 'All'], name='a')
11031104
tm.assert_frame_equal(actual, expected)
11041105

11051106
actual = pd.crosstab([a, b], c, rownames=['a', 'b'],
11061107
colnames=['c'], margins=True, dropna=False)
1107-
m = MultiIndex.from_arrays([['bar', 'bar', 'bar', 'foo', 'foo', 'foo', 'All'],
1108-
[np.nan, 'one', 'two', np.nan, 'one', 'two', '']],
1109-
names=['a', 'b'])
1108+
1109+
print actual.index
1110+
m = MultiIndex(levels=[['All', 'bar', 'foo'], ['', np.nan, 'one', 'two']],
1111+
labels=[[1, 1, 1, 2, 2, 2, 0], [1, 2, 3, 1, 2, 3, 0]],
1112+
names=['a', 'b'])
11101113
expected = DataFrame([[0, 0, 0], [1, 0, 1], [1, 0, 1], [0, 1, 1], [2, 0, 2], [1, 1, 2],
11111114
[5, 2, 7]], index=m)
11121115
expected.columns = Index(['dull', 'shiny', 'All'], name='c')

0 commit comments

Comments
 (0)