From 96938c4cdd5b207631b5c2976c42947ce0caaa68 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 4 Sep 2018 16:51:49 +0100 Subject: [PATCH 1/2] TST: add test for GH6131 --- pandas/tests/io/formats/test_to_html.py | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index f69cac62513d4..0d80ef460c748 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -1844,6 +1844,64 @@ def test_to_html_no_index_max_rows(self): """) assert result == expected + def test_to_html_pivot_table_max_cols(self): + # GH https://github.com/pandas-dev/pandas/issues/6131 + df = DataFrame([ + {'a': 'aa', 'b': 'ba', 'c': 'ca', 'd': 1}, + {'a': 'ab', 'b': 'bb', 'c': 'cc', 'd': 2}, + {'a': 'ac', 'b': 'bc', 'c': 'cc', 'd': 3} + ]) + result = df.pivot_table( + columns=['a'], index=['b', 'c']).to_html(max_cols=2) + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
d
aaa...ac
bc
baca1.0...NaN
bbccNaN...NaN
bcccNaN...3.0
""") + assert result == expected + def test_to_html_notebook_has_style(self): df = pd.DataFrame({"A": [1, 2, 3]}) result = df.to_html(notebook=True) From 2d9c48fe011c71244ae0fb32f564b6c8d9269cb2 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sat, 8 Sep 2018 23:16:48 +0100 Subject: [PATCH 2/2] create result of pivot_table example explicitly --- pandas/tests/io/formats/test_to_html.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 0d80ef460c748..845fb1ee3dc3a 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -1844,15 +1844,18 @@ def test_to_html_no_index_max_rows(self): """) assert result == expected - def test_to_html_pivot_table_max_cols(self): - # GH https://github.com/pandas-dev/pandas/issues/6131 - df = DataFrame([ - {'a': 'aa', 'b': 'ba', 'c': 'ca', 'd': 1}, - {'a': 'ab', 'b': 'bb', 'c': 'cc', 'd': 2}, - {'a': 'ac', 'b': 'bc', 'c': 'cc', 'd': 3} - ]) - result = df.pivot_table( - columns=['a'], index=['b', 'c']).to_html(max_cols=2) + def test_to_html_multiindex_max_cols(self): + # GH 6131 + index = MultiIndex(levels=[['ba', 'bb', 'bc'], ['ca', 'cb', 'cc']], + labels=[[0, 1, 2], [0, 1, 2]], + names=['b', 'c']) + columns = MultiIndex(levels=[['d'], ['aa', 'ab', 'ac']], + labels=[[0, 0, 0], [0, 1, 2]], + names=[None, 'a']) + data = np.array( + [[1., np.nan, np.nan], [np.nan, 2., np.nan], [np.nan, np.nan, 3.]]) + df = DataFrame(data, index, columns) + result = df.to_html(max_cols=2) expected = dedent("""\ @@ -1886,7 +1889,7 @@ def test_to_html_pivot_table_max_cols(self): - +
bbcccb NaN ... NaN