Skip to content

Commit b4b09bf

Browse files
committed
Compared whole dataframes in test_pivot_table_margins_name_with_aggfunc_list
1 parent 98ab8be commit b4b09bf

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

pandas/tools/tests/test_pivot.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -781,10 +781,19 @@ def test_pivot_table_with_iterator_values(self):
781781

782782
def test_pivot_table_margins_name_with_aggfunc_list(self):
783783
# GH 13354
784-
margins_name = 'Weekly'
785-
table = self.data.pivot_table(index='A', columns='B', margins=True,
786-
margins_name=margins_name, aggfunc=[np.mean, max])
787-
self.assertEqual(table[:][:].index[2], margins_name)
784+
margins_name='Weekly'
785+
costs = pd.DataFrame({'item':['bacon','cheese','bacon','cheese'],
786+
'cost':[2.5,4.5,3.2,3.3],
787+
'day':['M','M','T','T']})
788+
table = costs.pivot_table(index="item",columns="day",margins=True,
789+
margins_name=margins_name,aggfunc=[np.mean,max])
790+
ix = pd.Index(['bacon', 'cheese', margins_name], dtype='object', name='item')
791+
tups = [('mean', 'cost', 'M'), ('mean', 'cost', 'T'),
792+
('mean', 'cost', margins_name), ('max', 'cost', 'M'),
793+
('max', 'cost', 'T'), ('max', 'cost', margins_name)]
794+
cols = pd.MultiIndex.from_tuples(tups, names=[None, None, 'day'])
795+
expected = pd.DataFrame(table.values, index=ix, columns=cols)
796+
tm.assert_frame_equal(table, expected)
788797

789798

790799
class TestCrosstab(tm.TestCase):

0 commit comments

Comments
 (0)