From 6adc266323903aeb8baec2b72a5208d926916db3 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 04:31:00 +0100 Subject: [PATCH 01/94] BUG: header alignment --- pandas/io/formats/html.py | 44 +++++++++---------------- pandas/tests/io/formats/test_to_html.py | 29 ++++++++++++++++ 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index a6b03c9c6dd23..fb348036628db 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -195,31 +195,12 @@ def write_result(self, buf): buffer_put_lines(buf, self.elements) def _write_header(self, indent): - truncate_h = self.fmt.truncate_h - row_levels = self.frame.index.nlevels if not self.fmt.header: # write nothing return indent - def _column_header(): - if self.fmt.index: - row = [''] * (self.frame.index.nlevels - 1) - else: - row = [] - - if isinstance(self.columns, ABCMultiIndex): - if self.fmt.has_column_names and self.fmt.index: - row.append(single_column_table(self.columns.names)) - else: - row.append('') - style = "text-align: {just};".format(just=self.fmt.justify) - row.extend([single_column_table(c, self.fmt.justify, style) - for c in self.columns]) - else: - if self.fmt.index: - row.append(self.columns.name or '') - row.extend(self.columns) - return row + truncate_h = self.fmt.truncate_h + row_levels = self.frame.index.nlevels self.write('', indent) @@ -282,11 +263,11 @@ def _column_header(): values = (values[:ins_col] + [u('...')] + values[ins_col:]) - name = self.columns.names[lnum] - row = [''] * (row_levels - 1) + ['' if name is None else - pprint_thing(name)] - - if row == [""] and self.fmt.index is False: + if self.fmt.index: + name = self.columns.names[lnum] + row = [''] * (row_levels - 1) + ['' if name is None else + pprint_thing(name)] + else: row = [] tags = {} @@ -302,14 +283,19 @@ def _column_header(): self.write_tr(row, indent, self.indent_delta, tags=tags, header=True) else: - col_row = _column_header() + if self.fmt.index: + row = [''] * (row_levels - 1) + [self.columns.name or ''] + else: + row = [] + row.extend(self.columns) + align = self.fmt.justify if truncate_h: ins_col = row_levels + self.fmt.tr_col_num - col_row.insert(ins_col, '...') + row.insert(ins_col, '...') - self.write_tr(col_row, indent, self.indent_delta, header=True, + self.write_tr(row, indent, self.indent_delta, header=True, align=align) if all((self.fmt.has_index_names, diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 845fb1ee3dc3a..835dbe656c58c 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -1905,6 +1905,35 @@ def test_to_html_multiindex_max_cols(self): """) assert result == expected + def test_to_html_multi_indices_index_false(self): + # GH 22579 + index = pd.MultiIndex.from_product([['a'], ['b', 'c']]) + df = pd.DataFrame(np.zeros((2, 2), dtype=int), index, index) + result = df.to_html(index=False) + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + +
a
bc
00
00
""") + 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 a30da560257bfd217e84f24b997981fe79bd03f9 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 12:16:46 +0100 Subject: [PATCH 02/94] add test_to_html_index_name_single_index --- pandas/tests/io/formats/test_to_html.py | 97 ++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 835dbe656c58c..1c3d14e665ed3 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -1907,8 +1907,8 @@ def test_to_html_multiindex_max_cols(self): def test_to_html_multi_indices_index_false(self): # GH 22579 - index = pd.MultiIndex.from_product([['a'], ['b', 'c']]) - df = pd.DataFrame(np.zeros((2, 2), dtype=int), index, index) + multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) + df = DataFrame(np.zeros((2, 2), dtype=int), multi_index, multi_index) result = df.to_html(index=False) expected = dedent("""\ @@ -1934,6 +1934,99 @@ def test_to_html_multi_indices_index_false(self):
""") assert result == expected + def test_to_html_index_name_single_index(self): + df = DataFrame(np.zeros((2, 2), dtype=int)) + df.index.name = 'index.name' + df.columns.name = 'columns.name' + result = df.to_html() + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name01
index.name
000
100
""") + assert result == expected + + df = DataFrame(np.zeros((2, 2), dtype=int)) + df.columns.name = 'columns.name' + result = df.to_html() + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + +
columns.name01
000
100
""") + assert result == expected + + df = DataFrame(np.zeros((2, 2), dtype=int)) + df.index.name = 'index.name' + result = df.to_html() + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + + + + + + +
01
index.name
000
100
""") + 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 b444fa2f33849cd1f986f816da5a30e656afc7b1 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 12:21:17 +0100 Subject: [PATCH 03/94] add placeholders for multiIndex tests --- pandas/tests/io/formats/test_to_html.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 1c3d14e665ed3..0a546ad0848ab 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2027,6 +2027,24 @@ def test_to_html_index_name_single_index(self): """) assert result == expected + def test_to_html_index_name_multi_index_column(self): + pass + + def test_to_html_index_name_multi_index_index(self): + pass + + def test_to_html_index_name_multi_index_both(self): + pass + + def test_to_html_index_name_multi_index_column_index_false(self): + pass + + def test_to_html_index_name_multi_index_index_index_false(self): + pass + + def test_to_html_index_name_multi_index_both_index_false(self): + pass + def test_to_html_notebook_has_style(self): df = pd.DataFrame({"A": [1, 2, 3]}) result = df.to_html(notebook=True) From c61ea4a72253a495800f18c0db068c75431b8e1c Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 12:51:03 +0100 Subject: [PATCH 04/94] add regression test --- pandas/tests/io/formats/test_to_html.py | 47 ++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 0a546ad0848ab..7718a208f5f17 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2028,7 +2028,52 @@ def test_to_html_index_name_single_index(self): assert result == expected def test_to_html_index_name_multi_index_column(self): - pass + multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) + + # df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) + # df.index.name = 'index.name' + # df.columns.name = 'columns.name' + # result = df.to_html() + + # df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) + # df.columns.name = 'columns.name' + # result = df.to_html() + + df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) + df.index.name = 'index.name' + result = df.to_html() + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
a
bc
index.name
000
100
""") + assert result == expected def test_to_html_index_name_multi_index_index(self): pass From 863b6d674fe52c04dc355405585b51f14f2416a2 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 12:57:51 +0100 Subject: [PATCH 05/94] add regression test --- pandas/tests/io/formats/test_to_html.py | 40 ++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 7718a208f5f17..4c1111a193d95 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2076,7 +2076,45 @@ def test_to_html_index_name_multi_index_column(self): assert result == expected def test_to_html_index_name_multi_index_index(self): - pass + multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) + + # df = DataFrame(np.zeros((2, 2), dtype=int), index=multi_index) + # df.index.name = 'index.name' + # df.columns.name = 'columns.name' + # result = df.to_html() + + df = DataFrame(np.zeros((2, 2), dtype=int), index=multi_index) + df.columns.name = 'columns.name' + result = df.to_html() + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + + + +
columns.name01
ab00
c00
""") + assert result == expected + + # df = DataFrame(np.zeros((2, 2), dtype=int), index=multi_index) + # df.index.name = 'index.name' + # result = df.to_html() def test_to_html_index_name_multi_index_both(self): pass From b44d4ffb77df28fadfb5501a46f6bf216bc97587 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 13:10:27 +0100 Subject: [PATCH 06/94] add regression test --- pandas/tests/io/formats/test_to_html.py | 54 ++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 4c1111a193d95..782ce852d2bec 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2117,10 +2117,60 @@ def test_to_html_index_name_multi_index_index(self): # result = df.to_html() def test_to_html_index_name_multi_index_both(self): - pass + # multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) - def test_to_html_index_name_multi_index_column_index_false(self): + # df = DataFrame(np.zeros((2, 2), dtype=int), multi_index, multi_index) + # df.index.name = 'index.name' + # df.columns.name = 'columns.name' + # result = df.to_html() + + # df = DataFrame(np.zeros((2, 2), dtype=int), multi_index, multi_index) + # df.columns.name = 'columns.name' + # result = df.to_html() + + # df = DataFrame(np.zeros((2, 2), dtype=int), multi_index, multi_index) + # df.index.name = 'index.name' + # result = df.to_html() pass + + def test_to_html_index_name_multi_index_column_index_false(self): + multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) + + # df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) + # df.index.name = 'index.name' + # df.columns.name = 'columns.name' + # result = df.to_html(index=False) + + # df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) + # df.columns.name = 'columns.name' + # result = df.to_html(index=False) + + df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) + df.index.name = 'index.name' + result = df.to_html(index=False) + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + +
a
bc
00
00
""") + assert result == expected def test_to_html_index_name_multi_index_index_index_false(self): pass From d5c37e336e0d26e301bb701863af0d184c7e70b0 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 13:18:00 +0100 Subject: [PATCH 07/94] add regression test --- pandas/tests/io/formats/test_to_html.py | 37 +++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 782ce852d2bec..40026197cbb6c 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2132,7 +2132,7 @@ def test_to_html_index_name_multi_index_both(self): # df.index.name = 'index.name' # result = df.to_html() pass - + def test_to_html_index_name_multi_index_column_index_false(self): multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) @@ -2173,7 +2173,40 @@ def test_to_html_index_name_multi_index_column_index_false(self): assert result == expected def test_to_html_index_name_multi_index_index_index_false(self): - pass + multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) + + # df = DataFrame(np.zeros((2, 2), dtype=int), index=multi_index) + # df.index.name = 'index.name' + # df.columns.name = 'columns.name' + # result = df.to_html(index=False) + + # df = DataFrame(np.zeros((2, 2), dtype=int), index=multi_index) + # df.columns.name = 'columns.name' + # result = df.to_html(index=False) + + df = DataFrame(np.zeros((2, 2), dtype=int), index=multi_index) + df.index.name = 'index.name' + result = df.to_html(index=False) + expected = dedent("""\ + + + + + + + + + + + + + + + + + +
01
00
00
""") + assert result == expected def test_to_html_index_name_multi_index_both_index_false(self): pass From 6b441df419120202ffc8dc0d23a72c0303be1370 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 13:25:45 +0100 Subject: [PATCH 08/94] prep test_to_html_index_name_multi_index_both_index_false --- pandas/tests/io/formats/test_to_html.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 40026197cbb6c..58602d0fabb76 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2209,6 +2209,21 @@ def test_to_html_index_name_multi_index_index_index_false(self): assert result == expected def test_to_html_index_name_multi_index_both_index_false(self): + # multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) + + # df = DataFrame(np.zeros((2, 2), dtype=int), multi_index, multi_index) + # df.index.name = 'index.name' + # df.columns.name = 'columns.name' + # result = df.to_html(index=False) + + # df = DataFrame(np.zeros((2, 2), dtype=int), multi_index, multi_index) + # df.columns.name = 'columns.name' + # result = df.to_html(index=False) + + # df = DataFrame(np.zeros((2, 2), dtype=int), multi_index, multi_index) + # df.index.name = 'index.name' + # result = df.to_html(index=False) + pass def test_to_html_notebook_has_style(self): From dcf74a56178a402e1f076cb70c4bcba8423c1f25 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 15:59:22 +0100 Subject: [PATCH 09/94] add regression test --- pandas/tests/io/formats/test_to_html.py | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 58602d0fabb76..9679405818006 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2226,6 +2226,46 @@ def test_to_html_index_name_multi_index_both_index_false(self): pass + def test_to_html_index_names_multi_index_column(self): + columns_multi_index = MultiIndex.from_product( + [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) + df = DataFrame(np.zeros((2, 2), dtype=int), + columns=columns_multi_index) + df.index.name = 'index.name' + result = df.to_html() + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
index.name
000
100
""") + 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 dd07605c5296d647600d330a56bf17890713db72 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 16:05:24 +0100 Subject: [PATCH 10/94] add regression test --- pandas/tests/io/formats/test_to_html.py | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 9679405818006..d941437425a13 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2266,6 +2266,44 @@ def test_to_html_index_names_multi_index_column(self): """) assert result == expected + def test_to_html_index_names_multi_index_index(self): + index_multi_index = MultiIndex.from_product( + [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) + df = DataFrame(np.zeros((2, 2), dtype=int), index=index_multi_index) + df.columns.name = 'columns.name' + result = df.to_html() + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name01
index.name.0index.name.1
ab00
c00
""") + 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 4605a4ed20f11b63bf3d893cace09d478666082f Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 16:11:30 +0100 Subject: [PATCH 11/94] add regression test --- pandas/tests/io/formats/test_to_html.py | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index d941437425a13..0e5c071807384 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2304,6 +2304,51 @@ def test_to_html_index_names_multi_index_index(self): """) assert result == expected + def test_to_html_index_names_multi_index_both(self): + index_multi_index = MultiIndex.from_product( + [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) + columns_multi_index = MultiIndex.from_product( + [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) + df = DataFrame(np.zeros((2, 2), dtype=int), + index=index_multi_index, columns=columns_multi_index) + result = df.to_html() + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
index.name.0index.name.1
ab00
c00
""") + 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 dd825f35f5a4c86477b9a418661703a7c0820980 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 16:32:23 +0100 Subject: [PATCH 12/94] add regression test --- pandas/tests/io/formats/test_to_html.py | 45 +++++++++++++++++++++---- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 0e5c071807384..12c62eb0daf81 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2028,17 +2028,50 @@ def test_to_html_index_name_single_index(self): assert result == expected def test_to_html_index_name_multi_index_column(self): - multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) - - # df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) - # df.index.name = 'index.name' - # df.columns.name = 'columns.name' - # result = df.to_html() + columns_multi_index = MultiIndex.from_product( + [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) + df = DataFrame(np.zeros((2, 2), dtype=int), + columns=columns_multi_index) + df.index.name = 'index.name' + result = df.to_html() + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
index.name
000
100
""") + assert result == expected # df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) # df.columns.name = 'columns.name' # result = df.to_html() + multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) df.index.name = 'index.name' result = df.to_html() From b7fe95cfcc786f117a66e9013a5c4c7bc80c71a5 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 16:40:24 +0100 Subject: [PATCH 13/94] add regression test --- pandas/tests/io/formats/test_to_html.py | 35 ++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 12c62eb0daf81..b0b2dcf294875 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2067,9 +2067,38 @@ def test_to_html_index_name_multi_index_column(self): """) assert result == expected - # df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) - # df.columns.name = 'columns.name' - # result = df.to_html() + columns_multi_index = MultiIndex.from_product( + [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) + df = DataFrame(np.zeros((2, 2), dtype=int), + columns=columns_multi_index) + result = df.to_html() + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
000
100
""") + assert result == expected multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) From dec609d847881ab00ad301521dbd0c0f8f502df4 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 17:38:21 +0100 Subject: [PATCH 14/94] add regression test --- pandas/tests/io/formats/test_to_html.py | 42 ++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index b0b2dcf294875..6d984c11aa994 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2138,13 +2138,45 @@ def test_to_html_index_name_multi_index_column(self): assert result == expected def test_to_html_index_name_multi_index_index(self): - multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) - # df = DataFrame(np.zeros((2, 2), dtype=int), index=multi_index) - # df.index.name = 'index.name' - # df.columns.name = 'columns.name' - # result = df.to_html() + index_multi_index = MultiIndex.from_product( + [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) + df = DataFrame(np.zeros((2, 2), dtype=int), index=index_multi_index) + df.columns.name = 'columns.name' + result = df.to_html() + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name01
index.name.0index.name.1
ab00
c00
""") + assert result == expected + multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) df = DataFrame(np.zeros((2, 2), dtype=int), index=multi_index) df.columns.name = 'columns.name' result = df.to_html() From 5b9bc6e24bb011876c442efc9910f3fb30cb3529 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 17:44:34 +0100 Subject: [PATCH 15/94] add regression test --- pandas/tests/io/formats/test_to_html.py | 38 +++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 6d984c11aa994..1d54a0c38b87d 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2206,9 +2206,41 @@ def test_to_html_index_name_multi_index_index(self): """) assert result == expected - # df = DataFrame(np.zeros((2, 2), dtype=int), index=multi_index) - # df.index.name = 'index.name' - # result = df.to_html() + index_multi_index = MultiIndex.from_product( + [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) + df = DataFrame(np.zeros((2, 2), dtype=int), index=index_multi_index) + result = df.to_html() + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
01
index.name.0index.name.1
ab00
c00
""") + assert result == expected def test_to_html_index_name_multi_index_both(self): # multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) From a725108eefc584b03c4c556cb902054209b95617 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 17:51:29 +0100 Subject: [PATCH 16/94] move regression test --- pandas/tests/io/formats/test_to_html.py | 94 ++++++++++++------------- 1 file changed, 44 insertions(+), 50 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 1d54a0c38b87d..535cd41af774d 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2243,12 +2243,51 @@ def test_to_html_index_name_multi_index_index(self): assert result == expected def test_to_html_index_name_multi_index_both(self): - # multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) + index_multi_index = MultiIndex.from_product( + [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) + columns_multi_index = MultiIndex.from_product( + [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) + df = DataFrame(np.zeros((2, 2), dtype=int), + index=index_multi_index, columns=columns_multi_index) + result = df.to_html() + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
index.name.0index.name.1
ab00
c00
""") + assert result == expected - # df = DataFrame(np.zeros((2, 2), dtype=int), multi_index, multi_index) - # df.index.name = 'index.name' - # df.columns.name = 'columns.name' - # result = df.to_html() + # multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) # df = DataFrame(np.zeros((2, 2), dtype=int), multi_index, multi_index) # df.columns.name = 'columns.name' @@ -2430,51 +2469,6 @@ def test_to_html_index_names_multi_index_index(self): """) assert result == expected - def test_to_html_index_names_multi_index_both(self): - index_multi_index = MultiIndex.from_product( - [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) - columns_multi_index = MultiIndex.from_product( - [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) - df = DataFrame(np.zeros((2, 2), dtype=int), - index=index_multi_index, columns=columns_multi_index) - result = df.to_html() - expected = dedent("""\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name.0a
columns.name.1bc
index.name.0index.name.1
ab00
c00
""") - 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 d7e82378a9e41c9e3b0044785b9aaec00951b774 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 17:57:40 +0100 Subject: [PATCH 17/94] remove duplicated regression tests --- pandas/tests/io/formats/test_to_html.py | 78 ------------------------- 1 file changed, 78 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 535cd41af774d..5eb16056e2ba7 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2391,84 +2391,6 @@ def test_to_html_index_name_multi_index_both_index_false(self): pass - def test_to_html_index_names_multi_index_column(self): - columns_multi_index = MultiIndex.from_product( - [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) - df = DataFrame(np.zeros((2, 2), dtype=int), - columns=columns_multi_index) - df.index.name = 'index.name' - result = df.to_html() - expected = dedent("""\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name.0a
columns.name.1bc
index.name
000
100
""") - assert result == expected - - def test_to_html_index_names_multi_index_index(self): - index_multi_index = MultiIndex.from_product( - [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) - df = DataFrame(np.zeros((2, 2), dtype=int), index=index_multi_index) - df.columns.name = 'columns.name' - result = df.to_html() - expected = dedent("""\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name01
index.name.0index.name.1
ab00
c00
""") - 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 47fd13231682edcab7ad80b3f6dfe276b6fb2959 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 18:03:59 +0100 Subject: [PATCH 18/94] add regression test --- pandas/tests/io/formats/test_to_html.py | 41 ++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 5eb16056e2ba7..2b30b645e52e4 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2287,11 +2287,42 @@ def test_to_html_index_name_multi_index_both(self): """) assert result == expected - # multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) - - # df = DataFrame(np.zeros((2, 2), dtype=int), multi_index, multi_index) - # df.columns.name = 'columns.name' - # result = df.to_html() + multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) + columns_multi_index = MultiIndex.from_product( + [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) + df = DataFrame(np.zeros((2, 2), dtype=int), + index=multi_index, columns=columns_multi_index) + result = df.to_html() + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
ab00
c00
""") + assert result == expected # df = DataFrame(np.zeros((2, 2), dtype=int), multi_index, multi_index) # df.index.name = 'index.name' From 4e48a32ec5bd0690314e30092ed1a465b8d24cd9 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 18:09:03 +0100 Subject: [PATCH 19/94] add regression test --- pandas/tests/io/formats/test_to_html.py | 46 ++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 2b30b645e52e4..2f6a8cf3164cb 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2324,10 +2324,48 @@ def test_to_html_index_name_multi_index_both(self): """) assert result == expected - # df = DataFrame(np.zeros((2, 2), dtype=int), multi_index, multi_index) - # df.index.name = 'index.name' - # result = df.to_html() - pass + multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) + index_multi_index = MultiIndex.from_product( + [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) + df = DataFrame(np.zeros((2, 2), dtype=int), + index=index_multi_index, columns=multi_index) + result = df.to_html() + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
a
bc
index.name.0index.name.1
ab00
c00
""") + assert result == expected def test_to_html_index_name_multi_index_column_index_false(self): multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) From 30ac94e1ed671aa2e8b0fc7588f697964e188e4e Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 20:22:48 +0100 Subject: [PATCH 20/94] add failing test --- pandas/tests/io/formats/test_to_html.py | 40 +++++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 2f6a8cf3164cb..cf926d77605c8 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2368,17 +2368,45 @@ def test_to_html_index_name_multi_index_both(self): assert result == expected def test_to_html_index_name_multi_index_column_index_false(self): - multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) - - # df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) - # df.index.name = 'index.name' - # df.columns.name = 'columns.name' - # result = df.to_html(index=False) + columns_multi_index = MultiIndex.from_product( + [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) + df = DataFrame(np.zeros((2, 2), dtype=int), + columns=columns_multi_index) + df.index.name = 'index.name' + result = df.to_html(index=False) + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
00
00
""") + assert result == expected # df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) # df.columns.name = 'columns.name' # result = df.to_html(index=False) + multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) df.index.name = 'index.name' result = df.to_html(index=False) From 5f6a8d151c3c52c5174d261f7d9b0aa8aa9a4e1c Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 20:57:59 +0100 Subject: [PATCH 21/94] split and rename tests --- pandas/tests/io/formats/test_to_html.py | 60 +++++++++++-------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index cf926d77605c8..e615e3115d630 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -1934,7 +1934,7 @@ def test_to_html_multi_indices_index_false(self): """) assert result == expected - def test_to_html_index_name_single_index(self): + def test_to_html_single_index_named_index_both(self): df = DataFrame(np.zeros((2, 2), dtype=int)) df.index.name = 'index.name' df.columns.name = 'columns.name' @@ -1968,6 +1968,7 @@ def test_to_html_index_name_single_index(self): """) assert result == expected + def test_to_html_single_index_named_columns_index(self): df = DataFrame(np.zeros((2, 2), dtype=int)) df.columns.name = 'columns.name' result = df.to_html() @@ -1995,6 +1996,7 @@ def test_to_html_index_name_single_index(self): """) assert result == expected + def test_to_html_single_index_named_index_index(self): df = DataFrame(np.zeros((2, 2), dtype=int)) df.index.name = 'index.name' result = df.to_html() @@ -2027,7 +2029,7 @@ def test_to_html_index_name_single_index(self): """) assert result == expected - def test_to_html_index_name_multi_index_column(self): + def test_to_html_multi_index_column_named_index_both(self): columns_multi_index = MultiIndex.from_product( [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) df = DataFrame(np.zeros((2, 2), dtype=int), @@ -2067,6 +2069,7 @@ def test_to_html_index_name_multi_index_column(self): """) assert result == expected + def test_to_html_multi_index_column_named_columns_index(self): columns_multi_index = MultiIndex.from_product( [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) df = DataFrame(np.zeros((2, 2), dtype=int), @@ -2100,6 +2103,7 @@ def test_to_html_index_name_multi_index_column(self): """) assert result == expected + def test_to_html_multi_index_column_named_index_index(self): multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) df.index.name = 'index.name' @@ -2137,8 +2141,7 @@ def test_to_html_index_name_multi_index_column(self): """) assert result == expected - def test_to_html_index_name_multi_index_index(self): - + def test_to_html_multi_index_index_named_index_both(self): index_multi_index = MultiIndex.from_product( [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) df = DataFrame(np.zeros((2, 2), dtype=int), index=index_multi_index) @@ -2176,6 +2179,7 @@ def test_to_html_index_name_multi_index_index(self): """) assert result == expected + def test_to_html_multi_index_index_named_columns_index(self): multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) df = DataFrame(np.zeros((2, 2), dtype=int), index=multi_index) df.columns.name = 'columns.name' @@ -2206,6 +2210,7 @@ def test_to_html_index_name_multi_index_index(self): """) assert result == expected + def test_to_html_multi_index_index_named_index_index(self): index_multi_index = MultiIndex.from_product( [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) df = DataFrame(np.zeros((2, 2), dtype=int), index=index_multi_index) @@ -2242,7 +2247,7 @@ def test_to_html_index_name_multi_index_index(self): """) assert result == expected - def test_to_html_index_name_multi_index_both(self): + def test_to_html_multi_index_both_named_index_both(self): index_multi_index = MultiIndex.from_product( [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) columns_multi_index = MultiIndex.from_product( @@ -2287,6 +2292,7 @@ def test_to_html_index_name_multi_index_both(self): """) assert result == expected + def test_to_html_multi_index_both_named_columns_index(self): multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) columns_multi_index = MultiIndex.from_product( [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) @@ -2324,6 +2330,7 @@ def test_to_html_index_name_multi_index_both(self): """) assert result == expected + def test_to_html_multi_index_both_named_index_index(self): multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) index_multi_index = MultiIndex.from_product( [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) @@ -2367,7 +2374,7 @@ def test_to_html_index_name_multi_index_both(self): """) assert result == expected - def test_to_html_index_name_multi_index_column_index_false(self): + def test_to_html_multi_index_column_index_false_named_index_both(self): columns_multi_index = MultiIndex.from_product( [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) df = DataFrame(np.zeros((2, 2), dtype=int), @@ -2402,10 +2409,10 @@ def test_to_html_index_name_multi_index_column_index_false(self): """) assert result == expected - # df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) - # df.columns.name = 'columns.name' - # result = df.to_html(index=False) + def test_to_html_multi_index_column_index_false_named_columns_index(self): + pass + def test_to_html_multi_index_column_index_false_named_index_index(self): multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) df.index.name = 'index.name' @@ -2434,18 +2441,14 @@ def test_to_html_index_name_multi_index_column_index_false(self): """) assert result == expected - def test_to_html_index_name_multi_index_index_index_false(self): - multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) - - # df = DataFrame(np.zeros((2, 2), dtype=int), index=multi_index) - # df.index.name = 'index.name' - # df.columns.name = 'columns.name' - # result = df.to_html(index=False) + def test_to_html_multi_index_index_index_false_named_index_both(self): + pass - # df = DataFrame(np.zeros((2, 2), dtype=int), index=multi_index) - # df.columns.name = 'columns.name' - # result = df.to_html(index=False) + def test_to_html_multi_index_index_index_false_named_columns_index(self): + pass + def test_to_html_multi_index_index_index_false_named_index_index(self): + multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) df = DataFrame(np.zeros((2, 2), dtype=int), index=multi_index) df.index.name = 'index.name' result = df.to_html(index=False) @@ -2470,22 +2473,13 @@ def test_to_html_index_name_multi_index_index_index_false(self): """) assert result == expected - def test_to_html_index_name_multi_index_both_index_false(self): - # multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) - - # df = DataFrame(np.zeros((2, 2), dtype=int), multi_index, multi_index) - # df.index.name = 'index.name' - # df.columns.name = 'columns.name' - # result = df.to_html(index=False) - - # df = DataFrame(np.zeros((2, 2), dtype=int), multi_index, multi_index) - # df.columns.name = 'columns.name' - # result = df.to_html(index=False) + def test_to_html_multi_index_both_index_false_named_index_both(self): + pass - # df = DataFrame(np.zeros((2, 2), dtype=int), multi_index, multi_index) - # df.index.name = 'index.name' - # result = df.to_html(index=False) + def test_to_html_multi_index_both_index_false_named_columns_index(self): + pass + def test_to_html_multi_index_both_index_false_named_index_index(self): pass def test_to_html_notebook_has_style(self): From 1b4c5dc79f7a590ea963a9b7ab0f8e5d0c818b73 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Sep 2018 23:19:34 +0100 Subject: [PATCH 22/94] fix failing test --- pandas/io/formats/html.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index fb348036628db..6ed9f7385e27d 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -201,6 +201,7 @@ def _write_header(self, indent): truncate_h = self.fmt.truncate_h row_levels = self.frame.index.nlevels + has_column_names = any(name for name in self.columns.names) self.write('', indent) @@ -263,7 +264,7 @@ def _write_header(self, indent): values = (values[:ins_col] + [u('...')] + values[ins_col:]) - if self.fmt.index: + if self.fmt.index or has_column_names: name = self.columns.names[lnum] row = [''] * (row_levels - 1) + ['' if name is None else pprint_thing(name)] @@ -323,6 +324,7 @@ def _write_body(self, indent): fmt_values[i] = self.fmt._format_col(i) # write values + has_column_names = any(name for name in self.columns.names) if self.fmt.index: if isinstance(self.frame.index, ABCMultiIndex): self._write_hierarchical_rows(fmt_values, indent) @@ -330,7 +332,12 @@ def _write_body(self, indent): self._write_regular_rows(fmt_values, indent) else: for i in range(min(len(self.frame), self.max_rows)): - row = [fmt_values[j][i] for j in range(len(self.columns))] + if has_column_names: + row = [''] + else: + row = [] + row = row + [fmt_values[j][i] + for j in range(len(self.columns))] self.write_tr(row, indent, self.indent_delta, tags=None) indent -= self.indent_delta From 82d57eb51d8a98ca456167e7a374630c7b0b1e84 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 00:02:10 +0100 Subject: [PATCH 23/94] add test (failing) --- pandas/tests/io/formats/test_to_html.py | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index e615e3115d630..ff9a79a01f8dc 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2409,6 +2409,37 @@ def test_to_html_multi_index_column_index_false_named_index_both(self): """) assert result == expected + def test_to_html_multi_idx_column_idx_f_named_idx_both_idx_names_f(self): + columns_multi_index = MultiIndex.from_product( + [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) + df = DataFrame(np.zeros((2, 2), dtype=int), + columns=columns_multi_index) + df.index.name = 'index.name' + result = df.to_html(index=False, index_names=False) + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + +
a
bc
00
00
""") + assert result == expected + def test_to_html_multi_index_column_index_false_named_columns_index(self): pass From cfa7570167dbaf8e08de74ca94e4e34509fc0a25 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 00:13:26 +0100 Subject: [PATCH 24/94] fix failing test --- pandas/io/formats/html.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 6ed9f7385e27d..693465300f621 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -202,6 +202,7 @@ def _write_header(self, indent): truncate_h = self.fmt.truncate_h row_levels = self.frame.index.nlevels has_column_names = any(name for name in self.columns.names) + show_index_names = self.fmt.show_index_names self.write('', indent) @@ -264,7 +265,8 @@ def _write_header(self, indent): values = (values[:ins_col] + [u('...')] + values[ins_col:]) - if self.fmt.index or has_column_names: + show_column_names = has_column_names and show_index_names + if self.fmt.index or show_column_names: name = self.columns.names[lnum] row = [''] * (row_levels - 1) + ['' if name is None else pprint_thing(name)] @@ -332,7 +334,7 @@ def _write_body(self, indent): self._write_regular_rows(fmt_values, indent) else: for i in range(min(len(self.frame), self.max_rows)): - if has_column_names: + if has_column_names and self.fmt.show_index_names: row = [''] else: row = [] From 9f884fb6c81ea78f14a27d523fc678f5a058d54c Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 00:22:22 +0100 Subject: [PATCH 25/94] refactor --- pandas/io/formats/html.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 693465300f621..fcc4d1fb7b557 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -201,7 +201,7 @@ def _write_header(self, indent): truncate_h = self.fmt.truncate_h row_levels = self.frame.index.nlevels - has_column_names = any(name for name in self.columns.names) + has_column_names = self.fmt.has_column_names show_index_names = self.fmt.show_index_names self.write('', indent) @@ -326,7 +326,7 @@ def _write_body(self, indent): fmt_values[i] = self.fmt._format_col(i) # write values - has_column_names = any(name for name in self.columns.names) + has_column_names = self.fmt.has_column_names if self.fmt.index: if isinstance(self.frame.index, ABCMultiIndex): self._write_hierarchical_rows(fmt_values, indent) From 25e81030bf48795b3d119e81cfa22db1ec5cf63a Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 00:31:07 +0100 Subject: [PATCH 26/94] add regression test (failing) --- pandas/tests/io/formats/test_to_html.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index ff9a79a01f8dc..c39823696262b 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2440,6 +2440,28 @@ def test_to_html_multi_idx_column_idx_f_named_idx_both_idx_names_f(self): """) assert result == expected + def test_to_html_multi_idx_column_idx_f_named_idx_both_header_f(self): + columns_multi_index = MultiIndex.from_product( + [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) + df = DataFrame(np.zeros((2, 2), dtype=int), + columns=columns_multi_index) + df.index.name = 'index.name' + result = df.to_html(index=False, header=False) + expected = dedent("""\ + + + + + + + + + + + +
00
00
""") + assert result == expected + def test_to_html_multi_index_column_index_false_named_columns_index(self): pass From d7ec7a3be3cd86cad58555d75bf67b6bd71cd915 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 01:50:59 +0100 Subject: [PATCH 27/94] fix failing test --- pandas/io/formats/html.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index fcc4d1fb7b557..04d9865ae27df 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -327,6 +327,7 @@ def _write_body(self, indent): # write values has_column_names = self.fmt.has_column_names + show_index_names = self.fmt.show_index_names if self.fmt.index: if isinstance(self.frame.index, ABCMultiIndex): self._write_hierarchical_rows(fmt_values, indent) @@ -334,7 +335,7 @@ def _write_body(self, indent): self._write_regular_rows(fmt_values, indent) else: for i in range(min(len(self.frame), self.max_rows)): - if has_column_names and self.fmt.show_index_names: + if has_column_names and show_index_names and self.fmt.header: row = [''] else: row = [] From 17f66ac306e72f291e2ed7c2d32ffa4442e77c52 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 02:04:57 +0100 Subject: [PATCH 28/94] add test --- pandas/tests/io/formats/test_to_html.py | 33 ++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index c39823696262b..0d7ac5185a95d 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2463,7 +2463,38 @@ def test_to_html_multi_idx_column_idx_f_named_idx_both_header_f(self): assert result == expected def test_to_html_multi_index_column_index_false_named_columns_index(self): - pass + columns_multi_index = MultiIndex.from_product( + [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) + df = DataFrame(np.zeros((2, 2), dtype=int), + columns=columns_multi_index) + result = df.to_html(index=False) + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
00
00
""") + assert result == expected def test_to_html_multi_index_column_index_false_named_index_index(self): multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) From 92d0c9a2c8abe91d8045b859ecba8cf4af700c8d Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 02:20:20 +0100 Subject: [PATCH 29/94] add test (failing) --- pandas/tests/io/formats/test_to_html.py | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 0d7ac5185a95d..5a48bf5e8bbb5 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2526,7 +2526,34 @@ def test_to_html_multi_index_column_index_false_named_index_index(self): assert result == expected def test_to_html_multi_index_index_index_false_named_index_both(self): - pass + index_multi_index = MultiIndex.from_product( + [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) + df = DataFrame(np.zeros((2, 2), dtype=int), index=index_multi_index) + df.columns.name = 'columns.name' + result = df.to_html(index=False) + expected = dedent("""\ + + + + + + + + + + + + + + + + + + + + +
columns.name01
00
00
""") + assert result == expected def test_to_html_multi_index_index_index_false_named_columns_index(self): pass From e6da59be4c6725eab92e0c7e4e54ae367fa2a5ef Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 10:05:38 +0100 Subject: [PATCH 30/94] revert html.py to upstream/master --- pandas/io/formats/html.py | 56 +++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 04d9865ae27df..a6b03c9c6dd23 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -195,14 +195,31 @@ def write_result(self, buf): buffer_put_lines(buf, self.elements) def _write_header(self, indent): + truncate_h = self.fmt.truncate_h + row_levels = self.frame.index.nlevels if not self.fmt.header: # write nothing return indent - truncate_h = self.fmt.truncate_h - row_levels = self.frame.index.nlevels - has_column_names = self.fmt.has_column_names - show_index_names = self.fmt.show_index_names + def _column_header(): + if self.fmt.index: + row = [''] * (self.frame.index.nlevels - 1) + else: + row = [] + + if isinstance(self.columns, ABCMultiIndex): + if self.fmt.has_column_names and self.fmt.index: + row.append(single_column_table(self.columns.names)) + else: + row.append('') + style = "text-align: {just};".format(just=self.fmt.justify) + row.extend([single_column_table(c, self.fmt.justify, style) + for c in self.columns]) + else: + if self.fmt.index: + row.append(self.columns.name or '') + row.extend(self.columns) + return row self.write('', indent) @@ -265,12 +282,11 @@ def _write_header(self, indent): values = (values[:ins_col] + [u('...')] + values[ins_col:]) - show_column_names = has_column_names and show_index_names - if self.fmt.index or show_column_names: - name = self.columns.names[lnum] - row = [''] * (row_levels - 1) + ['' if name is None else - pprint_thing(name)] - else: + name = self.columns.names[lnum] + row = [''] * (row_levels - 1) + ['' if name is None else + pprint_thing(name)] + + if row == [""] and self.fmt.index is False: row = [] tags = {} @@ -286,19 +302,14 @@ def _write_header(self, indent): self.write_tr(row, indent, self.indent_delta, tags=tags, header=True) else: - if self.fmt.index: - row = [''] * (row_levels - 1) + [self.columns.name or ''] - else: - row = [] - row.extend(self.columns) - + col_row = _column_header() align = self.fmt.justify if truncate_h: ins_col = row_levels + self.fmt.tr_col_num - row.insert(ins_col, '...') + col_row.insert(ins_col, '...') - self.write_tr(row, indent, self.indent_delta, header=True, + self.write_tr(col_row, indent, self.indent_delta, header=True, align=align) if all((self.fmt.has_index_names, @@ -326,8 +337,6 @@ def _write_body(self, indent): fmt_values[i] = self.fmt._format_col(i) # write values - has_column_names = self.fmt.has_column_names - show_index_names = self.fmt.show_index_names if self.fmt.index: if isinstance(self.frame.index, ABCMultiIndex): self._write_hierarchical_rows(fmt_values, indent) @@ -335,12 +344,7 @@ def _write_body(self, indent): self._write_regular_rows(fmt_values, indent) else: for i in range(min(len(self.frame), self.max_rows)): - if has_column_names and show_index_names and self.fmt.header: - row = [''] - else: - row = [] - row = row + [fmt_values[j][i] - for j in range(len(self.columns))] + row = [fmt_values[j][i] for j in range(len(self.columns))] self.write_tr(row, indent, self.indent_delta, tags=None) indent -= self.indent_delta From 96b181e7fa2056f2c4f63f89e574dfda11890a04 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 10:32:22 +0100 Subject: [PATCH 31/94] re-apply minimal code changes --- pandas/io/formats/html.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index a6b03c9c6dd23..ae3e97b496da8 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -201,6 +201,9 @@ def _write_header(self, indent): # write nothing return indent + has_column_names = self.fmt.has_column_names + show_index_names = self.fmt.show_index_names + def _column_header(): if self.fmt.index: row = [''] * (self.frame.index.nlevels - 1) @@ -282,11 +285,12 @@ def _column_header(): values = (values[:ins_col] + [u('...')] + values[ins_col:]) - name = self.columns.names[lnum] - row = [''] * (row_levels - 1) + ['' if name is None else - pprint_thing(name)] - - if row == [""] and self.fmt.index is False: + show_column_names = has_column_names and show_index_names + if self.fmt.index or show_column_names: + name = self.columns.names[lnum] + row = [''] * (row_levels - 1) + ['' if name is None else + pprint_thing(name)] + else: row = [] tags = {} @@ -337,6 +341,8 @@ def _write_body(self, indent): fmt_values[i] = self.fmt._format_col(i) # write values + has_column_names = self.fmt.has_column_names + show_index_names = self.fmt.show_index_names if self.fmt.index: if isinstance(self.frame.index, ABCMultiIndex): self._write_hierarchical_rows(fmt_values, indent) @@ -344,7 +350,12 @@ def _write_body(self, indent): self._write_regular_rows(fmt_values, indent) else: for i in range(min(len(self.frame), self.max_rows)): - row = [fmt_values[j][i] for j in range(len(self.columns))] + if has_column_names and show_index_names and self.fmt.header: + row = [''] + else: + row = [] + row = row + [fmt_values[j][i] + for j in range(len(self.columns))] self.write_tr(row, indent, self.indent_delta, tags=None) indent -= self.indent_delta From e737cd639b7d4fbab0045be6153ce9d06d9770b9 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 10:52:31 +0100 Subject: [PATCH 32/94] minimise changes further --- pandas/io/formats/html.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index ae3e97b496da8..247fc01eea745 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -285,12 +285,12 @@ def _column_header(): values = (values[:ins_col] + [u('...')] + values[ins_col:]) + name = self.columns.names[lnum] + row = [''] * (row_levels - 1) + ['' if name is None else + pprint_thing(name)] + show_column_names = has_column_names and show_index_names - if self.fmt.index or show_column_names: - name = self.columns.names[lnum] - row = [''] * (row_levels - 1) + ['' if name is None else - pprint_thing(name)] - else: + if not (show_column_names or self.fmt.index): row = [] tags = {} From 9dbb6edda4ccd4853e99cc5f8b21b51c0feb9f60 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 11:08:34 +0100 Subject: [PATCH 33/94] refactor --- pandas/io/formats/html.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 247fc01eea745..f52ee4c9ea949 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -201,8 +201,8 @@ def _write_header(self, indent): # write nothing return indent - has_column_names = self.fmt.has_column_names - show_index_names = self.fmt.show_index_names + show_column_names = (self.fmt.has_column_names and + self.fmt.show_index_names) def _column_header(): if self.fmt.index: @@ -289,7 +289,6 @@ def _column_header(): row = [''] * (row_levels - 1) + ['' if name is None else pprint_thing(name)] - show_column_names = has_column_names and show_index_names if not (show_column_names or self.fmt.index): row = [] @@ -341,8 +340,9 @@ def _write_body(self, indent): fmt_values[i] = self.fmt._format_col(i) # write values - has_column_names = self.fmt.has_column_names - show_index_names = self.fmt.show_index_names + show_column_names = (self.fmt.has_column_names and + self.fmt.show_index_names and self.fmt.header) + if self.fmt.index: if isinstance(self.frame.index, ABCMultiIndex): self._write_hierarchical_rows(fmt_values, indent) @@ -350,7 +350,7 @@ def _write_body(self, indent): self._write_regular_rows(fmt_values, indent) else: for i in range(min(len(self.frame), self.max_rows)): - if has_column_names and show_index_names and self.fmt.header: + if show_column_names: row = [''] else: row = [] From 130873f8f3f06ff56d4ba71eb6b4ebf93db88827 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 12:23:33 +0100 Subject: [PATCH 34/94] refactor --- pandas/io/formats/html.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index f52ee4c9ea949..bcdb3d2446ea9 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -47,6 +47,9 @@ def __init__(self, formatter, classes=None, max_rows=None, max_cols=None, border = get_option('display.html.border') self.border = border self.table_id = table_id + self.show_col_idx_names = (self.fmt.has_column_names and + self.fmt.show_index_names and + self.fmt.header) def write(self, s, indent=0): rs = pprint_thing(s) @@ -201,9 +204,6 @@ def _write_header(self, indent): # write nothing return indent - show_column_names = (self.fmt.has_column_names and - self.fmt.show_index_names) - def _column_header(): if self.fmt.index: row = [''] * (self.frame.index.nlevels - 1) @@ -289,7 +289,7 @@ def _column_header(): row = [''] * (row_levels - 1) + ['' if name is None else pprint_thing(name)] - if not (show_column_names or self.fmt.index): + if not (self.show_col_idx_names or self.fmt.index): row = [] tags = {} @@ -340,9 +340,6 @@ def _write_body(self, indent): fmt_values[i] = self.fmt._format_col(i) # write values - show_column_names = (self.fmt.has_column_names and - self.fmt.show_index_names and self.fmt.header) - if self.fmt.index: if isinstance(self.frame.index, ABCMultiIndex): self._write_hierarchical_rows(fmt_values, indent) @@ -350,7 +347,7 @@ def _write_body(self, indent): self._write_regular_rows(fmt_values, indent) else: for i in range(min(len(self.frame), self.max_rows)): - if show_column_names: + if self.show_col_idx_names: row = [''] else: row = [] From fc8851dca4ff04b6961adc9d3c39076130748dbb Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 13:00:52 +0100 Subject: [PATCH 35/94] fix failing test --- pandas/io/formats/html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index bcdb3d2446ea9..04a9e6c479572 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -219,7 +219,7 @@ def _column_header(): row.extend([single_column_table(c, self.fmt.justify, style) for c in self.columns]) else: - if self.fmt.index: + if self.fmt.index or self.show_col_idx_names: row.append(self.columns.name or '') row.extend(self.columns) return row From 2ace532e362d0bccddb1c901b3f9b5fd106c4798 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 13:12:41 +0100 Subject: [PATCH 36/94] refactor --- pandas/io/formats/html.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 04a9e6c479572..fbece85a553a9 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -346,13 +346,10 @@ def _write_body(self, indent): else: self._write_regular_rows(fmt_values, indent) else: + row_init = [''] if self.show_col_idx_names else [] for i in range(min(len(self.frame), self.max_rows)): - if self.show_col_idx_names: - row = [''] - else: - row = [] - row = row + [fmt_values[j][i] - for j in range(len(self.columns))] + row = row_init + [fmt_values[j][i] + for j in range(len(self.columns))] self.write_tr(row, indent, self.indent_delta, tags=None) indent -= self.indent_delta From 49177d72d1419530941d250c48b6975ab95388c5 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 14:19:50 +0100 Subject: [PATCH 37/94] fix pep8 --- pandas/io/formats/html.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index fbece85a553a9..d7a20fc5063c8 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -47,9 +47,9 @@ def __init__(self, formatter, classes=None, max_rows=None, max_cols=None, border = get_option('display.html.border') self.border = border self.table_id = table_id - self.show_col_idx_names = (self.fmt.has_column_names and - self.fmt.show_index_names and - self.fmt.header) + self.show_col_idx_names = all((self.fmt.has_column_names, + self.fmt.show_index_names, + self.fmt.header)) def write(self, s, indent=0): rs = pprint_thing(s) From 5cbb8c545c8c44e6611f0cbca75bb0cf7d2c4afb Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 15:42:47 +0100 Subject: [PATCH 38/94] refactor --- pandas/io/formats/html.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index d7a20fc5063c8..76dde9727906b 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -346,10 +346,10 @@ def _write_body(self, indent): else: self._write_regular_rows(fmt_values, indent) else: - row_init = [''] if self.show_col_idx_names else [] for i in range(min(len(self.frame), self.max_rows)): - row = row_init + [fmt_values[j][i] - for j in range(len(self.columns))] + row = [fmt_values[j][i] for j in range(len(self.columns))] + if self.show_col_idx_names: + row.insert(0, '') self.write_tr(row, indent, self.indent_delta, tags=None) indent -= self.indent_delta From 1db45f28c53cce868601a8a34cf1525e8c7d2807 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 20:28:24 +0100 Subject: [PATCH 39/94] WIP parametrize tests --- pandas/tests/io/formats/test_to_html.py | 119 +++++++++++------------- 1 file changed, 56 insertions(+), 63 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 5a48bf5e8bbb5..b15c6a3010bc4 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -1934,12 +1934,11 @@ def test_to_html_multi_indices_index_false(self): """) assert result == expected - def test_to_html_single_index_named_index_both(self): - df = DataFrame(np.zeros((2, 2), dtype=int)) - df.index.name = 'index.name' - df.columns.name = 'columns.name' - result = df.to_html() - expected = dedent("""\ + @pytest.mark.parametrize("""index_multi_index, columns_multi_index, + named_index, named_columns, index, header, index_names, expected""", [ + (False, False, True, True, True, True, True,\ + # test_to_html_single_index_named_index_both + """\ @@ -1965,14 +1964,10 @@ def test_to_html_single_index_named_index_both(self): -
0
""") - assert result == expected - - def test_to_html_single_index_named_columns_index(self): - df = DataFrame(np.zeros((2, 2), dtype=int)) - df.columns.name = 'columns.name' - result = df.to_html() - expected = dedent("""\ + """), + (False, False, False, True, True, True, True,\ + # test_to_html_single_index_named_columns_index + """\ @@ -1993,14 +1988,10 @@ def test_to_html_single_index_named_columns_index(self): -
0
""") - assert result == expected - - def test_to_html_single_index_named_index_index(self): - df = DataFrame(np.zeros((2, 2), dtype=int)) - df.index.name = 'index.name' - result = df.to_html() - expected = dedent("""\ + """), + (False, False, True, False, True, True, True,\ + # test_to_html_single_index_named_index_index + """\ @@ -2026,17 +2017,10 @@ def test_to_html_single_index_named_index_index(self): -
0
""") - assert result == expected - - def test_to_html_multi_index_column_named_index_both(self): - columns_multi_index = MultiIndex.from_product( - [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) - df = DataFrame(np.zeros((2, 2), dtype=int), - columns=columns_multi_index) - df.index.name = 'index.name' - result = df.to_html() - expected = dedent("""\ + """), + (False, True, True, True, True, True, True,\ + # test_to_html_multi_index_column_named_index_both + """\ @@ -2066,16 +2050,10 @@ def test_to_html_multi_index_column_named_index_both(self): -
0
""") - assert result == expected - - def test_to_html_multi_index_column_named_columns_index(self): - columns_multi_index = MultiIndex.from_product( - [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) - df = DataFrame(np.zeros((2, 2), dtype=int), - columns=columns_multi_index) - result = df.to_html() - expected = dedent("""\ + """), + (False, True, False, True, True, True, True,\ + # test_to_html_multi_index_column_named_columns_index + """\ @@ -2100,15 +2078,10 @@ def test_to_html_multi_index_column_named_columns_index(self): -
0
""") - assert result == expected - - def test_to_html_multi_index_column_named_index_index(self): - multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) - df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) - df.index.name = 'index.name' - result = df.to_html() - expected = dedent("""\ + """), + (False, True, True, False, True, True, True,\ + # test_to_html_multi_index_column_named_index_index + """\ @@ -2138,16 +2111,10 @@ def test_to_html_multi_index_column_named_index_index(self): -
0
""") - assert result == expected - - def test_to_html_multi_index_index_named_index_both(self): - index_multi_index = MultiIndex.from_product( - [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) - df = DataFrame(np.zeros((2, 2), dtype=int), index=index_multi_index) - df.columns.name = 'columns.name' - result = df.to_html() - expected = dedent("""\ + """), + (True, False, True, True, True, True, True,\ + # test_to_html_multi_index_index_named_index_both + """\ @@ -2177,7 +2144,33 @@ def test_to_html_multi_index_index_named_index_both(self):
""") - assert result == expected + ]) + def test_to_html_index_names(self, index_multi_index, columns_multi_index, + named_index, named_columns, index, header, + index_names, expected): + + df = DataFrame(np.zeros((2, 2), dtype=int)) + + if index_multi_index: + df.index = MultiIndex.from_product([['a'], ['b', 'c']]) + if named_index: + if index_multi_index: + df.index.rename( + ['index.name.0', 'index.name.1'], inplace=True) + else: + df.index.name = 'index.name' + + if columns_multi_index: + df.columns = MultiIndex.from_product([['a'], ['b', 'c']]) + if named_columns: + if columns_multi_index: + df.columns.rename( + ['columns.name.0', 'columns.name.1'], inplace=True) + else: + df.columns.name = 'columns.name' + + result = df.to_html() + assert result == dedent(expected) def test_to_html_multi_index_index_named_columns_index(self): multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) From cf883d9961ede243797f3db6582a61b93c8238bd Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 21:32:10 +0100 Subject: [PATCH 40/94] WIP parametrize tests --- pandas/tests/io/formats/test_to_html.py | 449 +++++++++++++----------- 1 file changed, 239 insertions(+), 210 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index b15c6a3010bc4..984eecda0de30 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -22,6 +22,228 @@ pass +@pytest.fixture +def index_named_single_columns_named_single(): + return """\ + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name01
index.name
000
100
""" + + +@pytest.fixture +def index_unnamed_single_columns_named_single(): + return """\ + + + + + + + + + + + + + + + + + + + + +
columns.name01
000
100
""" + + +@pytest.fixture +def index_named_single_columns_unnamed_single(): + return """\ + + + + + + + + + + + + + + + + + + + + + + + + + +
01
index.name
000
100
""" + + +@pytest.fixture +def index_named_single_columns_named_multi(): + return """\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
index.name
000
100
""" + + +@pytest.fixture +def index_unnamed_single_columns_named_multi(): + return """\ + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
000
100
""" + + +@pytest.fixture +def index_named_single_columns_unnamed_multi(): + return """\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
a
bc
index.name
000
100
""" + + +@pytest.fixture +def index_named_multi_columns_named_multi(): + return """\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name01
index.name.0index.name.1
ab00
c00
""" + + class TestToHTML(object): def test_to_html_with_col_space(self): @@ -1936,214 +2158,20 @@ def test_to_html_multi_indices_index_false(self): @pytest.mark.parametrize("""index_multi_index, columns_multi_index, named_index, named_columns, index, header, index_names, expected""", [ - (False, False, True, True, True, True, True,\ - # test_to_html_single_index_named_index_both - """\ - - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name01
index.name
000
100
"""), - (False, False, False, True, True, True, True,\ - # test_to_html_single_index_named_columns_index - """\ - - - - - - - - - - - - - - - - - - - - -
columns.name01
000
100
"""), - (False, False, True, False, True, True, True,\ - # test_to_html_single_index_named_index_index - """\ - - - - - - - - - - - - - - - - - - - - - - - - - -
01
index.name
000
100
"""), - (False, True, True, True, True, True, True,\ - # test_to_html_multi_index_column_named_index_both - """\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name.0a
columns.name.1bc
index.name
000
100
"""), - (False, True, False, True, True, True, True,\ - # test_to_html_multi_index_column_named_columns_index - """\ - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name.0a
columns.name.1bc
000
100
"""), - (False, True, True, False, True, True, True,\ - # test_to_html_multi_index_column_named_index_index - """\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
a
bc
index.name
000
100
"""), - (True, False, True, True, True, True, True,\ - # test_to_html_multi_index_index_named_index_both - """\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name01
index.name.0index.name.1
ab00
c00
""") + (False, False, True, True, True, True, True, + index_named_single_columns_named_single), + (False, False, False, True, True, True, True, + index_unnamed_single_columns_named_single), + (False, False, True, False, True, True, True, + index_named_single_columns_unnamed_single), + (False, True, True, True, True, True, True, + index_named_single_columns_named_multi), + (False, True, False, True, True, True, True, + index_unnamed_single_columns_named_multi), + (False, True, True, False, True, True, True, + index_named_single_columns_unnamed_multi), + (True, False, True, True, True, True, True, + index_named_multi_columns_named_multi) ]) def test_to_html_index_names(self, index_multi_index, columns_multi_index, named_index, named_columns, index, header, @@ -2169,8 +2197,9 @@ def test_to_html_index_names(self, index_multi_index, columns_multi_index, else: df.columns.name = 'columns.name' - result = df.to_html() - assert result == dedent(expected) + result = df.to_html(index=index, header=header, + index_names=index_names) + assert result == dedent(expected()) def test_to_html_multi_index_index_named_columns_index(self): multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) From 3842c527503973a221fc42f2f363debe220fcafd Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 21:35:43 +0100 Subject: [PATCH 41/94] fix typo --- pandas/tests/io/formats/test_to_html.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 984eecda0de30..ff83c9fda20d5 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -211,7 +211,7 @@ def index_named_single_columns_unnamed_multi(): @pytest.fixture -def index_named_multi_columns_named_multi(): +def index_named_multi_columns_named_single(): return """\ @@ -2171,7 +2171,7 @@ def test_to_html_multi_indices_index_false(self): (False, True, True, False, True, True, True, index_named_single_columns_unnamed_multi), (True, False, True, True, True, True, True, - index_named_multi_columns_named_multi) + index_named_multi_columns_named_single) ]) def test_to_html_index_names(self, index_multi_index, columns_multi_index, named_index, named_columns, index, header, From 8722603bb4752926c99eb7aa8bbaacaea30474bf Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 22:31:53 +0100 Subject: [PATCH 42/94] refactor test --- pandas/tests/io/formats/test_to_html.py | 57 ++++++++++++++----------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index ff83c9fda20d5..5b51bd55e2f64 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2156,46 +2156,51 @@ def test_to_html_multi_indices_index_false(self):
""") assert result == expected - @pytest.mark.parametrize("""index_multi_index, columns_multi_index, - named_index, named_columns, index, header, index_names, expected""", [ - (False, False, True, True, True, True, True, + @pytest.mark.parametrize("""idx_type, col_idx_type, index, header, + index_names, expected""", [ + ('named_single', 'named_single', True, True, True, index_named_single_columns_named_single), - (False, False, False, True, True, True, True, + ('unnamed_single', 'named_single', True, True, True, index_unnamed_single_columns_named_single), - (False, False, True, False, True, True, True, + ('named_single', 'unnamed_single', True, True, True, index_named_single_columns_unnamed_single), - (False, True, True, True, True, True, True, + ('named_single', 'named_multi', True, True, True, index_named_single_columns_named_multi), - (False, True, False, True, True, True, True, + ('unnamed_single', 'named_multi', True, True, True, index_unnamed_single_columns_named_multi), - (False, True, True, False, True, True, True, + ('named_single', 'unnamed_multi', True, True, True, index_named_single_columns_unnamed_multi), - (True, False, True, True, True, True, True, + ('named_multi', 'named_single', True, True, True, index_named_multi_columns_named_single) ]) - def test_to_html_index_names(self, index_multi_index, columns_multi_index, - named_index, named_columns, index, header, + def test_to_html_index_names(self, idx_type, col_idx_type, index, header, index_names, expected): df = DataFrame(np.zeros((2, 2), dtype=int)) - if index_multi_index: + if idx_type == 'named_single': + df.index.name = 'index.name' + elif idx_type == 'unnamed_single': + pass + elif idx_type == 'named_multi': + df.index = MultiIndex.from_product([['a'], ['b', 'c']], names=[ + 'index.name.0', 'index.name.1']) + elif idx_type == 'unnamed_multi': df.index = MultiIndex.from_product([['a'], ['b', 'c']]) - if named_index: - if index_multi_index: - df.index.rename( - ['index.name.0', 'index.name.1'], inplace=True) - else: - df.index.name = 'index.name' - - if columns_multi_index: + else: + raise ValueError + + if col_idx_type == 'named_single': + df.columns.name = 'columns.name' + elif col_idx_type == 'unnamed_single': + pass + elif col_idx_type == 'named_multi': + df.columns = MultiIndex.from_product([['a'], ['b', 'c']], names=[ + 'columns.name.0', 'columns.name.1']) + elif col_idx_type == 'unnamed_multi': df.columns = MultiIndex.from_product([['a'], ['b', 'c']]) - if named_columns: - if columns_multi_index: - df.columns.rename( - ['columns.name.0', 'columns.name.1'], inplace=True) - else: - df.columns.name = 'columns.name' + else: + raise ValueError result = df.to_html(index=index, header=header, index_names=index_names) From d7c2e20364cb0df9fbf548592d717cde1bea9f73 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 23:27:42 +0100 Subject: [PATCH 43/94] WIP parametrize tests --- pandas/tests/io/formats/test_to_html.py | 222 ++++++++++++------------ 1 file changed, 108 insertions(+), 114 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 5b51bd55e2f64..86268cade4853 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -244,6 +244,107 @@ def index_named_multi_columns_named_single(): """ +@pytest.fixture +def index_unnamed_multi_columns_named_single(): + return """\ + + + + + + + + + + + + + + + + + + + + + + +
columns.name01
ab00
c00
""" + + +@pytest.fixture +def index_named_multi_columns_unnamed_single(): + return """\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
01
index.name.0index.name.1
ab00
c00
""" + + +@pytest.fixture +def index_named_multi_columns_named_multi(): + return """\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
index.name.0index.name.1
ab00
c00
""" + + class TestToHTML(object): def test_to_html_with_col_space(self): @@ -2171,7 +2272,13 @@ def test_to_html_multi_indices_index_false(self): ('named_single', 'unnamed_multi', True, True, True, index_named_single_columns_unnamed_multi), ('named_multi', 'named_single', True, True, True, - index_named_multi_columns_named_single) + index_named_multi_columns_named_single), + ('unnamed_multi', 'named_single', True, True, True, + index_unnamed_multi_columns_named_single), + ('named_multi', 'unnamed_single', True, True, True, + index_named_multi_columns_unnamed_single), + ('named_multi', 'named_multi', True, True, True, + index_named_multi_columns_named_multi) ]) def test_to_html_index_names(self, idx_type, col_idx_type, index, header, index_names, expected): @@ -2206,119 +2313,6 @@ def test_to_html_index_names(self, idx_type, col_idx_type, index, header, index_names=index_names) assert result == dedent(expected()) - def test_to_html_multi_index_index_named_columns_index(self): - multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) - df = DataFrame(np.zeros((2, 2), dtype=int), index=multi_index) - df.columns.name = 'columns.name' - result = df.to_html() - expected = dedent("""\ - - - - - - - - - - - - - - - - - - - - - - -
columns.name01
ab00
c00
""") - assert result == expected - - def test_to_html_multi_index_index_named_index_index(self): - index_multi_index = MultiIndex.from_product( - [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) - df = DataFrame(np.zeros((2, 2), dtype=int), index=index_multi_index) - result = df.to_html() - expected = dedent("""\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
01
index.name.0index.name.1
ab00
c00
""") - assert result == expected - - def test_to_html_multi_index_both_named_index_both(self): - index_multi_index = MultiIndex.from_product( - [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) - columns_multi_index = MultiIndex.from_product( - [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) - df = DataFrame(np.zeros((2, 2), dtype=int), - index=index_multi_index, columns=columns_multi_index) - result = df.to_html() - expected = dedent("""\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name.0a
columns.name.1bc
index.name.0index.name.1
ab00
c00
""") - assert result == expected - def test_to_html_multi_index_both_named_columns_index(self): multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) columns_multi_index = MultiIndex.from_product( From 2aed4ec267a6cd0025f201790411a7ac18a2a663 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 11 Sep 2018 23:54:03 +0100 Subject: [PATCH 44/94] WIP parametrize tests --- pandas/tests/io/formats/test_to_html.py | 227 ++++++++++++------------ 1 file changed, 109 insertions(+), 118 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 86268cade4853..770305ad36fac 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -345,6 +345,108 @@ def index_named_multi_columns_named_multi(): """ +@pytest.fixture +def index_unnamed_multi_columns_named_multi(): + return """\ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
ab00
c00
""" + + +@pytest.fixture +def index_named_multi_columns_unnamed_multi(): + return """\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
a
bc
index.name.0index.name.1
ab00
c00
""" + + +@pytest.fixture +def index_none_columns_named_multi(): + return """\ + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
00
00
""" + + class TestToHTML(object): def test_to_html_with_col_space(self): @@ -2278,7 +2380,13 @@ def test_to_html_multi_indices_index_false(self): ('named_multi', 'unnamed_single', True, True, True, index_named_multi_columns_unnamed_single), ('named_multi', 'named_multi', True, True, True, - index_named_multi_columns_named_multi) + index_named_multi_columns_named_multi), + ('unnamed_multi', 'named_multi', True, True, True, + index_unnamed_multi_columns_named_multi), + ('named_multi', 'unnamed_multi', True, True, True, + index_named_multi_columns_unnamed_multi), + ('named_single', 'named_multi', False, True, True, + index_none_columns_named_multi) ]) def test_to_html_index_names(self, idx_type, col_idx_type, index, header, index_names, expected): @@ -2313,123 +2421,6 @@ def test_to_html_index_names(self, idx_type, col_idx_type, index, header, index_names=index_names) assert result == dedent(expected()) - def test_to_html_multi_index_both_named_columns_index(self): - multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) - columns_multi_index = MultiIndex.from_product( - [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) - df = DataFrame(np.zeros((2, 2), dtype=int), - index=multi_index, columns=columns_multi_index) - result = df.to_html() - expected = dedent("""\ - - - - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name.0a
columns.name.1bc
ab00
c00
""") - assert result == expected - - def test_to_html_multi_index_both_named_index_index(self): - multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) - index_multi_index = MultiIndex.from_product( - [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) - df = DataFrame(np.zeros((2, 2), dtype=int), - index=index_multi_index, columns=multi_index) - result = df.to_html() - expected = dedent("""\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
a
bc
index.name.0index.name.1
ab00
c00
""") - assert result == expected - - def test_to_html_multi_index_column_index_false_named_index_both(self): - columns_multi_index = MultiIndex.from_product( - [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) - df = DataFrame(np.zeros((2, 2), dtype=int), - columns=columns_multi_index) - df.index.name = 'index.name' - result = df.to_html(index=False) - expected = dedent("""\ - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name.0a
columns.name.1bc
00
00
""") - assert result == expected - def test_to_html_multi_idx_column_idx_f_named_idx_both_idx_names_f(self): columns_multi_index = MultiIndex.from_product( [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) From f8191f0141239ded1d81e110e93b994ce0392c46 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 12 Sep 2018 01:12:02 +0100 Subject: [PATCH 45/94] WIP parametrize tests --- pandas/tests/io/formats/test_to_html.py | 333 ++++++++++-------------- 1 file changed, 132 insertions(+), 201 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 770305ad36fac..f94ce3b2017b1 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -420,31 +420,123 @@ def index_named_multi_columns_unnamed_multi(): @pytest.fixture def index_none_columns_named_multi(): return """\ - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name.0a
columns.name.1bc
00
00
""" + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
00
00
""" + + +@pytest.fixture +def index_none_columns_unnamed_multi(): + return """\ + + + + + + + + + + + + + + + + + + + + +
a
bc
00
00
""" + + +@pytest.fixture +def index_none_columns_none(): + return """\ + + + + + + + + + + + +
00
00
""" + + +@pytest.fixture +def index_none_columns_named_single(): + return """\ + + + + + + + + + + + + + + + + + + + + +
columns.name01
00
00
""" + + +@pytest.fixture +def index_none_columns_unnamed_single(): + return """\ + + + + + + + + + + + + + + + + + +
01
00
00
""" class TestToHTML(object): @@ -2386,7 +2478,21 @@ def test_to_html_multi_indices_index_false(self): ('named_multi', 'unnamed_multi', True, True, True, index_named_multi_columns_unnamed_multi), ('named_single', 'named_multi', False, True, True, - index_none_columns_named_multi) + index_none_columns_named_multi), + ('named_single', 'named_multi', False, True, False, + index_none_columns_unnamed_multi), + ('named_single', 'named_multi', False, False, True, + index_none_columns_none), + ('unnamed_single', 'named_multi', False, True, True, + index_none_columns_named_multi), + ('named_single', 'unnamed_multi', False, True, True, + index_none_columns_unnamed_multi), + ('named_multi', 'named_single', False, True, True, + index_none_columns_named_single), + ('unnamed_multi', 'named_single', False, True, True, + index_none_columns_named_single), + ('named_multi', 'unnamed_single', False, True, True, + index_none_columns_unnamed_single) ]) def test_to_html_index_names(self, idx_type, col_idx_type, index, header, index_names, expected): @@ -2421,181 +2527,6 @@ def test_to_html_index_names(self, idx_type, col_idx_type, index, header, index_names=index_names) assert result == dedent(expected()) - def test_to_html_multi_idx_column_idx_f_named_idx_both_idx_names_f(self): - columns_multi_index = MultiIndex.from_product( - [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) - df = DataFrame(np.zeros((2, 2), dtype=int), - columns=columns_multi_index) - df.index.name = 'index.name' - result = df.to_html(index=False, index_names=False) - expected = dedent("""\ - - - - - - - - - - - - - - - - - - - - -
a
bc
00
00
""") - assert result == expected - - def test_to_html_multi_idx_column_idx_f_named_idx_both_header_f(self): - columns_multi_index = MultiIndex.from_product( - [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) - df = DataFrame(np.zeros((2, 2), dtype=int), - columns=columns_multi_index) - df.index.name = 'index.name' - result = df.to_html(index=False, header=False) - expected = dedent("""\ - - - - - - - - - - - -
00
00
""") - assert result == expected - - def test_to_html_multi_index_column_index_false_named_columns_index(self): - columns_multi_index = MultiIndex.from_product( - [['a'], ['b', 'c']], names=['columns.name.0', 'columns.name.1']) - df = DataFrame(np.zeros((2, 2), dtype=int), - columns=columns_multi_index) - result = df.to_html(index=False) - expected = dedent("""\ - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name.0a
columns.name.1bc
00
00
""") - assert result == expected - - def test_to_html_multi_index_column_index_false_named_index_index(self): - multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) - df = DataFrame(np.zeros((2, 2), dtype=int), columns=multi_index) - df.index.name = 'index.name' - result = df.to_html(index=False) - expected = dedent("""\ - - - - - - - - - - - - - - - - - - - - -
a
bc
00
00
""") - assert result == expected - - def test_to_html_multi_index_index_index_false_named_index_both(self): - index_multi_index = MultiIndex.from_product( - [['a'], ['b', 'c']], names=['index.name.0', 'index.name.1']) - df = DataFrame(np.zeros((2, 2), dtype=int), index=index_multi_index) - df.columns.name = 'columns.name' - result = df.to_html(index=False) - expected = dedent("""\ - - - - - - - - - - - - - - - - - - - - -
columns.name01
00
00
""") - assert result == expected - - def test_to_html_multi_index_index_index_false_named_columns_index(self): - pass - - def test_to_html_multi_index_index_index_false_named_index_index(self): - multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) - df = DataFrame(np.zeros((2, 2), dtype=int), index=multi_index) - df.index.name = 'index.name' - result = df.to_html(index=False) - expected = dedent("""\ - - - - - - - - - - - - - - - - - -
01
00
00
""") - assert result == expected - def test_to_html_multi_index_both_index_false_named_index_both(self): pass From c21f7cd2c191b937f8c5592ef0aa2cff1a5d702c Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 12 Sep 2018 01:29:58 +0100 Subject: [PATCH 46/94] add test (failing) --- pandas/tests/io/formats/test_to_html.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index f94ce3b2017b1..a0baa00b2782c 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2492,7 +2492,13 @@ def test_to_html_multi_indices_index_false(self): ('unnamed_multi', 'named_single', False, True, True, index_none_columns_named_single), ('named_multi', 'unnamed_single', False, True, True, - index_none_columns_unnamed_single) + index_none_columns_unnamed_single), + ('named_multi', 'named_multi', False, True, True, + index_none_columns_named_multi), + # ('unnamed_multi', 'named_multi', False, True, True, + # index_none_columns_named_multi), + ('named_multi', 'unnamed_multi', False, True, True, + index_none_columns_unnamed_multi) ]) def test_to_html_index_names(self, idx_type, col_idx_type, index, header, index_names, expected): @@ -2527,15 +2533,6 @@ def test_to_html_index_names(self, idx_type, col_idx_type, index, header, index_names=index_names) assert result == dedent(expected()) - def test_to_html_multi_index_both_index_false_named_index_both(self): - pass - - def test_to_html_multi_index_both_index_false_named_columns_index(self): - pass - - def test_to_html_multi_index_both_index_false_named_index_index(self): - pass - def test_to_html_notebook_has_style(self): df = pd.DataFrame({"A": [1, 2, 3]}) result = df.to_html(notebook=True) From 3263cc14b17072bb0f32e00a4873fc3e71928f01 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 13 Sep 2018 01:09:52 +0100 Subject: [PATCH 47/94] fix failing test --- pandas/io/formats/html.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 76dde9727906b..e70651375c4af 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -288,9 +288,11 @@ def _column_header(): name = self.columns.names[lnum] row = [''] * (row_levels - 1) + ['' if name is None else pprint_thing(name)] - - if not (self.show_col_idx_names or self.fmt.index): - row = [] + if not self.fmt.index: + if self.show_col_idx_names: + row = [row[-1]] + else: + row = [] tags = {} j = len(row) From 528fcbc6b43b64903a0fcbbd7651df9776fc9b10 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 13 Sep 2018 01:10:42 +0100 Subject: [PATCH 48/94] add test --- pandas/tests/io/formats/test_to_html.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index a0baa00b2782c..255d382a4ebe0 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2495,8 +2495,8 @@ def test_to_html_multi_indices_index_false(self): index_none_columns_unnamed_single), ('named_multi', 'named_multi', False, True, True, index_none_columns_named_multi), - # ('unnamed_multi', 'named_multi', False, True, True, - # index_none_columns_named_multi), + ('unnamed_multi', 'named_multi', False, True, True, + index_none_columns_named_multi), ('named_multi', 'unnamed_multi', False, True, True, index_none_columns_unnamed_multi) ]) From fae4070685b1ac27b8e72a8d6ba1db858d99935e Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 13 Sep 2018 01:43:50 +0100 Subject: [PATCH 49/94] refactor --- pandas/io/formats/html.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index e70651375c4af..299522ed48fec 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -288,9 +288,10 @@ def _column_header(): name = self.columns.names[lnum] row = [''] * (row_levels - 1) + ['' if name is None else pprint_thing(name)] + if not self.fmt.index: if self.show_col_idx_names: - row = [row[-1]] + row = row[-1:] else: row = [] From c3ab8d27c9241eb78a029e246f48f1014daba4e2 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 13 Sep 2018 01:57:36 +0100 Subject: [PATCH 50/94] refactor test --- pandas/tests/io/formats/test_to_html.py | 86 ++++++++++--------------- 1 file changed, 34 insertions(+), 52 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 255d382a4ebe0..db826f8968d78 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -22,6 +22,37 @@ pass +@pytest.fixture +def dataframe_index_names(idx_type, col_idx_type): + df = DataFrame(np.zeros((2, 2), dtype=int)) + + if idx_type == 'named_single': + df.index.name = 'index.name' + elif idx_type == 'unnamed_single': + pass + elif idx_type == 'named_multi': + df.index = MultiIndex.from_product([['a'], ['b', 'c']], names=[ + 'index.name.0', 'index.name.1']) + elif idx_type == 'unnamed_multi': + df.index = MultiIndex.from_product([['a'], ['b', 'c']]) + else: + raise ValueError + + if col_idx_type == 'named_single': + df.columns.name = 'columns.name' + elif col_idx_type == 'unnamed_single': + pass + elif col_idx_type == 'named_multi': + df.columns = MultiIndex.from_product([['a'], ['b', 'c']], names=[ + 'columns.name.0', 'columns.name.1']) + elif col_idx_type == 'unnamed_multi': + df.columns = MultiIndex.from_product([['a'], ['b', 'c']]) + else: + raise ValueError + + return df + + @pytest.fixture def index_named_single_columns_named_single(): return """\ @@ -2424,32 +2455,9 @@ def test_to_html_multiindex_max_cols(self): def test_to_html_multi_indices_index_false(self): # GH 22579 - multi_index = MultiIndex.from_product([['a'], ['b', 'c']]) - df = DataFrame(np.zeros((2, 2), dtype=int), multi_index, multi_index) + df = dataframe_index_names('unnamed_multi', 'unnamed_multi') result = df.to_html(index=False) - expected = dedent("""\ - - - - - - - - - - - - - - - - - - - - -
a
bc
00
00
""") - assert result == expected + assert result == dedent(index_none_columns_unnamed_multi()) @pytest.mark.parametrize("""idx_type, col_idx_type, index, header, index_names, expected""", [ @@ -2502,33 +2510,7 @@ def test_to_html_multi_indices_index_false(self): ]) def test_to_html_index_names(self, idx_type, col_idx_type, index, header, index_names, expected): - - df = DataFrame(np.zeros((2, 2), dtype=int)) - - if idx_type == 'named_single': - df.index.name = 'index.name' - elif idx_type == 'unnamed_single': - pass - elif idx_type == 'named_multi': - df.index = MultiIndex.from_product([['a'], ['b', 'c']], names=[ - 'index.name.0', 'index.name.1']) - elif idx_type == 'unnamed_multi': - df.index = MultiIndex.from_product([['a'], ['b', 'c']]) - else: - raise ValueError - - if col_idx_type == 'named_single': - df.columns.name = 'columns.name' - elif col_idx_type == 'unnamed_single': - pass - elif col_idx_type == 'named_multi': - df.columns = MultiIndex.from_product([['a'], ['b', 'c']], names=[ - 'columns.name.0', 'columns.name.1']) - elif col_idx_type == 'unnamed_multi': - df.columns = MultiIndex.from_product([['a'], ['b', 'c']]) - else: - raise ValueError - + df = dataframe_index_names(idx_type, col_idx_type) result = df.to_html(index=index, header=header, index_names=index_names) assert result == dedent(expected()) From 0d9330e05634c659afe139fc7856a2f9dcc546d2 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 13 Sep 2018 02:01:20 +0100 Subject: [PATCH 51/94] replace single with standard --- pandas/tests/io/formats/test_to_html.py | 88 ++++++++++++------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index db826f8968d78..a28714070c0f4 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -26,9 +26,9 @@ def dataframe_index_names(idx_type, col_idx_type): df = DataFrame(np.zeros((2, 2), dtype=int)) - if idx_type == 'named_single': + if idx_type == 'named_standard': df.index.name = 'index.name' - elif idx_type == 'unnamed_single': + elif idx_type == 'unnamed_standard': pass elif idx_type == 'named_multi': df.index = MultiIndex.from_product([['a'], ['b', 'c']], names=[ @@ -38,9 +38,9 @@ def dataframe_index_names(idx_type, col_idx_type): else: raise ValueError - if col_idx_type == 'named_single': + if col_idx_type == 'named_standard': df.columns.name = 'columns.name' - elif col_idx_type == 'unnamed_single': + elif col_idx_type == 'unnamed_standard': pass elif col_idx_type == 'named_multi': df.columns = MultiIndex.from_product([['a'], ['b', 'c']], names=[ @@ -54,7 +54,7 @@ def dataframe_index_names(idx_type, col_idx_type): @pytest.fixture -def index_named_single_columns_named_single(): +def index_named_standard_columns_named_standard(): return """\ @@ -85,7 +85,7 @@ def index_named_single_columns_named_single(): @pytest.fixture -def index_unnamed_single_columns_named_single(): +def index_unnamed_standard_columns_named_standard(): return """\
@@ -111,7 +111,7 @@ def index_unnamed_single_columns_named_single(): @pytest.fixture -def index_named_single_columns_unnamed_single(): +def index_named_standard_columns_unnamed_standard(): return """\
@@ -142,7 +142,7 @@ def index_named_single_columns_unnamed_single(): @pytest.fixture -def index_named_single_columns_named_multi(): +def index_named_standard_columns_named_multi(): return """\
@@ -177,7 +177,7 @@ def index_named_single_columns_named_multi(): @pytest.fixture -def index_unnamed_single_columns_named_multi(): +def index_unnamed_standard_columns_named_multi(): return """\
@@ -207,7 +207,7 @@ def index_unnamed_single_columns_named_multi(): @pytest.fixture -def index_named_single_columns_unnamed_multi(): +def index_named_standard_columns_unnamed_multi(): return """\
@@ -242,7 +242,7 @@ def index_named_single_columns_unnamed_multi(): @pytest.fixture -def index_named_multi_columns_named_single(): +def index_named_multi_columns_named_standard(): return """\
@@ -276,7 +276,7 @@ def index_named_multi_columns_named_single(): @pytest.fixture -def index_unnamed_multi_columns_named_single(): +def index_unnamed_multi_columns_named_standard(): return """\
@@ -304,7 +304,7 @@ def index_unnamed_multi_columns_named_single(): @pytest.fixture -def index_named_multi_columns_unnamed_single(): +def index_named_multi_columns_unnamed_standard(): return """\
@@ -522,7 +522,7 @@ def index_none_columns_none(): @pytest.fixture -def index_none_columns_named_single(): +def index_none_columns_named_standard(): return """\
@@ -548,7 +548,7 @@ def index_none_columns_named_single(): @pytest.fixture -def index_none_columns_unnamed_single(): +def index_none_columns_unnamed_standard(): return """\
@@ -2461,46 +2461,46 @@ def test_to_html_multi_indices_index_false(self): @pytest.mark.parametrize("""idx_type, col_idx_type, index, header, index_names, expected""", [ - ('named_single', 'named_single', True, True, True, - index_named_single_columns_named_single), - ('unnamed_single', 'named_single', True, True, True, - index_unnamed_single_columns_named_single), - ('named_single', 'unnamed_single', True, True, True, - index_named_single_columns_unnamed_single), - ('named_single', 'named_multi', True, True, True, - index_named_single_columns_named_multi), - ('unnamed_single', 'named_multi', True, True, True, - index_unnamed_single_columns_named_multi), - ('named_single', 'unnamed_multi', True, True, True, - index_named_single_columns_unnamed_multi), - ('named_multi', 'named_single', True, True, True, - index_named_multi_columns_named_single), - ('unnamed_multi', 'named_single', True, True, True, - index_unnamed_multi_columns_named_single), - ('named_multi', 'unnamed_single', True, True, True, - index_named_multi_columns_unnamed_single), + ('named_standard', 'named_standard', True, True, True, + index_named_standard_columns_named_standard), + ('unnamed_standard', 'named_standard', True, True, True, + index_unnamed_standard_columns_named_standard), + ('named_standard', 'unnamed_standard', True, True, True, + index_named_standard_columns_unnamed_standard), + ('named_standard', 'named_multi', True, True, True, + index_named_standard_columns_named_multi), + ('unnamed_standard', 'named_multi', True, True, True, + index_unnamed_standard_columns_named_multi), + ('named_standard', 'unnamed_multi', True, True, True, + index_named_standard_columns_unnamed_multi), + ('named_multi', 'named_standard', True, True, True, + index_named_multi_columns_named_standard), + ('unnamed_multi', 'named_standard', True, True, True, + index_unnamed_multi_columns_named_standard), + ('named_multi', 'unnamed_standard', True, True, True, + index_named_multi_columns_unnamed_standard), ('named_multi', 'named_multi', True, True, True, index_named_multi_columns_named_multi), ('unnamed_multi', 'named_multi', True, True, True, index_unnamed_multi_columns_named_multi), ('named_multi', 'unnamed_multi', True, True, True, index_named_multi_columns_unnamed_multi), - ('named_single', 'named_multi', False, True, True, + ('named_standard', 'named_multi', False, True, True, index_none_columns_named_multi), - ('named_single', 'named_multi', False, True, False, + ('named_standard', 'named_multi', False, True, False, index_none_columns_unnamed_multi), - ('named_single', 'named_multi', False, False, True, + ('named_standard', 'named_multi', False, False, True, index_none_columns_none), - ('unnamed_single', 'named_multi', False, True, True, + ('unnamed_standard', 'named_multi', False, True, True, index_none_columns_named_multi), - ('named_single', 'unnamed_multi', False, True, True, + ('named_standard', 'unnamed_multi', False, True, True, index_none_columns_unnamed_multi), - ('named_multi', 'named_single', False, True, True, - index_none_columns_named_single), - ('unnamed_multi', 'named_single', False, True, True, - index_none_columns_named_single), - ('named_multi', 'unnamed_single', False, True, True, - index_none_columns_unnamed_single), + ('named_multi', 'named_standard', False, True, True, + index_none_columns_named_standard), + ('unnamed_multi', 'named_standard', False, True, True, + index_none_columns_named_standard), + ('named_multi', 'unnamed_standard', False, True, True, + index_none_columns_unnamed_standard), ('named_multi', 'named_multi', False, True, True, index_none_columns_named_multi), ('unnamed_multi', 'named_multi', False, True, True, From ebf711b021c0d429e72a0639f0668fb15dbf8e58 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 13 Sep 2018 02:49:56 +0100 Subject: [PATCH 52/94] refactor tests --- pandas/tests/io/formats/test_to_html.py | 170 +++++++++--------------- 1 file changed, 64 insertions(+), 106 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index a28714070c0f4..213ec986d6499 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -22,7 +22,6 @@ pass -@pytest.fixture def dataframe_index_names(idx_type, col_idx_type): df = DataFrame(np.zeros((2, 2), dtype=int)) @@ -53,9 +52,7 @@ def dataframe_index_names(idx_type, col_idx_type): return df -@pytest.fixture -def index_named_standard_columns_named_standard(): - return """\ +index_named_standard_columns_named_standard = """\
@@ -84,9 +81,7 @@ def index_named_standard_columns_named_standard():
""" -@pytest.fixture -def index_unnamed_standard_columns_named_standard(): - return """\ +index_unnamed_standard_columns_named_standard = """\ @@ -110,9 +105,7 @@ def index_unnamed_standard_columns_named_standard():
""" -@pytest.fixture -def index_named_standard_columns_unnamed_standard(): - return """\ +index_named_standard_columns_unnamed_standard = """\ @@ -141,9 +134,7 @@ def index_named_standard_columns_unnamed_standard():
""" -@pytest.fixture -def index_named_standard_columns_named_multi(): - return """\ +index_named_standard_columns_named_multi = """\ @@ -176,9 +167,7 @@ def index_named_standard_columns_named_multi():
""" -@pytest.fixture -def index_unnamed_standard_columns_named_multi(): - return """\ +index_unnamed_standard_columns_named_multi = """\ @@ -206,9 +195,7 @@ def index_unnamed_standard_columns_named_multi():
""" -@pytest.fixture -def index_named_standard_columns_unnamed_multi(): - return """\ +index_named_standard_columns_unnamed_multi = """\ @@ -241,9 +228,7 @@ def index_named_standard_columns_unnamed_multi():
""" -@pytest.fixture -def index_named_multi_columns_named_standard(): - return """\ +index_named_multi_columns_named_standard = """\ @@ -275,9 +260,7 @@ def index_named_multi_columns_named_standard():
""" -@pytest.fixture -def index_unnamed_multi_columns_named_standard(): - return """\ +index_unnamed_multi_columns_named_standard = """\ @@ -303,9 +286,7 @@ def index_unnamed_multi_columns_named_standard():
""" -@pytest.fixture -def index_named_multi_columns_unnamed_standard(): - return """\ +index_named_multi_columns_unnamed_standard = """\ @@ -337,9 +318,7 @@ def index_named_multi_columns_unnamed_standard():
""" -@pytest.fixture -def index_named_multi_columns_named_multi(): - return """\ +index_named_multi_columns_named_multi = """\ @@ -376,9 +355,7 @@ def index_named_multi_columns_named_multi():
""" -@pytest.fixture -def index_unnamed_multi_columns_named_multi(): - return """\ +index_unnamed_multi_columns_named_multi = """\ @@ -409,9 +386,7 @@ def index_unnamed_multi_columns_named_multi():
""" -@pytest.fixture -def index_named_multi_columns_unnamed_multi(): - return """\ +index_named_multi_columns_unnamed_multi = """\ @@ -448,9 +423,7 @@ def index_named_multi_columns_unnamed_multi():
""" -@pytest.fixture -def index_none_columns_named_multi(): - return """\ +index_none_columns_named_multi = """\ @@ -478,9 +451,7 @@ def index_none_columns_named_multi():
""" -@pytest.fixture -def index_none_columns_unnamed_multi(): - return """\ +index_none_columns_unnamed_multi = """\ @@ -504,9 +475,7 @@ def index_none_columns_unnamed_multi():
""" -@pytest.fixture -def index_none_columns_none(): - return """\ +index_none_columns_none = """\ @@ -520,10 +489,7 @@ def index_none_columns_none():
""" - -@pytest.fixture -def index_none_columns_named_standard(): - return """\ +index_none_columns_named_standard = """\ @@ -547,9 +513,7 @@ def index_none_columns_named_standard():
""" -@pytest.fixture -def index_none_columns_unnamed_standard(): - return """\ +index_none_columns_unnamed_standard = """\ @@ -2457,63 +2421,57 @@ def test_to_html_multi_indices_index_false(self): # GH 22579 df = dataframe_index_names('unnamed_multi', 'unnamed_multi') result = df.to_html(index=False) - assert result == dedent(index_none_columns_unnamed_multi()) - - @pytest.mark.parametrize("""idx_type, col_idx_type, index, header, - index_names, expected""", [ - ('named_standard', 'named_standard', True, True, True, - index_named_standard_columns_named_standard), - ('unnamed_standard', 'named_standard', True, True, True, - index_unnamed_standard_columns_named_standard), - ('named_standard', 'unnamed_standard', True, True, True, - index_named_standard_columns_unnamed_standard), - ('named_standard', 'named_multi', True, True, True, - index_named_standard_columns_named_multi), - ('unnamed_standard', 'named_multi', True, True, True, - index_unnamed_standard_columns_named_multi), - ('named_standard', 'unnamed_multi', True, True, True, - index_named_standard_columns_unnamed_multi), - ('named_multi', 'named_standard', True, True, True, - index_named_multi_columns_named_standard), - ('unnamed_multi', 'named_standard', True, True, True, - index_unnamed_multi_columns_named_standard), - ('named_multi', 'unnamed_standard', True, True, True, - index_named_multi_columns_unnamed_standard), - ('named_multi', 'named_multi', True, True, True, - index_named_multi_columns_named_multi), - ('unnamed_multi', 'named_multi', True, True, True, - index_unnamed_multi_columns_named_multi), - ('named_multi', 'unnamed_multi', True, True, True, - index_named_multi_columns_unnamed_multi), - ('named_standard', 'named_multi', False, True, True, - index_none_columns_named_multi), - ('named_standard', 'named_multi', False, True, False, - index_none_columns_unnamed_multi), - ('named_standard', 'named_multi', False, False, True, - index_none_columns_none), - ('unnamed_standard', 'named_multi', False, True, True, - index_none_columns_named_multi), - ('named_standard', 'unnamed_multi', False, True, True, - index_none_columns_unnamed_multi), - ('named_multi', 'named_standard', False, True, True, - index_none_columns_named_standard), - ('unnamed_multi', 'named_standard', False, True, True, - index_none_columns_named_standard), - ('named_multi', 'unnamed_standard', False, True, True, - index_none_columns_unnamed_standard), - ('named_multi', 'named_multi', False, True, True, - index_none_columns_named_multi), - ('unnamed_multi', 'named_multi', False, True, True, - index_none_columns_named_multi), - ('named_multi', 'unnamed_multi', False, True, True, - index_none_columns_unnamed_multi) - ]) + assert result == dedent(index_none_columns_unnamed_multi) + + @pytest.mark.parametrize( + 'idx_type, col_idx_type, index, header, index_names', [ + ('named_standard', 'named_standard', True, True, True), + ('unnamed_standard', 'named_standard', True, True, True), + ('named_standard', 'unnamed_standard', True, True, True), + ('named_standard', 'named_multi', True, True, True), + ('unnamed_standard', 'named_multi', True, True, True), + ('named_standard', 'unnamed_multi', True, True, True), + ('named_multi', 'named_standard', True, True, True), + ('unnamed_multi', 'named_standard', True, True, True), + ('named_multi', 'unnamed_standard', True, True, True), + ('named_multi', 'named_multi', True, True, True), + ('unnamed_multi', 'named_multi', True, True, True), + ('named_multi', 'unnamed_multi', True, True, True), + ('named_standard', 'named_multi', False, True, True), + ('named_standard', 'named_multi', False, True, False), + ('named_standard', 'named_multi', False, False, True), + ('unnamed_standard', 'named_multi', False, True, True), + ('named_standard', 'unnamed_multi', False, True, True), + ('named_multi', 'named_standard', False, True, True), + ('unnamed_multi', 'named_standard', False, True, True), + ('named_multi', 'unnamed_standard', False, True, True), + ('named_multi', 'named_multi', False, True, True), + ('unnamed_multi', 'named_multi', False, True, True), + ('named_multi', 'unnamed_multi', False, True, True) + ]) def test_to_html_index_names(self, idx_type, col_idx_type, index, header, - index_names, expected): + index_names): df = dataframe_index_names(idx_type, col_idx_type) result = df.to_html(index=index, header=header, index_names=index_names) - assert result == dedent(expected()) + + if index is False: + e1 = 'none' + elif index_names is False: + e1 = idx_type.replace('named', 'unnamed') + else: + e1 = idx_type + + if header is False: + e2 = 'none' + elif index_names is False: + e2 = col_idx_type.replace('named', 'unnamed') + else: + e2 = col_idx_type + e = 'index_' + e1 + '_columns_' + e2 + + expected = globals()[e] + assert result == dedent(expected) def test_to_html_notebook_has_style(self): df = pd.DataFrame({"A": [1, 2, 3]}) From b79842901aeb7ab674124eb28d5f6a93c20f0a82 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 13 Sep 2018 09:20:06 +0100 Subject: [PATCH 53/94] refactor test --- pandas/tests/io/formats/test_to_html.py | 111 +++++++++--------------- 1 file changed, 42 insertions(+), 69 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 213ec986d6499..e721772f8e5c3 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -22,7 +22,7 @@ pass -def dataframe_index_names(idx_type, col_idx_type): +def _test_helper_dataframe_index_names(idx_type, col_idx_type): df = DataFrame(np.zeros((2, 2), dtype=int)) if idx_type == 'named_standard': @@ -52,7 +52,8 @@ def dataframe_index_names(idx_type, col_idx_type): return df -index_named_standard_columns_named_standard = """\ +_EXPECTED_BASIC_ALIGNMENT = { + 'index_named_standard_columns_named_standard': """\
@@ -78,10 +79,8 @@ def dataframe_index_names(idx_type, col_idx_type): -
0
""" - - -index_unnamed_standard_columns_named_standard = """\ + """, + 'index_unnamed_standard_columns_named_standard': """\ @@ -102,10 +101,8 @@ def dataframe_index_names(idx_type, col_idx_type): -
0
""" - - -index_named_standard_columns_unnamed_standard = """\ + """, + 'index_named_standard_columns_unnamed_standard': """\ @@ -131,10 +128,8 @@ def dataframe_index_names(idx_type, col_idx_type): -
0
""" - - -index_named_standard_columns_named_multi = """\ + """, + 'index_named_standard_columns_named_multi': """\ @@ -164,10 +159,8 @@ def dataframe_index_names(idx_type, col_idx_type): -
0
""" - - -index_unnamed_standard_columns_named_multi = """\ + """, + 'index_unnamed_standard_columns_named_multi': """\ @@ -192,10 +185,8 @@ def dataframe_index_names(idx_type, col_idx_type): -
0
""" - - -index_named_standard_columns_unnamed_multi = """\ + """, + 'index_named_standard_columns_unnamed_multi': """\ @@ -225,10 +216,8 @@ def dataframe_index_names(idx_type, col_idx_type): -
0
""" - - -index_named_multi_columns_named_standard = """\ + """, + 'index_named_multi_columns_named_standard': """\ @@ -257,10 +246,8 @@ def dataframe_index_names(idx_type, col_idx_type): -
0
""" - - -index_unnamed_multi_columns_named_standard = """\ + """, + 'index_unnamed_multi_columns_named_standard': """\ @@ -283,10 +270,8 @@ def dataframe_index_names(idx_type, col_idx_type): -
0
""" - - -index_named_multi_columns_unnamed_standard = """\ + """, + 'index_named_multi_columns_unnamed_standard': """\ @@ -315,10 +300,8 @@ def dataframe_index_names(idx_type, col_idx_type): -
0
""" - - -index_named_multi_columns_named_multi = """\ + """, + 'index_named_multi_columns_named_multi': """\ @@ -352,10 +335,8 @@ def dataframe_index_names(idx_type, col_idx_type): -
0
""" - - -index_unnamed_multi_columns_named_multi = """\ + """, + 'index_unnamed_multi_columns_named_multi': """\ @@ -383,10 +364,8 @@ def dataframe_index_names(idx_type, col_idx_type): -
0
""" - - -index_named_multi_columns_unnamed_multi = """\ + """, + 'index_named_multi_columns_unnamed_multi': """\ @@ -420,10 +399,8 @@ def dataframe_index_names(idx_type, col_idx_type): -
0
""" - - -index_none_columns_named_multi = """\ + """, + 'index_none_columns_named_multi': """\ @@ -448,10 +425,8 @@ def dataframe_index_names(idx_type, col_idx_type): -
0
""" - - -index_none_columns_unnamed_multi = """\ + """, + 'index_none_columns_unnamed_multi': """\ @@ -472,10 +447,8 @@ def dataframe_index_names(idx_type, col_idx_type): -
0
""" - - -index_none_columns_none = """\ + """, + 'index_none_columns_none': """\ @@ -487,9 +460,8 @@ def dataframe_index_names(idx_type, col_idx_type): -
0
""" - -index_none_columns_named_standard = """\ + """, + 'index_none_columns_named_standard': """\ @@ -510,10 +482,8 @@ def dataframe_index_names(idx_type, col_idx_type): -
0
""" - - -index_none_columns_unnamed_standard = """\ + """, + 'index_none_columns_unnamed_standard': """\ @@ -532,6 +502,7 @@ def dataframe_index_names(idx_type, col_idx_type):
""" +} class TestToHTML(object): @@ -2419,9 +2390,11 @@ def test_to_html_multiindex_max_cols(self): def test_to_html_multi_indices_index_false(self): # GH 22579 - df = dataframe_index_names('unnamed_multi', 'unnamed_multi') + df = _test_helper_dataframe_index_names( + 'unnamed_multi', 'unnamed_multi') result = df.to_html(index=False) - assert result == dedent(index_none_columns_unnamed_multi) + assert result == dedent( + _EXPECTED_BASIC_ALIGNMENT['index_none_columns_unnamed_multi']) @pytest.mark.parametrize( 'idx_type, col_idx_type, index, header, index_names', [ @@ -2451,7 +2424,7 @@ def test_to_html_multi_indices_index_false(self): ]) def test_to_html_index_names(self, idx_type, col_idx_type, index, header, index_names): - df = dataframe_index_names(idx_type, col_idx_type) + df = _test_helper_dataframe_index_names(idx_type, col_idx_type) result = df.to_html(index=index, header=header, index_names=index_names) @@ -2470,7 +2443,7 @@ def test_to_html_index_names(self, idx_type, col_idx_type, index, header, e2 = col_idx_type e = 'index_' + e1 + '_columns_' + e2 - expected = globals()[e] + expected = _EXPECTED_BASIC_ALIGNMENT[e] assert result == dedent(expected) def test_to_html_notebook_has_style(self): From 23e3204bb557264b65a7e3d7a301d68037fdf446 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 13 Sep 2018 09:38:49 +0100 Subject: [PATCH 54/94] refactor test --- pandas/tests/io/formats/test_to_html.py | 28 +++++++++++-------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index e721772f8e5c3..9c146b85ae024 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2428,22 +2428,18 @@ def test_to_html_index_names(self, idx_type, col_idx_type, index, header, result = df.to_html(index=index, header=header, index_names=index_names) - if index is False: - e1 = 'none' - elif index_names is False: - e1 = idx_type.replace('named', 'unnamed') - else: - e1 = idx_type - - if header is False: - e2 = 'none' - elif index_names is False: - e2 = col_idx_type.replace('named', 'unnamed') - else: - e2 = col_idx_type - e = 'index_' + e1 + '_columns_' + e2 - - expected = _EXPECTED_BASIC_ALIGNMENT[e] + def _expected(idx_type, index, index_names): + if index is False: + return 'none' + if index_names is False: + return idx_type.replace('named', 'unnamed') + return idx_type + + expected = _EXPECTED_BASIC_ALIGNMENT[ + 'index_' + _expected(idx_type, index, index_names) + + '_columns_' + _expected(col_idx_type, header, index_names) + ] + assert result == dedent(expected) def test_to_html_notebook_has_style(self): From 9fd31b30ad1ff1904b0ca3708ff2ad1facda76c9 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 13 Sep 2018 11:17:52 +0100 Subject: [PATCH 55/94] add tests (failing) --- pandas/tests/io/formats/test_to_html.py | 140 +++++++++++++++++++----- 1 file changed, 113 insertions(+), 27 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 9c146b85ae024..6fe1f2b5de31a 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -501,6 +501,107 @@ def _test_helper_dataframe_index_names(idx_type, col_idx_type): 0 + """, + 'index_unnamed_standard_columns_unnamed_standard': """\ + + + + + + + + + + + + + + + + + + + + +
01
000
100
""", + 'index_unnamed_standard_columns_unnamed_multi': """\ + + + + + + + + + + + + + + + + + + + + + + + + +
a
bc
000
100
""", + 'index_unnamed_multi_columns_unnamed_standard': """\ + + + + + + + + + + + + + + + + + + + + + + +
01
ab00
c00
""", + 'index_unnamed_multi_columns_unnamed_multi': """\ + + + + + + + + + + + + + + + + + + + + + + + + + + +
a
bc
ab00
c00
""" } @@ -2396,32 +2497,17 @@ def test_to_html_multi_indices_index_false(self): assert result == dedent( _EXPECTED_BASIC_ALIGNMENT['index_none_columns_unnamed_multi']) - @pytest.mark.parametrize( - 'idx_type, col_idx_type, index, header, index_names', [ - ('named_standard', 'named_standard', True, True, True), - ('unnamed_standard', 'named_standard', True, True, True), - ('named_standard', 'unnamed_standard', True, True, True), - ('named_standard', 'named_multi', True, True, True), - ('unnamed_standard', 'named_multi', True, True, True), - ('named_standard', 'unnamed_multi', True, True, True), - ('named_multi', 'named_standard', True, True, True), - ('unnamed_multi', 'named_standard', True, True, True), - ('named_multi', 'unnamed_standard', True, True, True), - ('named_multi', 'named_multi', True, True, True), - ('unnamed_multi', 'named_multi', True, True, True), - ('named_multi', 'unnamed_multi', True, True, True), - ('named_standard', 'named_multi', False, True, True), - ('named_standard', 'named_multi', False, True, False), - ('named_standard', 'named_multi', False, False, True), - ('unnamed_standard', 'named_multi', False, True, True), - ('named_standard', 'unnamed_multi', False, True, True), - ('named_multi', 'named_standard', False, True, True), - ('unnamed_multi', 'named_standard', False, True, True), - ('named_multi', 'unnamed_standard', False, True, True), - ('named_multi', 'named_multi', False, True, True), - ('unnamed_multi', 'named_multi', False, True, True), - ('named_multi', 'unnamed_multi', False, True, True) - ]) + @pytest.mark.parametrize('index_names', [True, False]) + @pytest.mark.parametrize('header', [True]) + @pytest.mark.parametrize('index', [True, False]) + @pytest.mark.parametrize('col_idx_type', ['unnamed_standard', + 'named_standard', + 'unnamed_multi', + 'named_multi']) + @pytest.mark.parametrize('idx_type', ['unnamed_standard', + 'named_standard', + 'unnamed_multi', + 'named_multi']) def test_to_html_index_names(self, idx_type, col_idx_type, index, header, index_names): df = _test_helper_dataframe_index_names(idx_type, col_idx_type) @@ -2431,7 +2517,7 @@ def test_to_html_index_names(self, idx_type, col_idx_type, index, header, def _expected(idx_type, index, index_names): if index is False: return 'none' - if index_names is False: + if idx_type.startswith('named') and index_names is False: return idx_type.replace('named', 'unnamed') return idx_type From 22396e203c271afce65867c98fefa6b5c9b0f4f4 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 13 Sep 2018 12:45:40 +0100 Subject: [PATCH 56/94] fix failing tests --- pandas/io/formats/html.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 299522ed48fec..4250e24cabacf 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -220,7 +220,10 @@ def _column_header(): for c in self.columns]) else: if self.fmt.index or self.show_col_idx_names: - row.append(self.columns.name or '') + if self.show_col_idx_names: + row.append(self.columns.name or '') + else: + row.append('') row.extend(self.columns) return row @@ -289,6 +292,8 @@ def _column_header(): row = [''] * (row_levels - 1) + ['' if name is None else pprint_thing(name)] + if not self.show_col_idx_names: + row[-1] = '' if not self.fmt.index: if self.show_col_idx_names: row = row[-1:] From aee9b7e4ff5f33ae670ac83fc4d8252ad0e389b2 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 13 Sep 2018 12:56:10 +0100 Subject: [PATCH 57/94] minimise changes --- pandas/io/formats/html.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 4250e24cabacf..02a8533f566db 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -220,10 +220,9 @@ def _column_header(): for c in self.columns]) else: if self.fmt.index or self.show_col_idx_names: - if self.show_col_idx_names: - row.append(self.columns.name or '') - else: - row.append('') + row.append(self.columns.name or '') + if self.show_col_idx_names is False: + row[-1] = '' row.extend(self.columns) return row @@ -292,9 +291,9 @@ def _column_header(): row = [''] * (row_levels - 1) + ['' if name is None else pprint_thing(name)] - if not self.show_col_idx_names: + if self.show_col_idx_names is False: row[-1] = '' - if not self.fmt.index: + if self.fmt.index is False: if self.show_col_idx_names: row = row[-1:] else: From aae16321198211d6efd103611fced4b3139dd48b Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 13 Sep 2018 22:55:34 +0100 Subject: [PATCH 58/94] WIP add test fixtures --- ...named_standard_columns_named_standard.html | 26 +++++++++++++++++++ pandas/tests/io/formats/test_to_html.py | 25 ++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 pandas/tests/io/formats/data/index_named_standard_columns_named_standard.html diff --git a/pandas/tests/io/formats/data/index_named_standard_columns_named_standard.html b/pandas/tests/io/formats/data/index_named_standard_columns_named_standard.html new file mode 100644 index 0000000000000..dd9e3ecfc05db --- /dev/null +++ b/pandas/tests/io/formats/data/index_named_standard_columns_named_standard.html @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name01
index.name
000
100
\ No newline at end of file diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 6fe1f2b5de31a..23a280540c1f1 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -22,6 +22,17 @@ pass +@pytest.fixture +def read_file(datapath): + + def _read_file(filename): + filepath = datapath('io', 'formats', 'data', filename) + with open(filepath) as f: + contents = f.read() + return contents + return _read_file + + def _test_helper_dataframe_index_names(idx_type, col_idx_type): df = DataFrame(np.zeros((2, 2), dtype=int)) @@ -2497,6 +2508,20 @@ def test_to_html_multi_indices_index_false(self): assert result == dedent( _EXPECTED_BASIC_ALIGNMENT['index_none_columns_unnamed_multi']) + @pytest.mark.parametrize( + 'idx_type, col_idx_type, index, header, index_names', + [('named_standard', 'named_standard', True, True, True)]) + def test_to_html_WIP(self, read_file, idx_type, col_idx_type, index, + header, index_names): + df = _test_helper_dataframe_index_names(idx_type, col_idx_type) + result = df.to_html(index=index, header=header, + index_names=index_names) + + expected = read_file( + 'index_named_standard_columns_named_standard.html') + + assert result == expected + @pytest.mark.parametrize('index_names', [True, False]) @pytest.mark.parametrize('header', [True]) @pytest.mark.parametrize('index', [True, False]) From 398908551238779e7659c4a103fc35536c95baac Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 14 Sep 2018 11:29:17 +0100 Subject: [PATCH 59/94] WIP add test fixtures --- ...named_standard_columns_named_standard.html | 2 +- pandas/tests/io/formats/test_to_html.py | 43 ++++++++++--------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/pandas/tests/io/formats/data/index_named_standard_columns_named_standard.html b/pandas/tests/io/formats/data/index_named_standard_columns_named_standard.html index dd9e3ecfc05db..6478c99ad85e9 100644 --- a/pandas/tests/io/formats/data/index_named_standard_columns_named_standard.html +++ b/pandas/tests/io/formats/data/index_named_standard_columns_named_standard.html @@ -23,4 +23,4 @@ 0 - \ No newline at end of file + diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 23a280540c1f1..296a5b756c622 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -33,6 +33,16 @@ def _read_file(filename): return _read_file +@pytest.fixture +def expected_html(read_file): + + def _expected_html(name): + filename = '.'.join([name, 'html']) + html = read_file(filename) + return html.rstrip() + return _expected_html + + def _test_helper_dataframe_index_names(idx_type, col_idx_type): df = DataFrame(np.zeros((2, 2), dtype=int)) @@ -2508,20 +2518,6 @@ def test_to_html_multi_indices_index_false(self): assert result == dedent( _EXPECTED_BASIC_ALIGNMENT['index_none_columns_unnamed_multi']) - @pytest.mark.parametrize( - 'idx_type, col_idx_type, index, header, index_names', - [('named_standard', 'named_standard', True, True, True)]) - def test_to_html_WIP(self, read_file, idx_type, col_idx_type, index, - header, index_names): - df = _test_helper_dataframe_index_names(idx_type, col_idx_type) - result = df.to_html(index=index, header=header, - index_names=index_names) - - expected = read_file( - 'index_named_standard_columns_named_standard.html') - - assert result == expected - @pytest.mark.parametrize('index_names', [True, False]) @pytest.mark.parametrize('header', [True]) @pytest.mark.parametrize('index', [True, False]) @@ -2533,9 +2529,10 @@ def test_to_html_WIP(self, read_file, idx_type, col_idx_type, index, 'named_standard', 'unnamed_multi', 'named_multi']) - def test_to_html_index_names(self, idx_type, col_idx_type, index, header, - index_names): + def test_to_html_index_names(self, expected_html, idx_type, col_idx_type, + index, header, index_names): df = _test_helper_dataframe_index_names(idx_type, col_idx_type) + result = df.to_html(index=index, header=header, index_names=index_names) @@ -2546,12 +2543,16 @@ def _expected(idx_type, index, index_names): return idx_type.replace('named', 'unnamed') return idx_type - expected = _EXPECTED_BASIC_ALIGNMENT[ - 'index_' + _expected(idx_type, index, index_names) + - '_columns_' + _expected(col_idx_type, header, index_names) - ] + expected = expected_html( + '_'.join([ + 'index', + _expected(idx_type, index, index_names), + 'columns', + _expected(col_idx_type, header, index_names) + ]) + ) - assert result == dedent(expected) + assert result == expected def test_to_html_notebook_has_style(self): df = pd.DataFrame({"A": [1, 2, 3]}) From 21a70edc35516ee734796c78e6d11026f6442370 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 14 Sep 2018 13:24:20 +0100 Subject: [PATCH 60/94] WIP add test fixtures --- ...index_named_multi_columns_named_multi.html | 35 +++++++++++++++++++ ...ex_named_multi_columns_named_standard.html | 29 +++++++++++++++ ...dex_named_multi_columns_unnamed_multi.html | 34 ++++++++++++++++++ ..._named_multi_columns_unnamed_standard.html | 29 +++++++++++++++ ...ex_named_standard_columns_named_multi.html | 30 ++++++++++++++++ ..._named_standard_columns_unnamed_multi.html | 30 ++++++++++++++++ ...med_standard_columns_unnamed_standard.html | 26 ++++++++++++++ .../data/index_none_columns_named_multi.html | 25 +++++++++++++ .../index_none_columns_named_standard.html | 21 +++++++++++ .../formats/data/index_none_columns_none.html | 12 +++++++ .../index_none_columns_unnamed_multi.html | 21 +++++++++++ .../index_none_columns_unnamed_standard.html | 18 ++++++++++ ...dex_unnamed_multi_columns_named_multi.html | 28 +++++++++++++++ ..._unnamed_multi_columns_named_standard.html | 23 ++++++++++++ ...x_unnamed_multi_columns_unnamed_multi.html | 28 +++++++++++++++ ...nnamed_multi_columns_unnamed_standard.html | 23 ++++++++++++ ..._unnamed_standard_columns_named_multi.html | 25 +++++++++++++ ...named_standard_columns_named_standard.html | 21 +++++++++++ ...nnamed_standard_columns_unnamed_multi.html | 25 +++++++++++++ ...med_standard_columns_unnamed_standard.html | 21 +++++++++++ 20 files changed, 504 insertions(+) create mode 100644 pandas/tests/io/formats/data/index_named_multi_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/index_named_multi_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/index_named_multi_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/index_named_multi_columns_unnamed_standard.html create mode 100644 pandas/tests/io/formats/data/index_named_standard_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/index_named_standard_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/index_named_standard_columns_unnamed_standard.html create mode 100644 pandas/tests/io/formats/data/index_none_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/index_none_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/index_none_columns_none.html create mode 100644 pandas/tests/io/formats/data/index_none_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/index_none_columns_unnamed_standard.html create mode 100644 pandas/tests/io/formats/data/index_unnamed_multi_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/index_unnamed_multi_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/index_unnamed_multi_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/index_unnamed_multi_columns_unnamed_standard.html create mode 100644 pandas/tests/io/formats/data/index_unnamed_standard_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/index_unnamed_standard_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/index_unnamed_standard_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/index_unnamed_standard_columns_unnamed_standard.html diff --git a/pandas/tests/io/formats/data/index_named_multi_columns_named_multi.html b/pandas/tests/io/formats/data/index_named_multi_columns_named_multi.html new file mode 100644 index 0000000000000..04ba2880753e6 --- /dev/null +++ b/pandas/tests/io/formats/data/index_named_multi_columns_named_multi.html @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
index.name.0index.name.1
ab00
c00
+ \ No newline at end of file diff --git a/pandas/tests/io/formats/data/index_named_multi_columns_named_standard.html b/pandas/tests/io/formats/data/index_named_multi_columns_named_standard.html new file mode 100644 index 0000000000000..e85965f14075d --- /dev/null +++ b/pandas/tests/io/formats/data/index_named_multi_columns_named_standard.html @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name01
index.name.0index.name.1
ab00
c00
diff --git a/pandas/tests/io/formats/data/index_named_multi_columns_unnamed_multi.html b/pandas/tests/io/formats/data/index_named_multi_columns_unnamed_multi.html new file mode 100644 index 0000000000000..7af63e893b12e --- /dev/null +++ b/pandas/tests/io/formats/data/index_named_multi_columns_unnamed_multi.html @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
a
bc
index.name.0index.name.1
ab00
c00
diff --git a/pandas/tests/io/formats/data/index_named_multi_columns_unnamed_standard.html b/pandas/tests/io/formats/data/index_named_multi_columns_unnamed_standard.html new file mode 100644 index 0000000000000..2f7837864bf88 --- /dev/null +++ b/pandas/tests/io/formats/data/index_named_multi_columns_unnamed_standard.html @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
01
index.name.0index.name.1
ab00
c00
diff --git a/pandas/tests/io/formats/data/index_named_standard_columns_named_multi.html b/pandas/tests/io/formats/data/index_named_standard_columns_named_multi.html new file mode 100644 index 0000000000000..ca9b8bd834a9c --- /dev/null +++ b/pandas/tests/io/formats/data/index_named_standard_columns_named_multi.html @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
index.name
000
100
diff --git a/pandas/tests/io/formats/data/index_named_standard_columns_unnamed_multi.html b/pandas/tests/io/formats/data/index_named_standard_columns_unnamed_multi.html new file mode 100644 index 0000000000000..d7660872177dc --- /dev/null +++ b/pandas/tests/io/formats/data/index_named_standard_columns_unnamed_multi.html @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
a
bc
index.name
000
100
diff --git a/pandas/tests/io/formats/data/index_named_standard_columns_unnamed_standard.html b/pandas/tests/io/formats/data/index_named_standard_columns_unnamed_standard.html new file mode 100644 index 0000000000000..4810f66018d3b --- /dev/null +++ b/pandas/tests/io/formats/data/index_named_standard_columns_unnamed_standard.html @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +
01
index.name
000
100
diff --git a/pandas/tests/io/formats/data/index_none_columns_named_multi.html b/pandas/tests/io/formats/data/index_none_columns_named_multi.html new file mode 100644 index 0000000000000..cb19a95bf5d18 --- /dev/null +++ b/pandas/tests/io/formats/data/index_none_columns_named_multi.html @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
00
00
diff --git a/pandas/tests/io/formats/data/index_none_columns_named_standard.html b/pandas/tests/io/formats/data/index_none_columns_named_standard.html new file mode 100644 index 0000000000000..cff4d2372acec --- /dev/null +++ b/pandas/tests/io/formats/data/index_none_columns_named_standard.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + +
columns.name01
00
00
diff --git a/pandas/tests/io/formats/data/index_none_columns_none.html b/pandas/tests/io/formats/data/index_none_columns_none.html new file mode 100644 index 0000000000000..44899858d9519 --- /dev/null +++ b/pandas/tests/io/formats/data/index_none_columns_none.html @@ -0,0 +1,12 @@ + + + + + + + + + + + +
00
00
diff --git a/pandas/tests/io/formats/data/index_none_columns_unnamed_multi.html b/pandas/tests/io/formats/data/index_none_columns_unnamed_multi.html new file mode 100644 index 0000000000000..b21a618328b1b --- /dev/null +++ b/pandas/tests/io/formats/data/index_none_columns_unnamed_multi.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + +
a
bc
00
00
diff --git a/pandas/tests/io/formats/data/index_none_columns_unnamed_standard.html b/pandas/tests/io/formats/data/index_none_columns_unnamed_standard.html new file mode 100644 index 0000000000000..1249fa5605099 --- /dev/null +++ b/pandas/tests/io/formats/data/index_none_columns_unnamed_standard.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + +
01
00
00
diff --git a/pandas/tests/io/formats/data/index_unnamed_multi_columns_named_multi.html b/pandas/tests/io/formats/data/index_unnamed_multi_columns_named_multi.html new file mode 100644 index 0000000000000..95c38c9c8fd28 --- /dev/null +++ b/pandas/tests/io/formats/data/index_unnamed_multi_columns_named_multi.html @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
ab00
c00
diff --git a/pandas/tests/io/formats/data/index_unnamed_multi_columns_named_standard.html b/pandas/tests/io/formats/data/index_unnamed_multi_columns_named_standard.html new file mode 100644 index 0000000000000..9583a21f55f01 --- /dev/null +++ b/pandas/tests/io/formats/data/index_unnamed_multi_columns_named_standard.html @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + +
columns.name01
ab00
c00
diff --git a/pandas/tests/io/formats/data/index_unnamed_multi_columns_unnamed_multi.html b/pandas/tests/io/formats/data/index_unnamed_multi_columns_unnamed_multi.html new file mode 100644 index 0000000000000..f620259037b60 --- /dev/null +++ b/pandas/tests/io/formats/data/index_unnamed_multi_columns_unnamed_multi.html @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
a
bc
ab00
c00
diff --git a/pandas/tests/io/formats/data/index_unnamed_multi_columns_unnamed_standard.html b/pandas/tests/io/formats/data/index_unnamed_multi_columns_unnamed_standard.html new file mode 100644 index 0000000000000..2ca18c288437b --- /dev/null +++ b/pandas/tests/io/formats/data/index_unnamed_multi_columns_unnamed_standard.html @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + +
01
ab00
c00
diff --git a/pandas/tests/io/formats/data/index_unnamed_standard_columns_named_multi.html b/pandas/tests/io/formats/data/index_unnamed_standard_columns_named_multi.html new file mode 100644 index 0000000000000..ed3360f898afd --- /dev/null +++ b/pandas/tests/io/formats/data/index_unnamed_standard_columns_named_multi.html @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
000
100
diff --git a/pandas/tests/io/formats/data/index_unnamed_standard_columns_named_standard.html b/pandas/tests/io/formats/data/index_unnamed_standard_columns_named_standard.html new file mode 100644 index 0000000000000..54da03858a9a4 --- /dev/null +++ b/pandas/tests/io/formats/data/index_unnamed_standard_columns_named_standard.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + +
columns.name01
000
100
diff --git a/pandas/tests/io/formats/data/index_unnamed_standard_columns_unnamed_multi.html b/pandas/tests/io/formats/data/index_unnamed_standard_columns_unnamed_multi.html new file mode 100644 index 0000000000000..b57fafbe0ca40 --- /dev/null +++ b/pandas/tests/io/formats/data/index_unnamed_standard_columns_unnamed_multi.html @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
a
bc
000
100
diff --git a/pandas/tests/io/formats/data/index_unnamed_standard_columns_unnamed_standard.html b/pandas/tests/io/formats/data/index_unnamed_standard_columns_unnamed_standard.html new file mode 100644 index 0000000000000..235ca61a9e63d --- /dev/null +++ b/pandas/tests/io/formats/data/index_unnamed_standard_columns_unnamed_standard.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + +
01
000
100
From 85490a9704bc029f034cdd05685ad0a628bfd97d Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 14 Sep 2018 13:30:32 +0100 Subject: [PATCH 61/94] WIP add test fixtures --- pandas/tests/io/formats/test_to_html.py | 559 +----------------------- 1 file changed, 2 insertions(+), 557 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 296a5b756c622..7646ef2a84ef8 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -73,560 +73,6 @@ def _test_helper_dataframe_index_names(idx_type, col_idx_type): return df -_EXPECTED_BASIC_ALIGNMENT = { - 'index_named_standard_columns_named_standard': """\ - - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name01
index.name
000
100
""", - 'index_unnamed_standard_columns_named_standard': """\ - - - - - - - - - - - - - - - - - - - - -
columns.name01
000
100
""", - 'index_named_standard_columns_unnamed_standard': """\ - - - - - - - - - - - - - - - - - - - - - - - - - -
01
index.name
000
100
""", - 'index_named_standard_columns_named_multi': """\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name.0a
columns.name.1bc
index.name
000
100
""", - 'index_unnamed_standard_columns_named_multi': """\ - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name.0a
columns.name.1bc
000
100
""", - 'index_named_standard_columns_unnamed_multi': """\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
a
bc
index.name
000
100
""", - 'index_named_multi_columns_named_standard': """\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name01
index.name.0index.name.1
ab00
c00
""", - 'index_unnamed_multi_columns_named_standard': """\ - - - - - - - - - - - - - - - - - - - - - - -
columns.name01
ab00
c00
""", - 'index_named_multi_columns_unnamed_standard': """\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
01
index.name.0index.name.1
ab00
c00
""", - 'index_named_multi_columns_named_multi': """\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name.0a
columns.name.1bc
index.name.0index.name.1
ab00
c00
""", - 'index_unnamed_multi_columns_named_multi': """\ - - - - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name.0a
columns.name.1bc
ab00
c00
""", - 'index_named_multi_columns_unnamed_multi': """\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
a
bc
index.name.0index.name.1
ab00
c00
""", - 'index_none_columns_named_multi': """\ - - - - - - - - - - - - - - - - - - - - - - - - -
columns.name.0a
columns.name.1bc
00
00
""", - 'index_none_columns_unnamed_multi': """\ - - - - - - - - - - - - - - - - - - - - -
a
bc
00
00
""", - 'index_none_columns_none': """\ - - - - - - - - - - - -
00
00
""", - 'index_none_columns_named_standard': """\ - - - - - - - - - - - - - - - - - - - - -
columns.name01
00
00
""", - 'index_none_columns_unnamed_standard': """\ - - - - - - - - - - - - - - - - - -
01
00
00
""", - 'index_unnamed_standard_columns_unnamed_standard': """\ - - - - - - - - - - - - - - - - - - - - -
01
000
100
""", - 'index_unnamed_standard_columns_unnamed_multi': """\ - - - - - - - - - - - - - - - - - - - - - - - - -
a
bc
000
100
""", - 'index_unnamed_multi_columns_unnamed_standard': """\ - - - - - - - - - - - - - - - - - - - - - - -
01
ab00
c00
""", - 'index_unnamed_multi_columns_unnamed_multi': """\ - - - - - - - - - - - - - - - - - - - - - - - - - - - -
a
bc
ab00
c00
""" -} - - class TestToHTML(object): def test_to_html_with_col_space(self): @@ -2510,13 +1956,12 @@ def test_to_html_multiindex_max_cols(self): """) assert result == expected - def test_to_html_multi_indices_index_false(self): + def test_to_html_multi_indices_index_false(self, expected_html): # GH 22579 df = _test_helper_dataframe_index_names( 'unnamed_multi', 'unnamed_multi') result = df.to_html(index=False) - assert result == dedent( - _EXPECTED_BASIC_ALIGNMENT['index_none_columns_unnamed_multi']) + assert result == expected_html('index_none_columns_unnamed_multi') @pytest.mark.parametrize('index_names', [True, False]) @pytest.mark.parametrize('header', [True]) From 2452affd3c62ef6d5c7c085a983410eda9a92019 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 14 Sep 2018 21:19:09 +0100 Subject: [PATCH 62/94] WIP add test fixtures --- pandas/tests/io/formats/test_to_html.py | 138 +++++++++++++++--------- 1 file changed, 88 insertions(+), 50 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 7646ef2a84ef8..b0a82a0edfee7 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -12,6 +12,8 @@ from pandas.compat import u, lrange, StringIO from pandas.util import testing as tm import pandas.io.formats.format as fmt +import pandas.core.common as com +from pandas.core.dtypes.generic import ABCMultiIndex div_style = '' try: @@ -22,6 +24,18 @@ pass +def _has_names(index): + if isinstance(index, ABCMultiIndex): + return com._any_not_none(*index.names) + else: + return index.name is not None + + +def _index_init_params(index): + return (isinstance(index, ABCMultiIndex), + _has_names(index)) + + @pytest.fixture def read_file(datapath): @@ -43,34 +57,60 @@ def _expected_html(name): return _expected_html -def _test_helper_dataframe_index_names(idx_type, col_idx_type): - df = DataFrame(np.zeros((2, 2), dtype=int)) - - if idx_type == 'named_standard': - df.index.name = 'index.name' - elif idx_type == 'unnamed_standard': - pass - elif idx_type == 'named_multi': - df.index = MultiIndex.from_product([['a'], ['b', 'c']], names=[ - 'index.name.0', 'index.name.1']) - elif idx_type == 'unnamed_multi': - df.index = MultiIndex.from_product([['a'], ['b', 'c']]) - else: - raise ValueError - - if col_idx_type == 'named_standard': - df.columns.name = 'columns.name' - elif col_idx_type == 'unnamed_standard': - pass - elif col_idx_type == 'named_multi': - df.columns = MultiIndex.from_product([['a'], ['b', 'c']], names=[ +@pytest.fixture(params=[True, False]) +def index(request): + # to_html() parameter values for index + # whether to print index (row) labels, default True + return request.param + + +@pytest.fixture(params=[True, False]) +def header(request): + # to_html() parameter values for header + # whether to print column labels, default True + return request.param + + +@pytest.fixture(params=[True, False]) +def index_names(request): + # to_html() parameter values for index_names + # prints the names of the indexes, default True + return request.param + + +@pytest.fixture(params=[ + Index([0, 1]), + Index([0, 1], name='index.name'), + MultiIndex.from_product([['a'], ['b', 'c']]), + MultiIndex.from_product([['a'], ['b', 'c']], names=[ + 'index.name.0', 'index.name.1']) +], + ids=['index_unnamed_standard', + 'index_named_standard', + 'index_unnamed_multi', + 'index_named_multi']) +def idx_type(request): + # standard and multiIndex index, named and unnamed + # used for basic table alignment tests + return request.param + + +@pytest.fixture( + params=[ + Index([0, 1]), + Index([0, 1], name='columns.name'), + MultiIndex.from_product([['a'], ['b', 'c']]), + MultiIndex.from_product([['a'], ['b', 'c']], names=[ 'columns.name.0', 'columns.name.1']) - elif col_idx_type == 'unnamed_multi': - df.columns = MultiIndex.from_product([['a'], ['b', 'c']]) - else: - raise ValueError - - return df + ], + ids=['columns_unnamed_standard', + 'columns_named_standard', + 'columns_unnamed_multi', + 'columns_named_multi']) +def col_idx_type(request): + # standard and multiIndex columns index, named and unnamed + # used for basic table alignment tests + return request.param class TestToHTML(object): @@ -1956,37 +1996,35 @@ def test_to_html_multiindex_max_cols(self): """) assert result == expected - def test_to_html_multi_indices_index_false(self, expected_html): - # GH 22579 - df = _test_helper_dataframe_index_names( - 'unnamed_multi', 'unnamed_multi') - result = df.to_html(index=False) - assert result == expected_html('index_none_columns_unnamed_multi') + # def test_to_html_multi_indices_index_false(self, idx_type, col_idx_type, + # expected_html): + # # GH 22579 + # df = DataFrame(np.zeros((2, 2), dtype=int), + # index=idx_type, columns=col_idx_type) + # result = df.to_html(index=False) + # assert result == expected_html('index_none_columns_unnamed_multi') - @pytest.mark.parametrize('index_names', [True, False]) @pytest.mark.parametrize('header', [True]) - @pytest.mark.parametrize('index', [True, False]) - @pytest.mark.parametrize('col_idx_type', ['unnamed_standard', - 'named_standard', - 'unnamed_multi', - 'named_multi']) - @pytest.mark.parametrize('idx_type', ['unnamed_standard', - 'named_standard', - 'unnamed_multi', - 'named_multi']) - def test_to_html_index_names(self, expected_html, idx_type, col_idx_type, - index, header, index_names): - df = _test_helper_dataframe_index_names(idx_type, col_idx_type) - + def test_to_html_index_names(self, expected_html, + idx_type, col_idx_type, index, header, + index_names): + df = DataFrame(np.zeros((2, 2), dtype=int), + index=idx_type, columns=col_idx_type) result = df.to_html(index=index, header=header, index_names=index_names) def _expected(idx_type, index, index_names): + is_multi, is_named = _index_init_params(idx_type) if index is False: return 'none' - if idx_type.startswith('named') and index_names is False: - return idx_type.replace('named', 'unnamed') - return idx_type + + idx_type_ids = { + (False, False): 'unnamed_standard', + (True, False): 'named_standard', + (False, True): 'unnamed_multi', + (True, True): 'named_multi'} + + return idx_type_ids[(is_named and index_names, is_multi)] expected = expected_html( '_'.join([ From 9a0512c3ab19e55594ee64ae06897578b6b7c361 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 14 Sep 2018 21:37:45 +0100 Subject: [PATCH 63/94] WIP add test fixtures --- pandas/tests/io/formats/test_to_html.py | 97 ++++++++++++++++--------- 1 file changed, 64 insertions(+), 33 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index b0a82a0edfee7..fee2c98c19520 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -38,7 +38,6 @@ def _index_init_params(index): @pytest.fixture def read_file(datapath): - def _read_file(filename): filepath = datapath('io', 'formats', 'data', filename) with open(filepath) as f: @@ -49,7 +48,6 @@ def _read_file(filename): @pytest.fixture def expected_html(read_file): - def _expected_html(name): filename = '.'.join([name, 'html']) html = read_file(filename) @@ -57,21 +55,22 @@ def _expected_html(name): return _expected_html -@pytest.fixture(params=[True, False]) +@pytest.fixture(params=[True, False], ids=['index_true', 'index_false']) def index(request): # to_html() parameter values for index # whether to print index (row) labels, default True return request.param -@pytest.fixture(params=[True, False]) +@pytest.fixture(params=[True, False], ids=['header_true', 'header_false']) def header(request): # to_html() parameter values for header # whether to print column labels, default True return request.param -@pytest.fixture(params=[True, False]) +@pytest.fixture(params=[True, False], ids=['index_names_true', + 'index_names_false']) def index_names(request): # to_html() parameter values for index_names # prints the names of the indexes, default True @@ -113,6 +112,35 @@ def col_idx_type(request): return request.param +@pytest.fixture +def expected_output(expected_html): + def _expected_output(idx_type, col_idx_type, + index=True, header=True, index_names=True): + + def _expected_output_name(idx_type, index, index_names): + is_multi, is_named = _index_init_params(idx_type) + if index is False: + return 'none' + + idx_type_ids = { + (False, False): 'unnamed_standard', + (True, False): 'named_standard', + (False, True): 'unnamed_multi', + (True, True): 'named_multi'} + + return idx_type_ids[(is_named and index_names, is_multi)] + + return expected_html( + '_'.join([ + 'index', + _expected_output_name(idx_type, index, index_names), + 'columns', + _expected_output_name(col_idx_type, header, index_names) + ]) + ) + return _expected_output + + class TestToHTML(object): def test_to_html_with_col_space(self): @@ -2004,38 +2032,41 @@ def test_to_html_multiindex_max_cols(self): # result = df.to_html(index=False) # assert result == expected_html('index_none_columns_unnamed_multi') - @pytest.mark.parametrize('header', [True]) - def test_to_html_index_names(self, expected_html, - idx_type, col_idx_type, index, header, - index_names): + # @pytest.mark.parametrize('header', [False]) + # def test_to_html_index_names(self, expected_output, + # idx_type, col_idx_type, index, header, + # index_names): + # df = DataFrame(np.zeros((2, 2), dtype=int), + # index=idx_type, columns=col_idx_type) + # result = df.to_html(index=index, header=header, + # index_names=index_names) + # assert result == expected_output(idx_type, col_idx_type, + # index=index, header=header, + # index_names=index_names) + + def test_to_html_index_names_with_defaults(self, expected_output, + idx_type, col_idx_type): df = DataFrame(np.zeros((2, 2), dtype=int), index=idx_type, columns=col_idx_type) - result = df.to_html(index=index, header=header, - index_names=index_names) - - def _expected(idx_type, index, index_names): - is_multi, is_named = _index_init_params(idx_type) - if index is False: - return 'none' - - idx_type_ids = { - (False, False): 'unnamed_standard', - (True, False): 'named_standard', - (False, True): 'unnamed_multi', - (True, True): 'named_multi'} - - return idx_type_ids[(is_named and index_names, is_multi)] + result = df.to_html() + assert result == expected_output(idx_type, col_idx_type) - expected = expected_html( - '_'.join([ - 'index', - _expected(idx_type, index, index_names), - 'columns', - _expected(col_idx_type, header, index_names) - ]) - ) + def test_to_html_index_names_false(self, expected_output, + idx_type, col_idx_type): + df = DataFrame(np.zeros((2, 2), dtype=int), + index=idx_type, columns=col_idx_type) + result = df.to_html(index_names=False) + assert result == expected_output( + idx_type, col_idx_type, index_names=False) - assert result == expected + def test_to_html_index_names_index_false(self, expected_output, + idx_type, col_idx_type, + index_names): + df = DataFrame(np.zeros((2, 2), dtype=int), + index=idx_type, columns=col_idx_type) + result = df.to_html(index=False, index_names=index_names) + assert result == expected_output(idx_type, col_idx_type, + index=False, index_names=index_names) def test_to_html_notebook_has_style(self): df = pd.DataFrame({"A": [1, 2, 3]}) From f94e3369af870f7b1cf44269afa97df878d2cc7e Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sat, 15 Sep 2018 12:58:57 +0100 Subject: [PATCH 64/94] add test --- .../formats/data/gh22579_expected_output.html | 76 +++++++++++++++++++ ...index_named_multi_columns_named_multi.html | 1 - pandas/tests/io/formats/test_to_html.py | 16 ++-- 3 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 pandas/tests/io/formats/data/gh22579_expected_output.html diff --git a/pandas/tests/io/formats/data/gh22579_expected_output.html b/pandas/tests/io/formats/data/gh22579_expected_output.html new file mode 100644 index 0000000000000..425b0f915ed16 --- /dev/null +++ b/pandas/tests/io/formats/data/gh22579_expected_output.html @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ab
cdcd
0101010
1111111
2121212
3131313
4141414
5151515
6161616
7171717
8181818
9191919
diff --git a/pandas/tests/io/formats/data/index_named_multi_columns_named_multi.html b/pandas/tests/io/formats/data/index_named_multi_columns_named_multi.html index 04ba2880753e6..817b54d77f8b1 100644 --- a/pandas/tests/io/formats/data/index_named_multi_columns_named_multi.html +++ b/pandas/tests/io/formats/data/index_named_multi_columns_named_multi.html @@ -32,4 +32,3 @@ - \ No newline at end of file diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index fee2c98c19520..d42527b4ebe16 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2024,13 +2024,15 @@ def test_to_html_multiindex_max_cols(self): """) assert result == expected - # def test_to_html_multi_indices_index_false(self, idx_type, col_idx_type, - # expected_html): - # # GH 22579 - # df = DataFrame(np.zeros((2, 2), dtype=int), - # index=idx_type, columns=col_idx_type) - # result = df.to_html(index=False) - # assert result == expected_html('index_none_columns_unnamed_multi') + def test_to_html_multi_indexes_index_false(self, expected_html): + # GH 22579 + df = pd.DataFrame({'a': range(10), 'b': range( + 10, 20), 'c': range(10, 20), 'd': range(10, 20)}) + df.columns = pd.MultiIndex.from_product([['a', 'b'], ['c', 'd']]) + df.index = pd.MultiIndex.from_product( + [['a', 'b'], ['c', 'd', 'e', 'f', 'g']]) + result = df.to_html(index=False) + assert result == expected_html('gh22579_expected_output') # @pytest.mark.parametrize('header', [False]) # def test_to_html_index_names(self, expected_output, From db32821fe288ba3ec8fef18e69688b652a1607f9 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sat, 15 Sep 2018 14:10:34 +0100 Subject: [PATCH 65/94] refactor test --- pandas/tests/io/formats/test_to_html.py | 45 ++++++------------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index d42527b4ebe16..7c5ce6f65d4db 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -13,7 +13,6 @@ from pandas.util import testing as tm import pandas.io.formats.format as fmt import pandas.core.common as com -from pandas.core.dtypes.generic import ABCMultiIndex div_style = '' try: @@ -25,14 +24,14 @@ def _has_names(index): - if isinstance(index, ABCMultiIndex): + if index.nlevels > 1: return com._any_not_none(*index.names) else: return index.name is not None def _index_init_params(index): - return (isinstance(index, ABCMultiIndex), + return (index.nlevels > 1, _has_names(index)) @@ -2034,41 +2033,17 @@ def test_to_html_multi_indexes_index_false(self, expected_html): result = df.to_html(index=False) assert result == expected_html('gh22579_expected_output') - # @pytest.mark.parametrize('header', [False]) - # def test_to_html_index_names(self, expected_output, - # idx_type, col_idx_type, index, header, - # index_names): - # df = DataFrame(np.zeros((2, 2), dtype=int), - # index=idx_type, columns=col_idx_type) - # result = df.to_html(index=index, header=header, - # index_names=index_names) - # assert result == expected_output(idx_type, col_idx_type, - # index=index, header=header, - # index_names=index_names) - - def test_to_html_index_names_with_defaults(self, expected_output, - idx_type, col_idx_type): + @pytest.mark.parametrize('header', [True]) + def test_to_html_index_names(self, expected_output, + idx_type, col_idx_type, index, header, + index_names): df = DataFrame(np.zeros((2, 2), dtype=int), index=idx_type, columns=col_idx_type) - result = df.to_html() - assert result == expected_output(idx_type, col_idx_type) - - def test_to_html_index_names_false(self, expected_output, - idx_type, col_idx_type): - df = DataFrame(np.zeros((2, 2), dtype=int), - index=idx_type, columns=col_idx_type) - result = df.to_html(index_names=False) - assert result == expected_output( - idx_type, col_idx_type, index_names=False) - - def test_to_html_index_names_index_false(self, expected_output, - idx_type, col_idx_type, - index_names): - df = DataFrame(np.zeros((2, 2), dtype=int), - index=idx_type, columns=col_idx_type) - result = df.to_html(index=False, index_names=index_names) + result = df.to_html(index=index, header=header, + index_names=index_names) assert result == expected_output(idx_type, col_idx_type, - index=False, index_names=index_names) + index=index, header=header, + index_names=index_names) def test_to_html_notebook_has_style(self): df = pd.DataFrame({"A": [1, 2, 3]}) From 2546d827bf6deca2c2c0106582e0aeb29aee67bb Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sat, 15 Sep 2018 16:34:54 +0100 Subject: [PATCH 66/94] move read_file fixture factory into conftest.py --- pandas/tests/io/formats/conftest.py | 12 ++++++++++++ pandas/tests/io/formats/test_to_html.py | 10 ---------- 2 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 pandas/tests/io/formats/conftest.py diff --git a/pandas/tests/io/formats/conftest.py b/pandas/tests/io/formats/conftest.py new file mode 100644 index 0000000000000..79afd2e95c08f --- /dev/null +++ b/pandas/tests/io/formats/conftest.py @@ -0,0 +1,12 @@ +import pytest + + +@pytest.fixture +def read_file(datapath): + """fixture factory to read text files from tests/io/formats/data""" + def _read_file(filename): + filepath = datapath('io', 'formats', 'data', filename) + with open(filepath) as f: + contents = f.read() + return contents + return _read_file diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 7c5ce6f65d4db..b2fb1766d1ded 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -35,16 +35,6 @@ def _index_init_params(index): _has_names(index)) -@pytest.fixture -def read_file(datapath): - def _read_file(filename): - filepath = datapath('io', 'formats', 'data', filename) - with open(filepath) as f: - contents = f.read() - return contents - return _read_file - - @pytest.fixture def expected_html(read_file): def _expected_html(name): From 483ace8ded10fe51fbe00d8aa449055762c11a11 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 17 Sep 2018 20:36:43 +0100 Subject: [PATCH 67/94] update expected output --- .../tests/io/formats/data/index_none_columns_named_multi.html | 4 ++-- .../io/formats/data/index_none_columns_named_standard.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/io/formats/data/index_none_columns_named_multi.html b/pandas/tests/io/formats/data/index_none_columns_named_multi.html index cb19a95bf5d18..e111f55be7d25 100644 --- a/pandas/tests/io/formats/data/index_none_columns_named_multi.html +++ b/pandas/tests/io/formats/data/index_none_columns_named_multi.html @@ -12,12 +12,12 @@ - + 0 0 - + 0 0 diff --git a/pandas/tests/io/formats/data/index_none_columns_named_standard.html b/pandas/tests/io/formats/data/index_none_columns_named_standard.html index cff4d2372acec..d3a9ba017b43e 100644 --- a/pandas/tests/io/formats/data/index_none_columns_named_standard.html +++ b/pandas/tests/io/formats/data/index_none_columns_named_standard.html @@ -8,12 +8,12 @@ - + 0 0 - + 0 0 From 96b5442a570b3b619a881947d1638a2b0c34f760 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 17 Sep 2018 23:58:35 +0100 Subject: [PATCH 68/94] fix failing tests --- pandas/io/formats/html.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 02a8533f566db..994e8ebf712f2 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -353,11 +353,14 @@ def _write_body(self, indent): else: self._write_regular_rows(fmt_values, indent) else: + row_levels = 0 for i in range(min(len(self.frame), self.max_rows)): row = [fmt_values[j][i] for j in range(len(self.columns))] if self.show_col_idx_names: row.insert(0, '') - self.write_tr(row, indent, self.indent_delta, tags=None) + row_levels = 1 + self.write_tr(row, indent, self.indent_delta, + tags=None, nindex_levels=row_levels) indent -= self.indent_delta self.write('', indent) From 00d452c5726083dac9b1e09892b3c138168b0275 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 18 Sep 2018 00:20:28 +0100 Subject: [PATCH 69/94] refactor --- pandas/io/formats/html.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 994e8ebf712f2..305d45882609e 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -287,12 +287,13 @@ def _column_header(): values = (values[:ins_col] + [u('...')] + values[ins_col:]) - name = self.columns.names[lnum] + if self.show_col_idx_names: + name = self.columns.names[lnum] + else: + name = None row = [''] * (row_levels - 1) + ['' if name is None else pprint_thing(name)] - if self.show_col_idx_names is False: - row[-1] = '' if self.fmt.index is False: if self.show_col_idx_names: row = row[-1:] From 3d1d5c4c5964e7e351fa7891586307141963e33e Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 18 Sep 2018 01:29:36 +0100 Subject: [PATCH 70/94] refactor --- pandas/io/formats/html.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 305d45882609e..bfb5d0a39831c 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -200,6 +200,8 @@ def write_result(self, buf): def _write_header(self, indent): truncate_h = self.fmt.truncate_h row_levels = self.frame.index.nlevels + if self.show_col_idx_names and not self.fmt.index: + row_levels = 1 if not self.fmt.header: # write nothing return indent @@ -294,11 +296,8 @@ def _column_header(): row = [''] * (row_levels - 1) + ['' if name is None else pprint_thing(name)] - if self.fmt.index is False: - if self.show_col_idx_names: - row = row[-1:] - else: - row = [] + if not (self.show_col_idx_names or self.fmt.index): + row = [] tags = {} j = len(row) From 5dcd1464c1cc56df539e554bfa5efcb55c4f9ca9 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 19 Sep 2018 23:08:13 +0100 Subject: [PATCH 71/94] requested change --- pandas/tests/io/formats/test_to_html.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index b2fb1766d1ded..b17f7b9f625fb 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -2021,7 +2021,8 @@ def test_to_html_multi_indexes_index_false(self, expected_html): df.index = pd.MultiIndex.from_product( [['a', 'b'], ['c', 'd', 'e', 'f', 'g']]) result = df.to_html(index=False) - assert result == expected_html('gh22579_expected_output') + expected = expected_html('gh22579_expected_output') + assert result == expected @pytest.mark.parametrize('header', [True]) def test_to_html_index_names(self, expected_output, @@ -2031,9 +2032,10 @@ def test_to_html_index_names(self, expected_output, index=idx_type, columns=col_idx_type) result = df.to_html(index=index, header=header, index_names=index_names) - assert result == expected_output(idx_type, col_idx_type, - index=index, header=header, - index_names=index_names) + expected = expected_output(idx_type, col_idx_type, + index=index, header=header, + index_names=index_names) + assert result == expected def test_to_html_notebook_has_style(self): df = pd.DataFrame({"A": [1, 2, 3]}) From 5327098152cc5fda7f86c34cb7cce180bcee446b Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 19 Sep 2018 23:13:50 +0100 Subject: [PATCH 72/94] add comments --- pandas/io/formats/html.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index bfb5d0a39831c..b4bfccc38c8e5 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -47,6 +47,7 @@ def __init__(self, formatter, classes=None, max_rows=None, max_cols=None, border = get_option('display.html.border') self.border = border self.table_id = table_id + # GH 22579 self.show_col_idx_names = all((self.fmt.has_column_names, self.fmt.show_index_names, self.fmt.header)) @@ -200,6 +201,7 @@ def write_result(self, buf): def _write_header(self, indent): truncate_h = self.fmt.truncate_h row_levels = self.frame.index.nlevels +# GH 22579 TODO:additional tests for effect of changing row_levels if self.show_col_idx_names and not self.fmt.index: row_levels = 1 if not self.fmt.header: @@ -315,6 +317,7 @@ def _column_header(): col_row = _column_header() align = self.fmt.justify +# GH 22579 TODO:additional tests for effect of changing row_levels if truncate_h: ins_col = row_levels + self.fmt.tr_col_num col_row.insert(ins_col, '...') @@ -328,6 +331,7 @@ def _column_header(): row = ([x if x is not None else '' for x in self.frame.index.names] + [''] * min(len(self.columns), self.max_cols)) +# GH 22579 TODO:additional tests for effect of changing row_levels if truncate_h: ins_col = row_levels + self.fmt.tr_col_num row.insert(ins_col, '') From 0961db7d41a89d2c098ff045eae7fb59dfe6cf86 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 20 Sep 2018 12:27:48 +0100 Subject: [PATCH 73/94] refactor --- pandas/io/formats/html.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index b4bfccc38c8e5..79c6a80f164ac 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -358,11 +358,12 @@ def _write_body(self, indent): self._write_regular_rows(fmt_values, indent) else: row_levels = 0 + if self.show_col_idx_names: + row_levels = 1 +# GH 22579 TODO:no truncation logic. needs fixing first. for i in range(min(len(self.frame), self.max_rows)): - row = [fmt_values[j][i] for j in range(len(self.columns))] - if self.show_col_idx_names: - row.insert(0, '') - row_levels = 1 + row = [''] * row_levels + [fmt_values[j][i] + for j in range(len(self.columns))] self.write_tr(row, indent, self.indent_delta, tags=None, nindex_levels=row_levels) From 677472ac889652281dbc31f2d6555da022f4ee98 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 16 Nov 2018 15:51:06 +0000 Subject: [PATCH 74/94] (wip) remove conftest.py --- pandas/tests/io/formats/conftest.py | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 pandas/tests/io/formats/conftest.py diff --git a/pandas/tests/io/formats/conftest.py b/pandas/tests/io/formats/conftest.py deleted file mode 100644 index 79afd2e95c08f..0000000000000 --- a/pandas/tests/io/formats/conftest.py +++ /dev/null @@ -1,12 +0,0 @@ -import pytest - - -@pytest.fixture -def read_file(datapath): - """fixture factory to read text files from tests/io/formats/data""" - def _read_file(filename): - filepath = datapath('io', 'formats', 'data', filename) - with open(filepath) as f: - contents = f.read() - return contents - return _read_file From 5ec0c575184e7df91648930afa60193014df31ed Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 16 Nov 2018 16:58:16 +0000 Subject: [PATCH 75/94] (wip) refactor test --- pandas/tests/io/formats/test_to_html.py | 76 +++++++++---------------- 1 file changed, 27 insertions(+), 49 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index e9f5563b59f23..055f254b09689 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -23,18 +23,6 @@ pass -def _has_names(index): - if index.nlevels > 1: - return com._any_not_none(*index.names) - else: - return index.name is not None - - -def _index_init_params(index): - return (index.nlevels > 1, - _has_names(index)) - - @pytest.fixture(params=[True, False], ids=['index_true', 'index_false']) def index(request): # to_html() parameter values for index @@ -92,37 +80,6 @@ def col_idx_type(request): return request.param -@pytest.fixture -def expected_output(datapath): - def _expected_output(idx_type, col_idx_type, - index=True, header=True, index_names=True): - - def _expected_output_name(idx_type, index, index_names): - is_multi, is_named = _index_init_params(idx_type) - if index is False: - return 'none' - - idx_type_ids = { - (False, False): 'unnamed_standard', - (True, False): 'named_standard', - (False, True): 'unnamed_multi', - (True, True): 'named_multi'} - - return idx_type_ids[(is_named and index_names, is_multi)] - - return expected_html(datapath, - '_'.join([ - 'index', - _expected_output_name( - idx_type, index, index_names), - 'columns', - _expected_output_name( - col_idx_type, header, index_names) - ]) - ) - return _expected_output - - def expected_html(datapath, name): """ Read HTML file from formats data directory. @@ -2016,16 +1973,37 @@ def test_to_html_multi_indexes_index_false(self, datapath): assert result == expected @pytest.mark.parametrize('header', [True]) - def test_to_html_index_names(self, expected_output, - idx_type, col_idx_type, index, header, - index_names): + def test_to_html_basic_alignment(self, datapath, idx_type, col_idx_type, + index, header, index_names): + + def _exp_name(idx_type, index, index_names): + idx_type_ids = { + (False, False): 'unnamed_standard', + (True, False): 'named_standard', + (False, True): 'unnamed_multi', + (True, True): 'named_multi' + } + + if index: + if idx_type.nlevels > 1: + has_names = com._any_not_none(*idx_type.names) + else: + has_names = idx_type.name is not None + return idx_type_ids[(has_names and index_names, + idx_type.nlevels > 1)] + else: + return 'none' + df = DataFrame(np.zeros((2, 2), dtype=int), index=idx_type, columns=col_idx_type) result = df.to_html(index=index, header=header, index_names=index_names) - expected = expected_output(idx_type, col_idx_type, - index=index, header=header, - index_names=index_names) + filename = '_'.join(['index', + _exp_name(idx_type, index, index_names), + 'columns', + _exp_name(col_idx_type, header, index_names) + ]) + expected = expected_html(datapath, filename) assert result == expected @pytest.mark.parametrize('index', [False, 0]) From 72d485dccc58da394aa4427cee55cb2b814722c9 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 16 Nov 2018 17:14:37 +0000 Subject: [PATCH 76/94] (wip) refactor test --- pandas/tests/io/formats/test_to_html.py | 61 ++++++++++--------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 055f254b09689..7b9b145d155a2 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -45,41 +45,6 @@ def index_names(request): return request.param -@pytest.fixture(params=[ - Index([0, 1]), - Index([0, 1], name='index.name'), - MultiIndex.from_product([['a'], ['b', 'c']]), - MultiIndex.from_product([['a'], ['b', 'c']], names=[ - 'index.name.0', 'index.name.1']) -], - ids=['index_unnamed_standard', - 'index_named_standard', - 'index_unnamed_multi', - 'index_named_multi']) -def idx_type(request): - # standard and multiIndex index, named and unnamed - # used for basic table alignment tests - return request.param - - -@pytest.fixture( - params=[ - Index([0, 1]), - Index([0, 1], name='columns.name'), - MultiIndex.from_product([['a'], ['b', 'c']]), - MultiIndex.from_product([['a'], ['b', 'c']], names=[ - 'columns.name.0', 'columns.name.1']) - ], - ids=['columns_unnamed_standard', - 'columns_named_standard', - 'columns_unnamed_multi', - 'columns_named_multi']) -def col_idx_type(request): - # standard and multiIndex columns index, named and unnamed - # used for basic table alignment tests - return request.param - - def expected_html(datapath, name): """ Read HTML file from formats data directory. @@ -1972,7 +1937,31 @@ def test_to_html_multi_indexes_index_false(self, datapath): expected = expected_html(datapath, 'gh22579_expected_output') assert result == expected - @pytest.mark.parametrize('header', [True]) + @pytest.mark.parametrize('col_idx_type', + [Index([0, 1]), + Index([0, 1], name='columns.name'), + MultiIndex.from_product([['a'], ['b', 'c']]), + MultiIndex.from_product([['a'], ['b', 'c']], + names=['columns.name.0', + 'columns.name.1']) + ], + ids=['columns_unnamed_standard', + 'columns_named_standard', + 'columns_unnamed_multi', + 'columns_named_multi']) + @pytest.mark.parametrize('idx_type', + [Index([0, 1]), + Index([0, 1], name='index.name'), + MultiIndex.from_product([['a'], ['b', 'c']]), + MultiIndex.from_product([['a'], ['b', 'c']], + names=['index.name.0', + 'index.name.1']) + ], + ids=['index_unnamed_standard', + 'index_named_standard', + 'index_unnamed_multi', + 'index_named_multi']) + @pytest.mark.parametrize('header', [True], ids=['header_true']) def test_to_html_basic_alignment(self, datapath, idx_type, col_idx_type, index, header, index_names): From dd84b8d60a978823eb3e6ac87ce4953c0fe83d6b Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sat, 17 Nov 2018 17:11:56 +0000 Subject: [PATCH 77/94] (wip) add tests with truncation --- pandas/io/formats/html.py | 31 +++---- .../gh22579_truncation_index_false_named.html | 66 ++++++++++++++ ...h22579_truncation_index_false_unnamed.html | 58 ++++++++++++ .../data/gh22579_truncation_index_true.html | 88 +++++++++++++++++++ pandas/tests/io/formats/test_to_html.py | 30 +++++-- 5 files changed, 253 insertions(+), 20 deletions(-) create mode 100644 pandas/tests/io/formats/data/gh22579_truncation_index_false_named.html create mode 100644 pandas/tests/io/formats/data/gh22579_truncation_index_false_unnamed.html create mode 100644 pandas/tests/io/formats/data/gh22579_truncation_index_true.html diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 4030dfa8703c1..bc36c7fca7b28 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -46,7 +46,6 @@ def __init__(self, formatter, classes=None, max_rows=None, max_cols=None, border = get_option('display.html.border') self.border = border self.table_id = table_id - # GH 22579 self.show_col_idx_names = all((self.fmt.has_column_names, self.fmt.show_index_names, self.fmt.header)) @@ -199,10 +198,14 @@ def write_result(self, buf): def _write_header(self, indent): truncate_h = self.fmt.truncate_h - row_levels = self.frame.index.nlevels -# GH 22579 TODO:additional tests for effect of changing row_levels - if self.show_col_idx_names and not self.fmt.index: + + if self.fmt.index: + row_levels = self.frame.index.nlevels + elif self.show_col_idx_names: row_levels = 1 + else: + row_levels = 0 + if not self.fmt.header: # write nothing return indent @@ -223,9 +226,10 @@ def _column_header(): for c in self.columns]) else: if self.fmt.index or self.show_col_idx_names: - row.append(self.columns.name or '') - if self.show_col_idx_names is False: - row[-1] = '' + if self.fmt.show_index_names: + row.append(self.columns.name or '') + else: + row.append('') row.extend(self.columns) return row @@ -290,14 +294,15 @@ def _column_header(): values = (values[:ins_col] + [u('...')] + values[ins_col:]) - if self.show_col_idx_names: + if self.fmt.show_index_names: name = self.columns.names[lnum] else: name = None - row = [''] * (row_levels - 1) + ['' if name is None else - pprint_thing(name)] - if not (self.show_col_idx_names or self.fmt.index): + if self.fmt.index or self.show_col_idx_names: + row = [''] * (row_levels - 1) + ['' if name is None else + pprint_thing(name)] + else: row = [] tags = {} @@ -316,10 +321,7 @@ def _column_header(): col_row = _column_header() align = self.fmt.justify -# GH 22579 TODO:additional tests for effect of changing row_levels if truncate_h: - if not self.fmt.index: - row_levels = 0 ins_col = row_levels + self.fmt.tr_col_num col_row.insert(ins_col, '...') @@ -332,7 +334,6 @@ def _column_header(): row = ([x if x is not None else '' for x in self.frame.index.names] + [''] * min(len(self.columns), self.max_cols)) -# GH 22579 TODO:additional tests for effect of changing row_levels if truncate_h: ins_col = row_levels + self.fmt.tr_col_num row.insert(ins_col, '') diff --git a/pandas/tests/io/formats/data/gh22579_truncation_index_false_named.html b/pandas/tests/io/formats/data/gh22579_truncation_index_false_named.html new file mode 100644 index 0000000000000..6640db4cf8704 --- /dev/null +++ b/pandas/tests/io/formats/data/gh22579_truncation_index_false_named.html @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
fooa...b
c...d
bazef...ef
01...67
89...1415
..................
4849...5455
5657...6263
diff --git a/pandas/tests/io/formats/data/gh22579_truncation_index_false_unnamed.html b/pandas/tests/io/formats/data/gh22579_truncation_index_false_unnamed.html new file mode 100644 index 0000000000000..8c9a9e244277b --- /dev/null +++ b/pandas/tests/io/formats/data/gh22579_truncation_index_false_unnamed.html @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
a...b
c...d
ef...ef
01...67
89...1415
...............
4849...5455
5657...6263
diff --git a/pandas/tests/io/formats/data/gh22579_truncation_index_true.html b/pandas/tests/io/formats/data/gh22579_truncation_index_true.html new file mode 100644 index 0000000000000..e66d3c816e67d --- /dev/null +++ b/pandas/tests/io/formats/data/gh22579_truncation_index_true.html @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
fooa...b
c...d
bazef...ef
foobaz
ace01...67
f89...1415
........................
bde4849...5455
f5657...6263
diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 7b9b145d155a2..9707fc34cd7c1 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -1928,15 +1928,35 @@ def test_to_html_multiindex_max_cols(self): def test_to_html_multi_indexes_index_false(self, datapath): # GH 22579 - df = pd.DataFrame({'a': range(10), 'b': range( - 10, 20), 'c': range(10, 20), 'd': range(10, 20)}) - df.columns = pd.MultiIndex.from_product([['a', 'b'], ['c', 'd']]) - df.index = pd.MultiIndex.from_product( - [['a', 'b'], ['c', 'd', 'e', 'f', 'g']]) + df = DataFrame({'a': range(10), 'b': range(10, 20), 'c': range(10, 20), + 'd': range(10, 20)}) + df.columns = MultiIndex.from_product([['a', 'b'], ['c', 'd']]) + df.index = MultiIndex.from_product([['a', 'b'], + ['c', 'd', 'e', 'f', 'g']]) result = df.to_html(index=False) expected = expected_html(datapath, 'gh22579_expected_output') assert result == expected + index = MultiIndex.from_product([['a', 'b'], ['c', 'd'], ['e', 'f']], + names=['foo', None, 'baz']) + df = DataFrame(np.arange(64).reshape(8, 8), index=index, columns=index) + result = df.to_html(max_rows=4, max_cols=4, index=True) + expected = expected_html(datapath, 'gh22579_truncation_index_true') + assert result == expected + + df = DataFrame(np.arange(64).reshape(8, 8), index=index, columns=index) + result = df.to_html(max_rows=4, max_cols=4, index=False) + expected = expected_html(datapath, + 'gh22579_truncation_index_false_named') + assert result == expected + + index = MultiIndex.from_product([['a', 'b'], ['c', 'd'], ['e', 'f']]) + df = DataFrame(np.arange(64).reshape(8, 8), index=index, columns=index) + result = df.to_html(max_rows=4, max_cols=4, index=False) + expected = expected_html(datapath, + 'gh22579_truncation_index_false_unnamed') + assert result == expected + @pytest.mark.parametrize('col_idx_type', [Index([0, 1]), Index([0, 1], name='columns.name'), From 9b7eaaef1432e3e516a0d7cd41a2754400797c8b Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 18 Nov 2018 11:49:00 +0000 Subject: [PATCH 78/94] (wip) parametrize truncation tests --- pandas/tests/io/formats/test_to_html.py | 29 +++++++++++-------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 728d9bbac426f..96dbd952a1a76 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -449,24 +449,21 @@ def test_to_html_multi_indexes_index_false(self, datapath): expected = expected_html(datapath, 'gh22579_expected_output') assert result == expected + @pytest.mark.parametrize( + ('idx_flag', 'named_index', 'expected_output'), + [(True, True, 'gh22579_truncation_index_true'), + (False, True, 'gh22579_truncation_index_false_named'), + (False, False, 'gh22579_truncation_index_false_unnamed') + ]) + def test_to_html_multi_indexes_index_false_with_truncation( + self, datapath, idx_flag, named_index, expected_output): + # GH 22579 with truncation + names = ['foo', None, 'baz'] if named_index else None index = MultiIndex.from_product([['a', 'b'], ['c', 'd'], ['e', 'f']], - names=['foo', None, 'baz']) + names=names) df = DataFrame(np.arange(64).reshape(8, 8), index=index, columns=index) - result = df.to_html(max_rows=4, max_cols=4, index=True) - expected = expected_html(datapath, 'gh22579_truncation_index_true') - assert result == expected - - df = DataFrame(np.arange(64).reshape(8, 8), index=index, columns=index) - result = df.to_html(max_rows=4, max_cols=4, index=False) - expected = expected_html(datapath, - 'gh22579_truncation_index_false_named') - assert result == expected - - index = MultiIndex.from_product([['a', 'b'], ['c', 'd'], ['e', 'f']]) - df = DataFrame(np.arange(64).reshape(8, 8), index=index, columns=index) - result = df.to_html(max_rows=4, max_cols=4, index=False) - expected = expected_html(datapath, - 'gh22579_truncation_index_false_unnamed') + result = df.to_html(max_rows=4, max_cols=4, index=idx_flag) + expected = expected_html(datapath, expected_output) assert result == expected @pytest.mark.parametrize('col_idx_type', From 7383c8a4ac23e9040b70311e8f82d6c3d5ff498d Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 18 Nov 2018 13:00:20 +0000 Subject: [PATCH 79/94] (wip) refactor test helper --- pandas/tests/io/formats/test_to_html.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 96dbd952a1a76..c9b4d242d0cc5 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -495,22 +495,17 @@ def test_to_html_basic_alignment(self, datapath, idx_type, col_idx_type, index, header, index_names): def _exp_name(idx_type, index, index_names): - idx_type_ids = { - (False, False): 'unnamed_standard', - (True, False): 'named_standard', - (False, True): 'unnamed_multi', - (True, True): 'named_multi' - } - - if index: - if idx_type.nlevels > 1: - has_names = com._any_not_none(*idx_type.names) - else: - has_names = idx_type.name is not None - return idx_type_ids[(has_names and index_names, - idx_type.nlevels > 1)] - else: + # helper function to map test parameters to expected output + if not index: return 'none' + is_multi_index = idx_type.nlevels > 1 + if is_multi_index: + has_names = com._any_not_none(*idx_type.names) + else: + has_names = idx_type.name is not None + return '_'.join([ + 'named' if (has_names and index_names) else 'unnamed', + 'multi' if is_multi_index else 'standard']) df = DataFrame(np.zeros((2, 2), dtype=int), index=idx_type, columns=col_idx_type) From d89a180ab0c17719763e4f9301c442b2b082904b Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 18 Nov 2018 13:11:49 +0000 Subject: [PATCH 80/94] (wip) removed unused header parametrization --- pandas/tests/io/formats/test_to_html.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index c9b4d242d0cc5..ad5af5a8e483a 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -21,13 +21,6 @@ def index(request): return request.param -@pytest.fixture(params=[True, False], ids=['header_true', 'header_false']) -def header(request): - # to_html() parameter values for header - # whether to print column labels, default True - return request.param - - @pytest.fixture(params=[True, False], ids=['index_names_true', 'index_names_false']) def index_names(request): @@ -490,10 +483,8 @@ def test_to_html_multi_indexes_index_false_with_truncation( 'index_named_standard', 'index_unnamed_multi', 'index_named_multi']) - @pytest.mark.parametrize('header', [True], ids=['header_true']) def test_to_html_basic_alignment(self, datapath, idx_type, col_idx_type, - index, header, index_names): - + index, index_names): def _exp_name(idx_type, index, index_names): # helper function to map test parameters to expected output if not index: @@ -509,12 +500,11 @@ def _exp_name(idx_type, index, index_names): df = DataFrame(np.zeros((2, 2), dtype=int), index=idx_type, columns=col_idx_type) - result = df.to_html(index=index, header=header, - index_names=index_names) + result = df.to_html(index=index, index_names=index_names) filename = '_'.join(['index', _exp_name(idx_type, index, index_names), 'columns', - _exp_name(col_idx_type, header, index_names) + _exp_name(col_idx_type, True, index_names) ]) expected = expected_html(datapath, filename) assert result == expected From 24ba91ccce131d759ba7b49f8029daf2bb340fc5 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 18 Nov 2018 14:07:29 +0000 Subject: [PATCH 81/94] (wip) refactor --- pandas/io/formats/html.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index bc36c7fca7b28..ffb7fc97643bc 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -198,13 +198,10 @@ def write_result(self, buf): def _write_header(self, indent): truncate_h = self.fmt.truncate_h - if self.fmt.index: row_levels = self.frame.index.nlevels - elif self.show_col_idx_names: - row_levels = 1 else: - row_levels = 0 + row_levels = 1 if self.show_col_idx_names else 0 if not self.fmt.header: # write nothing @@ -294,16 +291,13 @@ def _column_header(): values = (values[:ins_col] + [u('...')] + values[ins_col:]) - if self.fmt.show_index_names: - name = self.columns.names[lnum] - else: - name = None - + row = [''] * (row_levels - 1) if self.fmt.index or self.show_col_idx_names: - row = [''] * (row_levels - 1) + ['' if name is None else - pprint_thing(name)] - else: - row = [] + if self.fmt.show_index_names: + name = self.columns.names[lnum] + row.append(pprint_thing(name or '')) + else: + row.append('') tags = {} j = len(row) @@ -377,10 +371,9 @@ def _write_regular_rows(self, fmt_values, indent): index_values = self.fmt.tr_frame.index.map(fmt) else: index_values = self.fmt.tr_frame.index.format() - - row_levels = 0 - if self.fmt.index or self.show_col_idx_names: row_levels = 1 + else: + row_levels = 1 if self.show_col_idx_names else 0 row = [] for i in range(nrows): From a4feea86201ccb9e6a54e3a0089a1130aeab333e Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 18 Nov 2018 19:11:46 +0000 Subject: [PATCH 82/94] add whatsnew entry --- doc/source/whatsnew/v0.24.0.rst | 2 ++ pandas/tests/io/formats/test_to_html.py | 1 + 2 files changed, 3 insertions(+) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index 98941b6d353bb..79ec57922b078 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1372,6 +1372,8 @@ Notice how we now instead output ``np.nan`` itself instead of a stringified form - :func:`read_sas()` will correctly parse sas7bdat files with data page types having also bit 7 set (so page type is 128 + 256 = 384) (:issue:`16615`) - Bug in :meth:`detect_client_encoding` where potential ``IOError`` goes unhandled when importing in a mod_wsgi process due to restricted access to stdout. (:issue:`21552`) - Bug in :func:`to_html()` with ``index=False`` misses truncation indicators (...) on truncated DataFrame (:issue:`15019`, :issue:`22783`) +- Bug in :func:`to_html()` with ``index=False`` when both columns and row index are MultiIndex (:issue:`22579`) +- Bug in :func:`to_html()` with ``index_names=False`` displaying index name (:issue:`22747`) - Bug in :func:`DataFrame.to_string()` that broke column alignment when ``index=False`` and width of first column's values is greater than the width of first column's header (:issue:`16839`, :issue:`13032`) - Bug in :func:`DataFrame.to_string()` that caused representations of :class:`DataFrame` to not take up the whole window (:issue:`22984`) - Bug in :func:`DataFrame.to_csv` where a single level MultiIndex incorrectly wrote a tuple. Now just the value of the index is written (:issue:`19589`). diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index ad5af5a8e483a..1d0998854d8be 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -485,6 +485,7 @@ def test_to_html_multi_indexes_index_false_with_truncation( 'index_named_multi']) def test_to_html_basic_alignment(self, datapath, idx_type, col_idx_type, index, index_names): + # GH 22747, GH 22579 def _exp_name(idx_type, index, index_names): # helper function to map test parameters to expected output if not index: From e00cbaf9e27e69d06881bde218e47141a2b3a89a Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 19 Nov 2018 13:12:59 +0000 Subject: [PATCH 83/94] requested changes --- pandas/tests/io/formats/test_to_html.py | 57 ++++++++++++------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 1d0998854d8be..55ba7a9d81672 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -442,12 +442,11 @@ def test_to_html_multi_indexes_index_false(self, datapath): expected = expected_html(datapath, 'gh22579_expected_output') assert result == expected - @pytest.mark.parametrize( - ('idx_flag', 'named_index', 'expected_output'), - [(True, True, 'gh22579_truncation_index_true'), - (False, True, 'gh22579_truncation_index_false_named'), - (False, False, 'gh22579_truncation_index_false_unnamed') - ]) + @pytest.mark.parametrize('idx_flag, named_index, expected_output', [ + (True, True, 'gh22579_truncation_index_true'), + (False, True, 'gh22579_truncation_index_false_named'), + (False, False, 'gh22579_truncation_index_false_unnamed') + ]) def test_to_html_multi_indexes_index_false_with_truncation( self, datapath, idx_flag, named_index, expected_output): # GH 22579 with truncation @@ -459,30 +458,28 @@ def test_to_html_multi_indexes_index_false_with_truncation( expected = expected_html(datapath, expected_output) assert result == expected - @pytest.mark.parametrize('col_idx_type', - [Index([0, 1]), - Index([0, 1], name='columns.name'), - MultiIndex.from_product([['a'], ['b', 'c']]), - MultiIndex.from_product([['a'], ['b', 'c']], - names=['columns.name.0', - 'columns.name.1']) - ], - ids=['columns_unnamed_standard', - 'columns_named_standard', - 'columns_unnamed_multi', - 'columns_named_multi']) - @pytest.mark.parametrize('idx_type', - [Index([0, 1]), - Index([0, 1], name='index.name'), - MultiIndex.from_product([['a'], ['b', 'c']]), - MultiIndex.from_product([['a'], ['b', 'c']], - names=['index.name.0', - 'index.name.1']) - ], - ids=['index_unnamed_standard', - 'index_named_standard', - 'index_unnamed_multi', - 'index_named_multi']) + @pytest.mark.parametrize('col_idx_type', [ + Index([0, 1]), + Index([0, 1], name='columns.name'), + MultiIndex.from_product([['a'], ['b', 'c']]), + MultiIndex.from_product([['a'], ['b', 'c']], names=['columns.name.0', + 'columns.name.1']) + ], + ids=['columns_unnamed_standard', + 'columns_named_standard', + 'columns_unnamed_multi', + 'columns_named_multi']) + @pytest.mark.parametrize('idx_type', [ + Index([0, 1]), + Index([0, 1], name='index.name'), + MultiIndex.from_product([['a'], ['b', 'c']]), + MultiIndex.from_product([['a'], ['b', 'c']], names=['index.name.0', + 'index.name.1']) + ], + ids=['index_unnamed_standard', + 'index_named_standard', + 'index_unnamed_multi', + 'index_named_multi']) def test_to_html_basic_alignment(self, datapath, idx_type, col_idx_type, index, index_names): # GH 22747, GH 22579 From 767541bc60b4dab33d017a2ba2d7c59ba78fba44 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 26 Nov 2018 21:43:44 +0000 Subject: [PATCH 84/94] changes requested --- pandas/tests/io/formats/test_to_html.py | 79 +++++++++++-------------- 1 file changed, 36 insertions(+), 43 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 55ba7a9d81672..36ca9f307bd74 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -11,22 +11,6 @@ from pandas.compat import u, lrange, StringIO from pandas.util import testing as tm import pandas.io.formats.format as fmt -import pandas.core.common as com - - -@pytest.fixture(params=[True, False], ids=['index_true', 'index_false']) -def index(request): - # to_html() parameter values for index - # whether to print index (row) labels, default True - return request.param - - -@pytest.fixture(params=[True, False], ids=['index_names_true', - 'index_names_false']) -def index_names(request): - # to_html() parameter values for index_names - # prints the names of the indexes, default True - return request.param def expected_html(datapath, name): @@ -458,23 +442,38 @@ def test_to_html_multi_indexes_index_false_with_truncation( expected = expected_html(datapath, expected_output) assert result == expected + @pytest.mark.parametrize( + 'index_names', [True, False], ids=['index_names_true', + 'index_names_false']) + @pytest.mark.parametrize( + 'index', [True, False], ids=['index_true', 'index_false']) @pytest.mark.parametrize('col_idx_type', [ - Index([0, 1]), - Index([0, 1], name='columns.name'), - MultiIndex.from_product([['a'], ['b', 'c']]), - MultiIndex.from_product([['a'], ['b', 'c']], names=['columns.name.0', - 'columns.name.1']) + (Index([0, 1]), + 'columns_unnamed_standard'), + (Index([0, 1], name='columns.name'), + 'columns_named_standard'), + (MultiIndex.from_product([['a'], ['b', 'c']]), + 'columns_unnamed_multi'), + (MultiIndex.from_product([['a'], ['b', 'c']], + names=['columns.name.0', + 'columns.name.1']), + 'columns_named_multi') ], ids=['columns_unnamed_standard', 'columns_named_standard', 'columns_unnamed_multi', 'columns_named_multi']) @pytest.mark.parametrize('idx_type', [ - Index([0, 1]), - Index([0, 1], name='index.name'), - MultiIndex.from_product([['a'], ['b', 'c']]), - MultiIndex.from_product([['a'], ['b', 'c']], names=['index.name.0', - 'index.name.1']) + (Index([0, 1]), + 'index_unnamed_standard'), + (Index([0, 1], name='index.name'), + 'index_named_standard'), + (MultiIndex.from_product([['a'], ['b', 'c']]), + 'index_unnamed_multi'), + (MultiIndex.from_product([['a'], ['b', 'c']], + names=['index.name.0', + 'index.name.1']), + 'index_named_multi') ], ids=['index_unnamed_standard', 'index_named_standard', @@ -483,27 +482,21 @@ def test_to_html_multi_indexes_index_false_with_truncation( def test_to_html_basic_alignment(self, datapath, idx_type, col_idx_type, index, index_names): # GH 22747, GH 22579 - def _exp_name(idx_type, index, index_names): - # helper function to map test parameters to expected output - if not index: - return 'none' - is_multi_index = idx_type.nlevels > 1 - if is_multi_index: - has_names = com._any_not_none(*idx_type.names) - else: - has_names = idx_type.name is not None - return '_'.join([ - 'named' if (has_names and index_names) else 'unnamed', - 'multi' if is_multi_index else 'standard']) + idx_type, idx_type_id = idx_type + col_idx_type, col_idx_type_id = col_idx_type df = DataFrame(np.zeros((2, 2), dtype=int), index=idx_type, columns=col_idx_type) result = df.to_html(index=index, index_names=index_names) - filename = '_'.join(['index', - _exp_name(idx_type, index, index_names), - 'columns', - _exp_name(col_idx_type, True, index_names) - ]) + + if not index: + idx_type_id = 'index_none' + elif not index_names: + idx_type_id = idx_type_id.replace('index_named', 'index_unnamed') + if not index_names: + col_idx_type_id = col_idx_type_id.replace( + 'columns_named', 'columns_unnamed') + filename = idx_type_id + '_' + col_idx_type_id expected = expected_html(datapath, filename) assert result == expected From 9eb162f219a218dff510d54773abdcf609dd2802 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 27 Nov 2018 03:05:48 +0000 Subject: [PATCH 85/94] requested changes --- pandas/tests/io/formats/test_to_html.py | 80 ++++++++++--------------- 1 file changed, 30 insertions(+), 50 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 4fad4c3d3a406..77689d4d86408 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -442,61 +442,41 @@ def test_to_html_multi_indexes_index_false_with_truncation( expected = expected_html(datapath, expected_output) assert result == expected - @pytest.mark.parametrize( - 'index_names', [True, False], ids=['index_names_true', - 'index_names_false']) - @pytest.mark.parametrize( - 'index', [True, False], ids=['index_true', 'index_false']) - @pytest.mark.parametrize('col_idx_type', [ - (Index([0, 1]), - 'columns_unnamed_standard'), - (Index([0, 1], name='columns.name'), - 'columns_named_standard'), - (MultiIndex.from_product([['a'], ['b', 'c']]), - 'columns_unnamed_multi'), - (MultiIndex.from_product([['a'], ['b', 'c']], - names=['columns.name.0', - 'columns.name.1']), - 'columns_named_multi') - ], - ids=['columns_unnamed_standard', - 'columns_named_standard', - 'columns_unnamed_multi', - 'columns_named_multi']) - @pytest.mark.parametrize('idx_type', [ - (Index([0, 1]), - 'index_unnamed_standard'), - (Index([0, 1], name='index.name'), - 'index_named_standard'), - (MultiIndex.from_product([['a'], ['b', 'c']]), - 'index_unnamed_multi'), - (MultiIndex.from_product([['a'], ['b', 'c']], - names=['index.name.0', - 'index.name.1']), - 'index_named_multi') - ], - ids=['index_unnamed_standard', - 'index_named_standard', - 'index_unnamed_multi', - 'index_named_multi']) - def test_to_html_basic_alignment(self, datapath, idx_type, col_idx_type, - index, index_names): + @pytest.mark.parametrize('index_names', [True, False]) + @pytest.mark.parametrize('index', [True, False]) + @pytest.mark.parametrize('column_index, column_type', [ + (Index([0, 1]), 'unnamed_standard'), + (Index([0, 1], name='columns.name'), 'named_standard'), + (MultiIndex.from_product([['a'], ['b', 'c']]), 'unnamed_multi'), + (MultiIndex.from_product( + [['a'], ['b', 'c']], names=['columns.name.0', + 'columns.name.1']), 'named_multi') + ]) + @pytest.mark.parametrize('row_index, row_type', [ + (Index([0, 1]), 'unnamed_standard'), + (Index([0, 1], name='index.name'), 'named_standard'), + (MultiIndex.from_product([['a'], ['b', 'c']]), 'unnamed_multi'), + (MultiIndex.from_product( + [['a'], ['b', 'c']], names=['index.name.0', + 'index.name.1']), 'named_multi') + ]) + def test_to_html_basic_alignment( + self, datapath, row_index, row_type, column_index, column_type, + index, index_names): # GH 22747, GH 22579 - idx_type, idx_type_id = idx_type - col_idx_type, col_idx_type_id = col_idx_type - df = DataFrame(np.zeros((2, 2), dtype=int), - index=idx_type, columns=col_idx_type) + index=row_index, columns=column_index) result = df.to_html(index=index, index_names=index_names) if not index: - idx_type_id = 'index_none' - elif not index_names: - idx_type_id = idx_type_id.replace('index_named', 'index_unnamed') - if not index_names: - col_idx_type_id = col_idx_type_id.replace( - 'columns_named', 'columns_unnamed') - filename = idx_type_id + '_' + col_idx_type_id + row_type = 'none' + elif not index_names and row_type.startswith('named'): + row_type = 'un' + row_type + + if not index_names and column_type.startswith('named'): + column_type = 'un' + column_type + + filename = 'index_' + row_type + '_columns_' + column_type expected = expected_html(datapath, filename) assert result == expected From d60fa0bd792cdd2cad6adeb147ac580dbe4110ad Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 3 Dec 2018 20:29:14 +0000 Subject: [PATCH 86/94] double backticks on MultiIndex --- doc/source/whatsnew/v0.24.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index 56a2daca0f6ca..783a74cf094c4 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1473,7 +1473,7 @@ Notice how we now instead output ``np.nan`` itself instead of a stringified form - :func:`read_sas()` will correctly parse sas7bdat files with data page types having also bit 7 set (so page type is 128 + 256 = 384) (:issue:`16615`) - Bug in :meth:`detect_client_encoding` where potential ``IOError`` goes unhandled when importing in a mod_wsgi process due to restricted access to stdout. (:issue:`21552`) - Bug in :func:`to_html()` with ``index=False`` misses truncation indicators (...) on truncated DataFrame (:issue:`15019`, :issue:`22783`) -- Bug in :func:`to_html()` with ``index=False`` when both columns and row index are MultiIndex (:issue:`22579`) +- Bug in :func:`to_html()` with ``index=False`` when both columns and row index are ``MultiIndex`` (:issue:`22579`) - Bug in :func:`to_html()` with ``index_names=False`` displaying index name (:issue:`22747`) - Bug in :func:`DataFrame.to_string()` that broke column alignment when ``index=False`` and width of first column's values is greater than the width of first column's header (:issue:`16839`, :issue:`13032`) - Bug in :func:`DataFrame.to_string()` that caused representations of :class:`DataFrame` to not take up the whole window (:issue:`22984`) From d3986f027cfeab5211d435e9ae64f3f70eee504c Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 9 Dec 2018 20:46:38 +0000 Subject: [PATCH 87/94] add code comments --- pandas/io/formats/html.py | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 341cbb4d88766..bdbd92aedda97 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -41,6 +41,12 @@ def __init__(self, formatter, classes=None, notebook=False, border=None, border = get_option('display.html.border') self.border = border self.table_id = table_id + # see gh-22579 + # Column misalignment also occurs for + # a standard index when the columns index is named. + # Determine if ANY column names need to be displayed + # since if the row index is not displayed a column of + # blank cells need to be included before the DataFrame values. self.show_col_idx_names = all((self.fmt.has_column_names, self.fmt.show_index_names, self.fmt.header)) @@ -201,6 +207,17 @@ def write_result(self, buf): def _write_header(self, indent): truncate_h = self.fmt.truncate_h + # see gh-22579 + # Column Offset Bug with to_html(index=False) with + # MultiIndex Columns and Index. + # Column misalignment also occurs for + # a standard index when the columns index is named. + # If the row index is not displayed a column of + # blank cells need to be included before the DataFrame values. + # However, in this code block only the placement of the truncation + # indicators within the header is affected by this. + # TODO: refactor to class property as row_levels also used in + # _write_regular_rows and _write_hierarchical_rows if self.fmt.index: row_levels = self.frame.index.nlevels else: @@ -271,8 +288,21 @@ def _write_header(self, indent): values = (values[:ins_col] + [u('...')] + values[ins_col:]) + # see gh-22579 + # Column Offset Bug with to_html(index=False) with + # MultiIndex Columns and Index. + # Initially fill row with blank cells before column names. + # TODO: Refactor to remove code duplication with code + # block below for standard columns index. row = [''] * (row_levels - 1) if self.fmt.index or self.show_col_idx_names: + # see gh-22747 + # If to_html(index_names=False) do not show columns + # index names. + # TODO: Refactor to use _get_column_name_list from + # DataFrameFormatter class and create a + # _get_formatted_column_labels function for code + # parity with DataFrameFormatter class. if self.fmt.show_index_names: name = self.columns.names[lnum] row.append(pprint_thing(name or '')) @@ -292,8 +322,19 @@ def _write_header(self, indent): self.write_tr(row, indent, self.indent_delta, tags=tags, header=True) else: + # see gh-22579 + # Column misalignment also occurs for + # a standard index when the columns index is named. + # Initially fill row with blank cells before column names. + # TODO: Refactor to remove code duplication with code block + # above for columns MultiIndex. row = [''] * (row_levels - 1) if self.fmt.index or self.show_col_idx_names: + # see gh-22747 + # If to_html(index_names=False) do not show columns + # index names. + # TODO: Refactor to use _get_column_name_list from + # DataFrameFormatter class. if self.fmt.show_index_names: row.append(self.columns.name or '') else: @@ -352,6 +393,13 @@ def _write_regular_rows(self, fmt_values, indent): index_values = self.fmt.tr_frame.index.format() row_levels = 1 else: + # see gh-22579 + # Column misalignment also occurs for + # a standard index when the columns index is named. + # row_levels is used for the number of cells and + # the placement of the truncation indicators. + # TODO: refactor to class property as row_levels also used in + # _write_header and _write_hierarchical_rows row_levels = 1 if self.show_col_idx_names else 0 row = [] @@ -365,6 +413,10 @@ def _write_regular_rows(self, fmt_values, indent): row = [] if self.fmt.index: row.append(index_values[i]) + # see gh-22579 + # Column misalignment also occurs for + # a standard index when the columns index is named. + # Add blank cell before data cells. elif self.show_col_idx_names: row.append('') row.extend(fmt_values[j][i] for j in range(self.ncols)) From 6d600646ac2fc59a2eb673223ce76724eece6016 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 10 Dec 2018 11:21:23 +0000 Subject: [PATCH 88/94] additional test case for gh-22783 --- .../data/gh22783_named_columns_index.html | 31 +++++++++++++++++++ pandas/tests/io/formats/test_to_html.py | 11 +++++-- 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 pandas/tests/io/formats/data/gh22783_named_columns_index.html diff --git a/pandas/tests/io/formats/data/gh22783_named_columns_index.html b/pandas/tests/io/formats/data/gh22783_named_columns_index.html new file mode 100644 index 0000000000000..ab7597eaf9fd3 --- /dev/null +++ b/pandas/tests/io/formats/data/gh22783_named_columns_index.html @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name01...34
1.7640520.400157...2.2408931.867558
-0.9772780.950088...-0.1032190.410599
+ \ No newline at end of file diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 1e60fec1a7867..921d6dd62a65b 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -494,13 +494,20 @@ def test_to_html_truncation_index_false_max_rows(self, datapath, index): assert result == expected @pytest.mark.parametrize('index', [False, 0]) - def test_to_html_truncation_index_false_max_cols(self, datapath, index): + @pytest.mark.parametrize('col_index_named, expected_output', [ + (False, 'gh22783_expected_output'), + (True, 'gh22783_named_columns_index') + ]) + def test_to_html_truncation_index_false_max_cols( + self, datapath, index, col_index_named, expected_output): # GH 22783 data = [[1.764052, 0.400157, 0.978738, 2.240893, 1.867558], [-0.977278, 0.950088, -0.151357, -0.103219, 0.410599]] df = DataFrame(data) + if col_index_named: + df.columns.rename('columns.name', inplace=True) result = df.to_html(max_cols=4, index=index) - expected = expected_html(datapath, 'gh22783_expected_output') + expected = expected_html(datapath, expected_output) assert result == expected def test_to_html_notebook_has_style(self): From 7da52a1df17213c8fce4796d7ee51adba11e2c69 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 14 Dec 2018 12:36:34 +0000 Subject: [PATCH 89/94] add test case --- pandas/tests/io/formats/test_to_html.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 570c6ba94f02e..30fcc1e09cdab 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -426,18 +426,23 @@ def test_to_html_multi_indexes_index_false(self, datapath): expected = expected_html(datapath, 'gh22579_expected_output') assert result == expected - @pytest.mark.parametrize('idx_flag, named_index, expected_output', [ - (True, True, 'gh22579_truncation_index_true'), - (False, True, 'gh22579_truncation_index_false_named'), - (False, False, 'gh22579_truncation_index_false_unnamed') - ]) + @pytest.mark.parametrize( + 'idx_flag, named_index, row_is_multi, expected_output', [ + (True, True, True, 'gh22579_truncation_index_true'), + (False, True, True, 'gh22579_truncation_index_false_named'), + (False, False, True, 'gh22579_truncation_index_false_unnamed'), + (False, True, False, 'gh22579_truncation_index_false_named') + ]) def test_to_html_multi_indexes_index_false_with_truncation( - self, datapath, idx_flag, named_index, expected_output): + self, datapath, idx_flag, named_index, row_is_multi, + expected_output): # GH 22579 with truncation names = ['foo', None, 'baz'] if named_index else None index = MultiIndex.from_product([['a', 'b'], ['c', 'd'], ['e', 'f']], names=names) - df = DataFrame(np.arange(64).reshape(8, 8), index=index, columns=index) + row_index = index if row_is_multi else None + df = DataFrame(np.arange(64).reshape(8, 8), index=row_index, + columns=index) result = df.to_html(max_rows=4, max_cols=4, index=idx_flag) expected = expected_html(datapath, expected_output) assert result == expected From 0a0f82f44edeb96c6e9a7d89765a0ad89abaf98e Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 14 Dec 2018 12:41:05 +0000 Subject: [PATCH 90/94] make show_col_idx_names class property --- pandas/io/formats/html.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 4432ae3f08652..931a4e7097e15 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -42,15 +42,20 @@ def __init__(self, formatter, classes=None, notebook=False, border=None, self.border = border self.table_id = table_id self.render_links = render_links + + @property + def show_col_idx_names(self): # see gh-22579 # Column misalignment also occurs for # a standard index when the columns index is named. # Determine if ANY column names need to be displayed # since if the row index is not displayed a column of # blank cells need to be included before the DataFrame values. - self.show_col_idx_names = all((self.fmt.has_column_names, - self.fmt.show_index_names, - self.fmt.header)) + # TODO: refactor to add show_col_idx_names property to + # DataFrameFormatter + return all((self.fmt.has_column_names, + self.fmt.show_index_names, + self.fmt.header)) @property def is_truncated(self): From 8d2d68aa8e79dbe8989cba53dbf035f188087ea5 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 14 Dec 2018 17:00:07 +0000 Subject: [PATCH 91/94] parametrize truncation tests --- ...ndex_named_multi_columns_named_multi.html} | 0 ...ex_named_multi_columns_named_standard.html | 72 +++++++++++++++ ...dex_named_multi_columns_unnamed_multi.html | 88 +++++++++++++++++++ ..._named_multi_columns_unnamed_standard.html | 72 +++++++++++++++ ...ex_named_standard_columns_named_multi.html | 74 ++++++++++++++++ ...named_standard_columns_named_standard.html | 62 +++++++++++++ ..._named_standard_columns_unnamed_multi.html | 74 ++++++++++++++++ ...med_standard_columns_unnamed_standard.html | 62 +++++++++++++ ...nc_df_index_none_columns_named_multi.html} | 0 ..._df_index_none_columns_named_standard.html | 54 ++++++++++++ .../trunc_df_index_none_columns_none.html | 39 ++++++++ ..._df_index_none_columns_unnamed_multi.html} | 0 ...f_index_none_columns_unnamed_standard.html | 48 ++++++++++ ...dex_unnamed_multi_columns_named_multi.html | 78 ++++++++++++++++ ..._unnamed_multi_columns_named_standard.html | 62 +++++++++++++ ...c_df_index_unnamed_multi_columns_none.html | 50 +++++++++++ ...x_unnamed_multi_columns_unnamed_multi.html | 78 ++++++++++++++++ ...nnamed_multi_columns_unnamed_standard.html | 62 +++++++++++++ ..._unnamed_standard_columns_named_multi.html | 66 ++++++++++++++ ...named_standard_columns_named_standard.html | 54 ++++++++++++ ...f_index_unnamed_standard_columns_none.html | 44 ++++++++++ ...nnamed_standard_columns_unnamed_multi.html | 66 ++++++++++++++ ...med_standard_columns_unnamed_standard.html | 54 ++++++++++++ pandas/tests/io/formats/test_to_html.py | 62 ++++++++----- 24 files changed, 1300 insertions(+), 21 deletions(-) rename pandas/tests/io/formats/data/{gh22579_truncation_index_true.html => trunc_df_index_named_multi_columns_named_multi.html} (100%) create mode 100644 pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_unnamed_standard.html create mode 100644 pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_unnamed_standard.html rename pandas/tests/io/formats/data/{gh22579_truncation_index_false_named.html => trunc_df_index_none_columns_named_multi.html} (100%) create mode 100644 pandas/tests/io/formats/data/trunc_df_index_none_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/trunc_df_index_none_columns_none.html rename pandas/tests/io/formats/data/{gh22579_truncation_index_false_unnamed.html => trunc_df_index_none_columns_unnamed_multi.html} (100%) create mode 100644 pandas/tests/io/formats/data/trunc_df_index_none_columns_unnamed_standard.html create mode 100644 pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_none.html create mode 100644 pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_unnamed_standard.html create mode 100644 pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_none.html create mode 100644 pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_unnamed_standard.html diff --git a/pandas/tests/io/formats/data/gh22579_truncation_index_true.html b/pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_named_multi.html similarity index 100% rename from pandas/tests/io/formats/data/gh22579_truncation_index_true.html rename to pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_named_multi.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_named_standard.html b/pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_named_standard.html new file mode 100644 index 0000000000000..536b371145081 --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_named_standard.html @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name01...67
foobaz
ace01...67
f89...1415
........................
bde4849...5455
f5657...6263
diff --git a/pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_unnamed_multi.html b/pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_unnamed_multi.html new file mode 100644 index 0000000000000..d472cdecb12c9 --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_unnamed_multi.html @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
a...b
c...d
ef...ef
foobaz
ace01...67
f89...1415
........................
bde4849...5455
f5657...6263
diff --git a/pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_unnamed_standard.html b/pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_unnamed_standard.html new file mode 100644 index 0000000000000..31c71ca3e59f6 --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_unnamed_standard.html @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
01...67
foobaz
ace01...67
f89...1415
........................
bde4849...5455
f5657...6263
diff --git a/pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_named_multi.html b/pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_named_multi.html new file mode 100644 index 0000000000000..779e84f6ee6d1 --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_named_multi.html @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
fooa...b
c...d
bazef...ef
index.name
001...67
189...1415
..................
64849...5455
75657...6263
diff --git a/pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_named_standard.html b/pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_named_standard.html new file mode 100644 index 0000000000000..b86454f5fb11f --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_named_standard.html @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name01...67
index.name
001...67
189...1415
..................
64849...5455
75657...6263
diff --git a/pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_unnamed_multi.html b/pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_unnamed_multi.html new file mode 100644 index 0000000000000..24b776e18bef9 --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_unnamed_multi.html @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
a...b
c...d
ef...ef
index.name
001...67
189...1415
..................
64849...5455
75657...6263
diff --git a/pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_unnamed_standard.html b/pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_unnamed_standard.html new file mode 100644 index 0000000000000..a0ca960207ac0 --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_unnamed_standard.html @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
01...67
index.name
001...67
189...1415
..................
64849...5455
75657...6263
diff --git a/pandas/tests/io/formats/data/gh22579_truncation_index_false_named.html b/pandas/tests/io/formats/data/trunc_df_index_none_columns_named_multi.html similarity index 100% rename from pandas/tests/io/formats/data/gh22579_truncation_index_false_named.html rename to pandas/tests/io/formats/data/trunc_df_index_none_columns_named_multi.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_none_columns_named_standard.html b/pandas/tests/io/formats/data/trunc_df_index_none_columns_named_standard.html new file mode 100644 index 0000000000000..364a0b98d6548 --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_none_columns_named_standard.html @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name01...67
01...67
89...1415
..................
4849...5455
5657...6263
diff --git a/pandas/tests/io/formats/data/trunc_df_index_none_columns_none.html b/pandas/tests/io/formats/data/trunc_df_index_none_columns_none.html new file mode 100644 index 0000000000000..e2af1ba42e940 --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_none_columns_none.html @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
01...67
89...1415
...............
4849...5455
5657...6263
diff --git a/pandas/tests/io/formats/data/gh22579_truncation_index_false_unnamed.html b/pandas/tests/io/formats/data/trunc_df_index_none_columns_unnamed_multi.html similarity index 100% rename from pandas/tests/io/formats/data/gh22579_truncation_index_false_unnamed.html rename to pandas/tests/io/formats/data/trunc_df_index_none_columns_unnamed_multi.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_none_columns_unnamed_standard.html b/pandas/tests/io/formats/data/trunc_df_index_none_columns_unnamed_standard.html new file mode 100644 index 0000000000000..b9dcf52619490 --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_none_columns_unnamed_standard.html @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
01...67
01...67
89...1415
...............
4849...5455
5657...6263
diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_named_multi.html b/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_named_multi.html new file mode 100644 index 0000000000000..0590d0dea6669 --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_named_multi.html @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
fooa...b
c...d
bazef...ef
ace01...67
f89...1415
........................
bde4849...5455
f5657...6263
diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_named_standard.html b/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_named_standard.html new file mode 100644 index 0000000000000..28a2d964675a3 --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_named_standard.html @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name01...67
ace01...67
f89...1415
........................
bde4849...5455
f5657...6263
diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_none.html b/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_none.html new file mode 100644 index 0000000000000..387ac51b17634 --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_none.html @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ace01...67
f89...1415
........................
bde4849...5455
f5657...6263
diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_unnamed_multi.html b/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_unnamed_multi.html new file mode 100644 index 0000000000000..30cd85904be4e --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_unnamed_multi.html @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
a...b
c...d
ef...ef
ace01...67
f89...1415
........................
bde4849...5455
f5657...6263
diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_unnamed_standard.html b/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_unnamed_standard.html new file mode 100644 index 0000000000000..81edece220408 --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_unnamed_standard.html @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
01...67
ace01...67
f89...1415
........................
bde4849...5455
f5657...6263
diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_named_multi.html b/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_named_multi.html new file mode 100644 index 0000000000000..2acacfed3a6d0 --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_named_multi.html @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
fooa...b
c...d
bazef...ef
001...67
189...1415
..................
64849...5455
75657...6263
diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_named_standard.html b/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_named_standard.html new file mode 100644 index 0000000000000..c9bacdbd241a6 --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_named_standard.html @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name01...67
001...67
189...1415
..................
64849...5455
75657...6263
diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_none.html b/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_none.html new file mode 100644 index 0000000000000..f2696f7d6b46a --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_none.html @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
001...67
189...1415
..................
64849...5455
75657...6263
diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_unnamed_multi.html b/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_unnamed_multi.html new file mode 100644 index 0000000000000..37e731520c7d9 --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_unnamed_multi.html @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
a...b
c...d
ef...ef
001...67
189...1415
..................
64849...5455
75657...6263
diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_unnamed_standard.html b/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_unnamed_standard.html new file mode 100644 index 0000000000000..3241ff41c5c58 --- /dev/null +++ b/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_unnamed_standard.html @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
01...67
001...67
189...1415
..................
64849...5455
75657...6263
diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 30fcc1e09cdab..cd2d9a9227928 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -426,27 +426,6 @@ def test_to_html_multi_indexes_index_false(self, datapath): expected = expected_html(datapath, 'gh22579_expected_output') assert result == expected - @pytest.mark.parametrize( - 'idx_flag, named_index, row_is_multi, expected_output', [ - (True, True, True, 'gh22579_truncation_index_true'), - (False, True, True, 'gh22579_truncation_index_false_named'), - (False, False, True, 'gh22579_truncation_index_false_unnamed'), - (False, True, False, 'gh22579_truncation_index_false_named') - ]) - def test_to_html_multi_indexes_index_false_with_truncation( - self, datapath, idx_flag, named_index, row_is_multi, - expected_output): - # GH 22579 with truncation - names = ['foo', None, 'baz'] if named_index else None - index = MultiIndex.from_product([['a', 'b'], ['c', 'd'], ['e', 'f']], - names=names) - row_index = index if row_is_multi else None - df = DataFrame(np.arange(64).reshape(8, 8), index=row_index, - columns=index) - result = df.to_html(max_rows=4, max_cols=4, index=idx_flag) - expected = expected_html(datapath, expected_output) - assert result == expected - @pytest.mark.parametrize('index_names', [True, False]) @pytest.mark.parametrize('index', [True, False]) @pytest.mark.parametrize('column_index, column_type', [ @@ -485,6 +464,47 @@ def test_to_html_basic_alignment( expected = expected_html(datapath, filename) assert result == expected + @pytest.mark.parametrize('index_names', [True, False]) + @pytest.mark.parametrize('index', [True, False]) + @pytest.mark.parametrize('column_index, column_type', [ + (Index(np.arange(8)), 'unnamed_standard'), + (Index(np.arange(8), name='columns.name'), 'named_standard'), + (MultiIndex.from_product( + [['a', 'b'], ['c', 'd'], ['e', 'f']]), 'unnamed_multi'), + (MultiIndex.from_product( + [['a', 'b'], ['c', 'd'], ['e', 'f']], names=['foo', None, 'baz']), + 'named_multi') + ]) + @pytest.mark.parametrize('row_index, row_type', [ + (Index(np.arange(8)), 'unnamed_standard'), + (Index(np.arange(8), name='index.name'), 'named_standard'), + (MultiIndex.from_product( + [['a', 'b'], ['c', 'd'], ['e', 'f']]), 'unnamed_multi'), + (MultiIndex.from_product( + [['a', 'b'], ['c', 'd'], ['e', 'f']], names=['foo', None, 'baz']), + 'named_multi') + ]) + def test_to_html_alignment_with_truncation( + self, datapath, row_index, row_type, column_index, column_type, + index, index_names): + # GH 22747, GH 22579 + df = DataFrame(np.arange(64).reshape(8, 8), + index=row_index, columns=column_index) + result = df.to_html(max_rows=4, max_cols=4, + index=index, index_names=index_names) + + if not index: + row_type = 'none' + elif not index_names and row_type.startswith('named'): + row_type = 'un' + row_type + + if not index_names and column_type.startswith('named'): + column_type = 'un' + column_type + + filename = 'trunc_df_index_' + row_type + '_columns_' + column_type + expected = expected_html(datapath, filename) + assert result == expected + @pytest.mark.parametrize('index', [False, 0]) def test_to_html_truncation_index_false_max_rows(self, datapath, index): # GH 15019 From d2e233ebb9006f55019e64e99383f6fd5189b2fd Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 14 Dec 2018 17:01:11 +0000 Subject: [PATCH 92/94] fix whitespace --- pandas/tests/io/formats/data/gh22783_named_columns_index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/io/formats/data/gh22783_named_columns_index.html b/pandas/tests/io/formats/data/gh22783_named_columns_index.html index ab7597eaf9fd3..55ab290920cc5 100644 --- a/pandas/tests/io/formats/data/gh22783_named_columns_index.html +++ b/pandas/tests/io/formats/data/gh22783_named_columns_index.html @@ -28,4 +28,3 @@ - \ No newline at end of file From b7e4f54798a94ba3dfcf72da83b1e09539048f48 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 14 Dec 2018 17:45:20 +0000 Subject: [PATCH 93/94] make row_levels class property --- pandas/io/formats/html.py | 54 +++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 931a4e7097e15..eb11dd461927b 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -57,6 +57,21 @@ def show_col_idx_names(self): self.fmt.show_index_names, self.fmt.header)) + @property + def row_levels(self): + if self.fmt.index: + # showing (row) index + return self.frame.index.nlevels + elif self.show_col_idx_names: + # see gh-22579 + # Column misalignment also occurs for + # a standard index when the columns index is named. + # If the row index is not displayed a column of + # blank cells need to be included before the DataFrame values. + return 1 + # not showing (row) index + return 0 + @property def is_truncated(self): return self.fmt.is_truncated @@ -215,21 +230,6 @@ def write_result(self, buf): def _write_header(self, indent): truncate_h = self.fmt.truncate_h - # see gh-22579 - # Column Offset Bug with to_html(index=False) with - # MultiIndex Columns and Index. - # Column misalignment also occurs for - # a standard index when the columns index is named. - # If the row index is not displayed a column of - # blank cells need to be included before the DataFrame values. - # However, in this code block only the placement of the truncation - # indicators within the header is affected by this. - # TODO: refactor to class property as row_levels also used in - # _write_regular_rows and _write_hierarchical_rows - if self.fmt.index: - row_levels = self.frame.index.nlevels - else: - row_levels = 1 if self.show_col_idx_names else 0 if not self.fmt.header: # write nothing @@ -302,7 +302,7 @@ def _write_header(self, indent): # Initially fill row with blank cells before column names. # TODO: Refactor to remove code duplication with code # block below for standard columns index. - row = [''] * (row_levels - 1) + row = [''] * (self.row_levels - 1) if self.fmt.index or self.show_col_idx_names: # see gh-22747 # If to_html(index_names=False) do not show columns @@ -336,7 +336,7 @@ def _write_header(self, indent): # Initially fill row with blank cells before column names. # TODO: Refactor to remove code duplication with code block # above for columns MultiIndex. - row = [''] * (row_levels - 1) + row = [''] * (self.row_levels - 1) if self.fmt.index or self.show_col_idx_names: # see gh-22747 # If to_html(index_names=False) do not show columns @@ -351,7 +351,7 @@ def _write_header(self, indent): align = self.fmt.justify if truncate_h: - ins_col = row_levels + self.fmt.tr_col_num + ins_col = self.row_levels + self.fmt.tr_col_num row.insert(ins_col, '...') self.write_tr(row, indent, self.indent_delta, header=True, @@ -399,16 +399,6 @@ def _write_regular_rows(self, fmt_values, indent): index_values = self.fmt.tr_frame.index.map(fmt) else: index_values = self.fmt.tr_frame.index.format() - row_levels = 1 - else: - # see gh-22579 - # Column misalignment also occurs for - # a standard index when the columns index is named. - # row_levels is used for the number of cells and - # the placement of the truncation indicators. - # TODO: refactor to class property as row_levels also used in - # _write_header and _write_hierarchical_rows - row_levels = 1 if self.show_col_idx_names else 0 row = [] for i in range(nrows): @@ -416,7 +406,7 @@ def _write_regular_rows(self, fmt_values, indent): if truncate_v and i == (self.fmt.tr_row_num): str_sep_row = ['...'] * len(row) self.write_tr(str_sep_row, indent, self.indent_delta, - tags=None, nindex_levels=row_levels) + tags=None, nindex_levels=self.row_levels) row = [] if self.fmt.index: @@ -430,10 +420,10 @@ def _write_regular_rows(self, fmt_values, indent): row.extend(fmt_values[j][i] for j in range(self.ncols)) if truncate_h: - dot_col_ix = self.fmt.tr_col_num + row_levels + dot_col_ix = self.fmt.tr_col_num + self.row_levels row.insert(dot_col_ix, '...') self.write_tr(row, indent, self.indent_delta, tags=None, - nindex_levels=row_levels) + nindex_levels=self.row_levels) def _write_hierarchical_rows(self, fmt_values, indent): template = 'rowspan="{span}" valign="top"' @@ -442,6 +432,8 @@ def _write_hierarchical_rows(self, fmt_values, indent): truncate_v = self.fmt.truncate_v frame = self.fmt.tr_frame nrows = len(frame) + # TODO: after gh-22887 fixed, refactor to use class property + # in place of row_levels row_levels = self.frame.index.nlevels idx_values = frame.index.format(sparsify=False, adjoin=False, From 5b635e49820c43989e4b643c95d2638b385a2dc3 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 28 Dec 2018 15:37:07 +0000 Subject: [PATCH 94/94] move data files --- .../io/formats/data/{ => html}/datetime64_hourformatter.html | 0 .../io/formats/data/{ => html}/datetime64_monthformatter.html | 0 pandas/tests/io/formats/data/{ => html}/escape_disabled.html | 0 pandas/tests/io/formats/data/{ => html}/escaped.html | 0 .../io/formats/data/{ => html}/gh12031_expected_output.html | 0 .../io/formats/data/{ => html}/gh14882_expected_output_1.html | 0 .../io/formats/data/{ => html}/gh14882_expected_output_2.html | 0 .../io/formats/data/{ => html}/gh14998_expected_output.html | 0 .../io/formats/data/{ => html}/gh15019_expected_output.html | 0 .../io/formats/data/{ => html}/gh21625_expected_output.html | 0 .../io/formats/data/{ => html}/gh22270_expected_output.html | 0 .../io/formats/data/{ => html}/gh22579_expected_output.html | 0 .../io/formats/data/{ => html}/gh22783_expected_output.html | 0 .../io/formats/data/{ => html}/gh22783_named_columns_index.html | 0 .../io/formats/data/{ => html}/gh6131_expected_output.html | 0 .../io/formats/data/{ => html}/gh8452_expected_output.html | 0 pandas/tests/io/formats/data/{ => html}/index_1.html | 0 pandas/tests/io/formats/data/{ => html}/index_2.html | 0 pandas/tests/io/formats/data/{ => html}/index_3.html | 0 pandas/tests/io/formats/data/{ => html}/index_4.html | 0 pandas/tests/io/formats/data/{ => html}/index_5.html | 0 pandas/tests/io/formats/data/{ => html}/index_formatter.html | 0 .../data/{ => html}/index_named_multi_columns_named_multi.html | 0 .../{ => html}/index_named_multi_columns_named_standard.html | 0 .../{ => html}/index_named_multi_columns_unnamed_multi.html | 0 .../{ => html}/index_named_multi_columns_unnamed_standard.html | 0 .../{ => html}/index_named_standard_columns_named_multi.html | 0 .../{ => html}/index_named_standard_columns_named_standard.html | 0 .../{ => html}/index_named_standard_columns_unnamed_multi.html | 0 .../index_named_standard_columns_unnamed_standard.html | 0 .../formats/data/{ => html}/index_none_columns_named_multi.html | 0 .../data/{ => html}/index_none_columns_named_standard.html | 0 .../io/formats/data/{ => html}/index_none_columns_none.html | 0 .../data/{ => html}/index_none_columns_unnamed_multi.html | 0 .../data/{ => html}/index_none_columns_unnamed_standard.html | 0 .../{ => html}/index_unnamed_multi_columns_named_multi.html | 0 .../{ => html}/index_unnamed_multi_columns_named_standard.html | 0 .../{ => html}/index_unnamed_multi_columns_unnamed_multi.html | 0 .../index_unnamed_multi_columns_unnamed_standard.html | 0 .../{ => html}/index_unnamed_standard_columns_named_multi.html | 0 .../index_unnamed_standard_columns_named_standard.html | 0 .../index_unnamed_standard_columns_unnamed_multi.html | 0 .../index_unnamed_standard_columns_unnamed_standard.html | 0 pandas/tests/io/formats/data/{ => html}/justify.html | 0 pandas/tests/io/formats/data/{ => html}/multiindex_1.html | 0 pandas/tests/io/formats/data/{ => html}/multiindex_2.html | 0 .../tests/io/formats/data/{ => html}/multiindex_sparsify_1.html | 0 .../tests/io/formats/data/{ => html}/multiindex_sparsify_2.html | 0 .../{ => html}/multiindex_sparsify_false_multi_sparse_1.html | 0 .../{ => html}/multiindex_sparsify_false_multi_sparse_2.html | 0 pandas/tests/io/formats/data/{ => html}/render_links_false.html | 0 pandas/tests/io/formats/data/{ => html}/render_links_true.html | 0 .../trunc_df_index_named_multi_columns_named_multi.html | 0 .../trunc_df_index_named_multi_columns_named_standard.html | 0 .../trunc_df_index_named_multi_columns_unnamed_multi.html | 0 .../trunc_df_index_named_multi_columns_unnamed_standard.html | 0 .../trunc_df_index_named_standard_columns_named_multi.html | 0 .../trunc_df_index_named_standard_columns_named_standard.html | 0 .../trunc_df_index_named_standard_columns_unnamed_multi.html | 0 .../trunc_df_index_named_standard_columns_unnamed_standard.html | 0 .../{ => html}/trunc_df_index_none_columns_named_multi.html | 0 .../{ => html}/trunc_df_index_none_columns_named_standard.html | 0 .../data/{ => html}/trunc_df_index_none_columns_none.html | 0 .../{ => html}/trunc_df_index_none_columns_unnamed_multi.html | 0 .../trunc_df_index_none_columns_unnamed_standard.html | 0 .../trunc_df_index_unnamed_multi_columns_named_multi.html | 0 .../trunc_df_index_unnamed_multi_columns_named_standard.html | 0 .../{ => html}/trunc_df_index_unnamed_multi_columns_none.html | 0 .../trunc_df_index_unnamed_multi_columns_unnamed_multi.html | 0 .../trunc_df_index_unnamed_multi_columns_unnamed_standard.html | 0 .../trunc_df_index_unnamed_standard_columns_named_multi.html | 0 .../trunc_df_index_unnamed_standard_columns_named_standard.html | 0 .../trunc_df_index_unnamed_standard_columns_none.html | 0 .../trunc_df_index_unnamed_standard_columns_unnamed_multi.html | 0 ...runc_df_index_unnamed_standard_columns_unnamed_standard.html | 0 pandas/tests/io/formats/data/{ => html}/truncate.html | 0 .../tests/io/formats/data/{ => html}/truncate_multi_index.html | 0 .../data/{ => html}/truncate_multi_index_sparse_off.html | 0 pandas/tests/io/formats/data/{ => html}/unicode_1.html | 0 pandas/tests/io/formats/data/{ => html}/unicode_2.html | 0 pandas/tests/io/formats/data/{ => html}/with_classes.html | 0 pandas/tests/io/formats/test_to_html.py | 2 +- 82 files changed, 1 insertion(+), 1 deletion(-) rename pandas/tests/io/formats/data/{ => html}/datetime64_hourformatter.html (100%) rename pandas/tests/io/formats/data/{ => html}/datetime64_monthformatter.html (100%) rename pandas/tests/io/formats/data/{ => html}/escape_disabled.html (100%) rename pandas/tests/io/formats/data/{ => html}/escaped.html (100%) rename pandas/tests/io/formats/data/{ => html}/gh12031_expected_output.html (100%) rename pandas/tests/io/formats/data/{ => html}/gh14882_expected_output_1.html (100%) rename pandas/tests/io/formats/data/{ => html}/gh14882_expected_output_2.html (100%) rename pandas/tests/io/formats/data/{ => html}/gh14998_expected_output.html (100%) rename pandas/tests/io/formats/data/{ => html}/gh15019_expected_output.html (100%) rename pandas/tests/io/formats/data/{ => html}/gh21625_expected_output.html (100%) rename pandas/tests/io/formats/data/{ => html}/gh22270_expected_output.html (100%) rename pandas/tests/io/formats/data/{ => html}/gh22579_expected_output.html (100%) rename pandas/tests/io/formats/data/{ => html}/gh22783_expected_output.html (100%) rename pandas/tests/io/formats/data/{ => html}/gh22783_named_columns_index.html (100%) rename pandas/tests/io/formats/data/{ => html}/gh6131_expected_output.html (100%) rename pandas/tests/io/formats/data/{ => html}/gh8452_expected_output.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_1.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_2.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_3.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_4.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_5.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_formatter.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_named_multi_columns_named_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_named_multi_columns_named_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_named_multi_columns_unnamed_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_named_multi_columns_unnamed_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_named_standard_columns_named_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_named_standard_columns_named_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_named_standard_columns_unnamed_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_named_standard_columns_unnamed_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_none_columns_named_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_none_columns_named_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_none_columns_none.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_none_columns_unnamed_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_none_columns_unnamed_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_unnamed_multi_columns_named_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_unnamed_multi_columns_named_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_unnamed_multi_columns_unnamed_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_unnamed_multi_columns_unnamed_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_unnamed_standard_columns_named_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_unnamed_standard_columns_named_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_unnamed_standard_columns_unnamed_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/index_unnamed_standard_columns_unnamed_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/justify.html (100%) rename pandas/tests/io/formats/data/{ => html}/multiindex_1.html (100%) rename pandas/tests/io/formats/data/{ => html}/multiindex_2.html (100%) rename pandas/tests/io/formats/data/{ => html}/multiindex_sparsify_1.html (100%) rename pandas/tests/io/formats/data/{ => html}/multiindex_sparsify_2.html (100%) rename pandas/tests/io/formats/data/{ => html}/multiindex_sparsify_false_multi_sparse_1.html (100%) rename pandas/tests/io/formats/data/{ => html}/multiindex_sparsify_false_multi_sparse_2.html (100%) rename pandas/tests/io/formats/data/{ => html}/render_links_false.html (100%) rename pandas/tests/io/formats/data/{ => html}/render_links_true.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_named_multi_columns_named_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_named_multi_columns_named_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_named_multi_columns_unnamed_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_named_multi_columns_unnamed_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_named_standard_columns_named_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_named_standard_columns_named_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_named_standard_columns_unnamed_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_named_standard_columns_unnamed_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_none_columns_named_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_none_columns_named_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_none_columns_none.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_none_columns_unnamed_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_none_columns_unnamed_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_unnamed_multi_columns_named_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_unnamed_multi_columns_named_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_unnamed_multi_columns_none.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_unnamed_multi_columns_unnamed_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_unnamed_multi_columns_unnamed_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_unnamed_standard_columns_named_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_unnamed_standard_columns_named_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_unnamed_standard_columns_none.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_unnamed_standard_columns_unnamed_multi.html (100%) rename pandas/tests/io/formats/data/{ => html}/trunc_df_index_unnamed_standard_columns_unnamed_standard.html (100%) rename pandas/tests/io/formats/data/{ => html}/truncate.html (100%) rename pandas/tests/io/formats/data/{ => html}/truncate_multi_index.html (100%) rename pandas/tests/io/formats/data/{ => html}/truncate_multi_index_sparse_off.html (100%) rename pandas/tests/io/formats/data/{ => html}/unicode_1.html (100%) rename pandas/tests/io/formats/data/{ => html}/unicode_2.html (100%) rename pandas/tests/io/formats/data/{ => html}/with_classes.html (100%) diff --git a/pandas/tests/io/formats/data/datetime64_hourformatter.html b/pandas/tests/io/formats/data/html/datetime64_hourformatter.html similarity index 100% rename from pandas/tests/io/formats/data/datetime64_hourformatter.html rename to pandas/tests/io/formats/data/html/datetime64_hourformatter.html diff --git a/pandas/tests/io/formats/data/datetime64_monthformatter.html b/pandas/tests/io/formats/data/html/datetime64_monthformatter.html similarity index 100% rename from pandas/tests/io/formats/data/datetime64_monthformatter.html rename to pandas/tests/io/formats/data/html/datetime64_monthformatter.html diff --git a/pandas/tests/io/formats/data/escape_disabled.html b/pandas/tests/io/formats/data/html/escape_disabled.html similarity index 100% rename from pandas/tests/io/formats/data/escape_disabled.html rename to pandas/tests/io/formats/data/html/escape_disabled.html diff --git a/pandas/tests/io/formats/data/escaped.html b/pandas/tests/io/formats/data/html/escaped.html similarity index 100% rename from pandas/tests/io/formats/data/escaped.html rename to pandas/tests/io/formats/data/html/escaped.html diff --git a/pandas/tests/io/formats/data/gh12031_expected_output.html b/pandas/tests/io/formats/data/html/gh12031_expected_output.html similarity index 100% rename from pandas/tests/io/formats/data/gh12031_expected_output.html rename to pandas/tests/io/formats/data/html/gh12031_expected_output.html diff --git a/pandas/tests/io/formats/data/gh14882_expected_output_1.html b/pandas/tests/io/formats/data/html/gh14882_expected_output_1.html similarity index 100% rename from pandas/tests/io/formats/data/gh14882_expected_output_1.html rename to pandas/tests/io/formats/data/html/gh14882_expected_output_1.html diff --git a/pandas/tests/io/formats/data/gh14882_expected_output_2.html b/pandas/tests/io/formats/data/html/gh14882_expected_output_2.html similarity index 100% rename from pandas/tests/io/formats/data/gh14882_expected_output_2.html rename to pandas/tests/io/formats/data/html/gh14882_expected_output_2.html diff --git a/pandas/tests/io/formats/data/gh14998_expected_output.html b/pandas/tests/io/formats/data/html/gh14998_expected_output.html similarity index 100% rename from pandas/tests/io/formats/data/gh14998_expected_output.html rename to pandas/tests/io/formats/data/html/gh14998_expected_output.html diff --git a/pandas/tests/io/formats/data/gh15019_expected_output.html b/pandas/tests/io/formats/data/html/gh15019_expected_output.html similarity index 100% rename from pandas/tests/io/formats/data/gh15019_expected_output.html rename to pandas/tests/io/formats/data/html/gh15019_expected_output.html diff --git a/pandas/tests/io/formats/data/gh21625_expected_output.html b/pandas/tests/io/formats/data/html/gh21625_expected_output.html similarity index 100% rename from pandas/tests/io/formats/data/gh21625_expected_output.html rename to pandas/tests/io/formats/data/html/gh21625_expected_output.html diff --git a/pandas/tests/io/formats/data/gh22270_expected_output.html b/pandas/tests/io/formats/data/html/gh22270_expected_output.html similarity index 100% rename from pandas/tests/io/formats/data/gh22270_expected_output.html rename to pandas/tests/io/formats/data/html/gh22270_expected_output.html diff --git a/pandas/tests/io/formats/data/gh22579_expected_output.html b/pandas/tests/io/formats/data/html/gh22579_expected_output.html similarity index 100% rename from pandas/tests/io/formats/data/gh22579_expected_output.html rename to pandas/tests/io/formats/data/html/gh22579_expected_output.html diff --git a/pandas/tests/io/formats/data/gh22783_expected_output.html b/pandas/tests/io/formats/data/html/gh22783_expected_output.html similarity index 100% rename from pandas/tests/io/formats/data/gh22783_expected_output.html rename to pandas/tests/io/formats/data/html/gh22783_expected_output.html diff --git a/pandas/tests/io/formats/data/gh22783_named_columns_index.html b/pandas/tests/io/formats/data/html/gh22783_named_columns_index.html similarity index 100% rename from pandas/tests/io/formats/data/gh22783_named_columns_index.html rename to pandas/tests/io/formats/data/html/gh22783_named_columns_index.html diff --git a/pandas/tests/io/formats/data/gh6131_expected_output.html b/pandas/tests/io/formats/data/html/gh6131_expected_output.html similarity index 100% rename from pandas/tests/io/formats/data/gh6131_expected_output.html rename to pandas/tests/io/formats/data/html/gh6131_expected_output.html diff --git a/pandas/tests/io/formats/data/gh8452_expected_output.html b/pandas/tests/io/formats/data/html/gh8452_expected_output.html similarity index 100% rename from pandas/tests/io/formats/data/gh8452_expected_output.html rename to pandas/tests/io/formats/data/html/gh8452_expected_output.html diff --git a/pandas/tests/io/formats/data/index_1.html b/pandas/tests/io/formats/data/html/index_1.html similarity index 100% rename from pandas/tests/io/formats/data/index_1.html rename to pandas/tests/io/formats/data/html/index_1.html diff --git a/pandas/tests/io/formats/data/index_2.html b/pandas/tests/io/formats/data/html/index_2.html similarity index 100% rename from pandas/tests/io/formats/data/index_2.html rename to pandas/tests/io/formats/data/html/index_2.html diff --git a/pandas/tests/io/formats/data/index_3.html b/pandas/tests/io/formats/data/html/index_3.html similarity index 100% rename from pandas/tests/io/formats/data/index_3.html rename to pandas/tests/io/formats/data/html/index_3.html diff --git a/pandas/tests/io/formats/data/index_4.html b/pandas/tests/io/formats/data/html/index_4.html similarity index 100% rename from pandas/tests/io/formats/data/index_4.html rename to pandas/tests/io/formats/data/html/index_4.html diff --git a/pandas/tests/io/formats/data/index_5.html b/pandas/tests/io/formats/data/html/index_5.html similarity index 100% rename from pandas/tests/io/formats/data/index_5.html rename to pandas/tests/io/formats/data/html/index_5.html diff --git a/pandas/tests/io/formats/data/index_formatter.html b/pandas/tests/io/formats/data/html/index_formatter.html similarity index 100% rename from pandas/tests/io/formats/data/index_formatter.html rename to pandas/tests/io/formats/data/html/index_formatter.html diff --git a/pandas/tests/io/formats/data/index_named_multi_columns_named_multi.html b/pandas/tests/io/formats/data/html/index_named_multi_columns_named_multi.html similarity index 100% rename from pandas/tests/io/formats/data/index_named_multi_columns_named_multi.html rename to pandas/tests/io/formats/data/html/index_named_multi_columns_named_multi.html diff --git a/pandas/tests/io/formats/data/index_named_multi_columns_named_standard.html b/pandas/tests/io/formats/data/html/index_named_multi_columns_named_standard.html similarity index 100% rename from pandas/tests/io/formats/data/index_named_multi_columns_named_standard.html rename to pandas/tests/io/formats/data/html/index_named_multi_columns_named_standard.html diff --git a/pandas/tests/io/formats/data/index_named_multi_columns_unnamed_multi.html b/pandas/tests/io/formats/data/html/index_named_multi_columns_unnamed_multi.html similarity index 100% rename from pandas/tests/io/formats/data/index_named_multi_columns_unnamed_multi.html rename to pandas/tests/io/formats/data/html/index_named_multi_columns_unnamed_multi.html diff --git a/pandas/tests/io/formats/data/index_named_multi_columns_unnamed_standard.html b/pandas/tests/io/formats/data/html/index_named_multi_columns_unnamed_standard.html similarity index 100% rename from pandas/tests/io/formats/data/index_named_multi_columns_unnamed_standard.html rename to pandas/tests/io/formats/data/html/index_named_multi_columns_unnamed_standard.html diff --git a/pandas/tests/io/formats/data/index_named_standard_columns_named_multi.html b/pandas/tests/io/formats/data/html/index_named_standard_columns_named_multi.html similarity index 100% rename from pandas/tests/io/formats/data/index_named_standard_columns_named_multi.html rename to pandas/tests/io/formats/data/html/index_named_standard_columns_named_multi.html diff --git a/pandas/tests/io/formats/data/index_named_standard_columns_named_standard.html b/pandas/tests/io/formats/data/html/index_named_standard_columns_named_standard.html similarity index 100% rename from pandas/tests/io/formats/data/index_named_standard_columns_named_standard.html rename to pandas/tests/io/formats/data/html/index_named_standard_columns_named_standard.html diff --git a/pandas/tests/io/formats/data/index_named_standard_columns_unnamed_multi.html b/pandas/tests/io/formats/data/html/index_named_standard_columns_unnamed_multi.html similarity index 100% rename from pandas/tests/io/formats/data/index_named_standard_columns_unnamed_multi.html rename to pandas/tests/io/formats/data/html/index_named_standard_columns_unnamed_multi.html diff --git a/pandas/tests/io/formats/data/index_named_standard_columns_unnamed_standard.html b/pandas/tests/io/formats/data/html/index_named_standard_columns_unnamed_standard.html similarity index 100% rename from pandas/tests/io/formats/data/index_named_standard_columns_unnamed_standard.html rename to pandas/tests/io/formats/data/html/index_named_standard_columns_unnamed_standard.html diff --git a/pandas/tests/io/formats/data/index_none_columns_named_multi.html b/pandas/tests/io/formats/data/html/index_none_columns_named_multi.html similarity index 100% rename from pandas/tests/io/formats/data/index_none_columns_named_multi.html rename to pandas/tests/io/formats/data/html/index_none_columns_named_multi.html diff --git a/pandas/tests/io/formats/data/index_none_columns_named_standard.html b/pandas/tests/io/formats/data/html/index_none_columns_named_standard.html similarity index 100% rename from pandas/tests/io/formats/data/index_none_columns_named_standard.html rename to pandas/tests/io/formats/data/html/index_none_columns_named_standard.html diff --git a/pandas/tests/io/formats/data/index_none_columns_none.html b/pandas/tests/io/formats/data/html/index_none_columns_none.html similarity index 100% rename from pandas/tests/io/formats/data/index_none_columns_none.html rename to pandas/tests/io/formats/data/html/index_none_columns_none.html diff --git a/pandas/tests/io/formats/data/index_none_columns_unnamed_multi.html b/pandas/tests/io/formats/data/html/index_none_columns_unnamed_multi.html similarity index 100% rename from pandas/tests/io/formats/data/index_none_columns_unnamed_multi.html rename to pandas/tests/io/formats/data/html/index_none_columns_unnamed_multi.html diff --git a/pandas/tests/io/formats/data/index_none_columns_unnamed_standard.html b/pandas/tests/io/formats/data/html/index_none_columns_unnamed_standard.html similarity index 100% rename from pandas/tests/io/formats/data/index_none_columns_unnamed_standard.html rename to pandas/tests/io/formats/data/html/index_none_columns_unnamed_standard.html diff --git a/pandas/tests/io/formats/data/index_unnamed_multi_columns_named_multi.html b/pandas/tests/io/formats/data/html/index_unnamed_multi_columns_named_multi.html similarity index 100% rename from pandas/tests/io/formats/data/index_unnamed_multi_columns_named_multi.html rename to pandas/tests/io/formats/data/html/index_unnamed_multi_columns_named_multi.html diff --git a/pandas/tests/io/formats/data/index_unnamed_multi_columns_named_standard.html b/pandas/tests/io/formats/data/html/index_unnamed_multi_columns_named_standard.html similarity index 100% rename from pandas/tests/io/formats/data/index_unnamed_multi_columns_named_standard.html rename to pandas/tests/io/formats/data/html/index_unnamed_multi_columns_named_standard.html diff --git a/pandas/tests/io/formats/data/index_unnamed_multi_columns_unnamed_multi.html b/pandas/tests/io/formats/data/html/index_unnamed_multi_columns_unnamed_multi.html similarity index 100% rename from pandas/tests/io/formats/data/index_unnamed_multi_columns_unnamed_multi.html rename to pandas/tests/io/formats/data/html/index_unnamed_multi_columns_unnamed_multi.html diff --git a/pandas/tests/io/formats/data/index_unnamed_multi_columns_unnamed_standard.html b/pandas/tests/io/formats/data/html/index_unnamed_multi_columns_unnamed_standard.html similarity index 100% rename from pandas/tests/io/formats/data/index_unnamed_multi_columns_unnamed_standard.html rename to pandas/tests/io/formats/data/html/index_unnamed_multi_columns_unnamed_standard.html diff --git a/pandas/tests/io/formats/data/index_unnamed_standard_columns_named_multi.html b/pandas/tests/io/formats/data/html/index_unnamed_standard_columns_named_multi.html similarity index 100% rename from pandas/tests/io/formats/data/index_unnamed_standard_columns_named_multi.html rename to pandas/tests/io/formats/data/html/index_unnamed_standard_columns_named_multi.html diff --git a/pandas/tests/io/formats/data/index_unnamed_standard_columns_named_standard.html b/pandas/tests/io/formats/data/html/index_unnamed_standard_columns_named_standard.html similarity index 100% rename from pandas/tests/io/formats/data/index_unnamed_standard_columns_named_standard.html rename to pandas/tests/io/formats/data/html/index_unnamed_standard_columns_named_standard.html diff --git a/pandas/tests/io/formats/data/index_unnamed_standard_columns_unnamed_multi.html b/pandas/tests/io/formats/data/html/index_unnamed_standard_columns_unnamed_multi.html similarity index 100% rename from pandas/tests/io/formats/data/index_unnamed_standard_columns_unnamed_multi.html rename to pandas/tests/io/formats/data/html/index_unnamed_standard_columns_unnamed_multi.html diff --git a/pandas/tests/io/formats/data/index_unnamed_standard_columns_unnamed_standard.html b/pandas/tests/io/formats/data/html/index_unnamed_standard_columns_unnamed_standard.html similarity index 100% rename from pandas/tests/io/formats/data/index_unnamed_standard_columns_unnamed_standard.html rename to pandas/tests/io/formats/data/html/index_unnamed_standard_columns_unnamed_standard.html diff --git a/pandas/tests/io/formats/data/justify.html b/pandas/tests/io/formats/data/html/justify.html similarity index 100% rename from pandas/tests/io/formats/data/justify.html rename to pandas/tests/io/formats/data/html/justify.html diff --git a/pandas/tests/io/formats/data/multiindex_1.html b/pandas/tests/io/formats/data/html/multiindex_1.html similarity index 100% rename from pandas/tests/io/formats/data/multiindex_1.html rename to pandas/tests/io/formats/data/html/multiindex_1.html diff --git a/pandas/tests/io/formats/data/multiindex_2.html b/pandas/tests/io/formats/data/html/multiindex_2.html similarity index 100% rename from pandas/tests/io/formats/data/multiindex_2.html rename to pandas/tests/io/formats/data/html/multiindex_2.html diff --git a/pandas/tests/io/formats/data/multiindex_sparsify_1.html b/pandas/tests/io/formats/data/html/multiindex_sparsify_1.html similarity index 100% rename from pandas/tests/io/formats/data/multiindex_sparsify_1.html rename to pandas/tests/io/formats/data/html/multiindex_sparsify_1.html diff --git a/pandas/tests/io/formats/data/multiindex_sparsify_2.html b/pandas/tests/io/formats/data/html/multiindex_sparsify_2.html similarity index 100% rename from pandas/tests/io/formats/data/multiindex_sparsify_2.html rename to pandas/tests/io/formats/data/html/multiindex_sparsify_2.html diff --git a/pandas/tests/io/formats/data/multiindex_sparsify_false_multi_sparse_1.html b/pandas/tests/io/formats/data/html/multiindex_sparsify_false_multi_sparse_1.html similarity index 100% rename from pandas/tests/io/formats/data/multiindex_sparsify_false_multi_sparse_1.html rename to pandas/tests/io/formats/data/html/multiindex_sparsify_false_multi_sparse_1.html diff --git a/pandas/tests/io/formats/data/multiindex_sparsify_false_multi_sparse_2.html b/pandas/tests/io/formats/data/html/multiindex_sparsify_false_multi_sparse_2.html similarity index 100% rename from pandas/tests/io/formats/data/multiindex_sparsify_false_multi_sparse_2.html rename to pandas/tests/io/formats/data/html/multiindex_sparsify_false_multi_sparse_2.html diff --git a/pandas/tests/io/formats/data/render_links_false.html b/pandas/tests/io/formats/data/html/render_links_false.html similarity index 100% rename from pandas/tests/io/formats/data/render_links_false.html rename to pandas/tests/io/formats/data/html/render_links_false.html diff --git a/pandas/tests/io/formats/data/render_links_true.html b/pandas/tests/io/formats/data/html/render_links_true.html similarity index 100% rename from pandas/tests/io/formats/data/render_links_true.html rename to pandas/tests/io/formats/data/html/render_links_true.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_named_multi.html b/pandas/tests/io/formats/data/html/trunc_df_index_named_multi_columns_named_multi.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_named_multi.html rename to pandas/tests/io/formats/data/html/trunc_df_index_named_multi_columns_named_multi.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_named_standard.html b/pandas/tests/io/formats/data/html/trunc_df_index_named_multi_columns_named_standard.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_named_standard.html rename to pandas/tests/io/formats/data/html/trunc_df_index_named_multi_columns_named_standard.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_unnamed_multi.html b/pandas/tests/io/formats/data/html/trunc_df_index_named_multi_columns_unnamed_multi.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_unnamed_multi.html rename to pandas/tests/io/formats/data/html/trunc_df_index_named_multi_columns_unnamed_multi.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_unnamed_standard.html b/pandas/tests/io/formats/data/html/trunc_df_index_named_multi_columns_unnamed_standard.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_named_multi_columns_unnamed_standard.html rename to pandas/tests/io/formats/data/html/trunc_df_index_named_multi_columns_unnamed_standard.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_named_multi.html b/pandas/tests/io/formats/data/html/trunc_df_index_named_standard_columns_named_multi.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_named_multi.html rename to pandas/tests/io/formats/data/html/trunc_df_index_named_standard_columns_named_multi.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_named_standard.html b/pandas/tests/io/formats/data/html/trunc_df_index_named_standard_columns_named_standard.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_named_standard.html rename to pandas/tests/io/formats/data/html/trunc_df_index_named_standard_columns_named_standard.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_unnamed_multi.html b/pandas/tests/io/formats/data/html/trunc_df_index_named_standard_columns_unnamed_multi.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_unnamed_multi.html rename to pandas/tests/io/formats/data/html/trunc_df_index_named_standard_columns_unnamed_multi.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_unnamed_standard.html b/pandas/tests/io/formats/data/html/trunc_df_index_named_standard_columns_unnamed_standard.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_named_standard_columns_unnamed_standard.html rename to pandas/tests/io/formats/data/html/trunc_df_index_named_standard_columns_unnamed_standard.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_none_columns_named_multi.html b/pandas/tests/io/formats/data/html/trunc_df_index_none_columns_named_multi.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_none_columns_named_multi.html rename to pandas/tests/io/formats/data/html/trunc_df_index_none_columns_named_multi.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_none_columns_named_standard.html b/pandas/tests/io/formats/data/html/trunc_df_index_none_columns_named_standard.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_none_columns_named_standard.html rename to pandas/tests/io/formats/data/html/trunc_df_index_none_columns_named_standard.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_none_columns_none.html b/pandas/tests/io/formats/data/html/trunc_df_index_none_columns_none.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_none_columns_none.html rename to pandas/tests/io/formats/data/html/trunc_df_index_none_columns_none.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_none_columns_unnamed_multi.html b/pandas/tests/io/formats/data/html/trunc_df_index_none_columns_unnamed_multi.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_none_columns_unnamed_multi.html rename to pandas/tests/io/formats/data/html/trunc_df_index_none_columns_unnamed_multi.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_none_columns_unnamed_standard.html b/pandas/tests/io/formats/data/html/trunc_df_index_none_columns_unnamed_standard.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_none_columns_unnamed_standard.html rename to pandas/tests/io/formats/data/html/trunc_df_index_none_columns_unnamed_standard.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_named_multi.html b/pandas/tests/io/formats/data/html/trunc_df_index_unnamed_multi_columns_named_multi.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_named_multi.html rename to pandas/tests/io/formats/data/html/trunc_df_index_unnamed_multi_columns_named_multi.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_named_standard.html b/pandas/tests/io/formats/data/html/trunc_df_index_unnamed_multi_columns_named_standard.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_named_standard.html rename to pandas/tests/io/formats/data/html/trunc_df_index_unnamed_multi_columns_named_standard.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_none.html b/pandas/tests/io/formats/data/html/trunc_df_index_unnamed_multi_columns_none.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_none.html rename to pandas/tests/io/formats/data/html/trunc_df_index_unnamed_multi_columns_none.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_unnamed_multi.html b/pandas/tests/io/formats/data/html/trunc_df_index_unnamed_multi_columns_unnamed_multi.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_unnamed_multi.html rename to pandas/tests/io/formats/data/html/trunc_df_index_unnamed_multi_columns_unnamed_multi.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_unnamed_standard.html b/pandas/tests/io/formats/data/html/trunc_df_index_unnamed_multi_columns_unnamed_standard.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_unnamed_multi_columns_unnamed_standard.html rename to pandas/tests/io/formats/data/html/trunc_df_index_unnamed_multi_columns_unnamed_standard.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_named_multi.html b/pandas/tests/io/formats/data/html/trunc_df_index_unnamed_standard_columns_named_multi.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_named_multi.html rename to pandas/tests/io/formats/data/html/trunc_df_index_unnamed_standard_columns_named_multi.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_named_standard.html b/pandas/tests/io/formats/data/html/trunc_df_index_unnamed_standard_columns_named_standard.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_named_standard.html rename to pandas/tests/io/formats/data/html/trunc_df_index_unnamed_standard_columns_named_standard.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_none.html b/pandas/tests/io/formats/data/html/trunc_df_index_unnamed_standard_columns_none.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_none.html rename to pandas/tests/io/formats/data/html/trunc_df_index_unnamed_standard_columns_none.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_unnamed_multi.html b/pandas/tests/io/formats/data/html/trunc_df_index_unnamed_standard_columns_unnamed_multi.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_unnamed_multi.html rename to pandas/tests/io/formats/data/html/trunc_df_index_unnamed_standard_columns_unnamed_multi.html diff --git a/pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_unnamed_standard.html b/pandas/tests/io/formats/data/html/trunc_df_index_unnamed_standard_columns_unnamed_standard.html similarity index 100% rename from pandas/tests/io/formats/data/trunc_df_index_unnamed_standard_columns_unnamed_standard.html rename to pandas/tests/io/formats/data/html/trunc_df_index_unnamed_standard_columns_unnamed_standard.html diff --git a/pandas/tests/io/formats/data/truncate.html b/pandas/tests/io/formats/data/html/truncate.html similarity index 100% rename from pandas/tests/io/formats/data/truncate.html rename to pandas/tests/io/formats/data/html/truncate.html diff --git a/pandas/tests/io/formats/data/truncate_multi_index.html b/pandas/tests/io/formats/data/html/truncate_multi_index.html similarity index 100% rename from pandas/tests/io/formats/data/truncate_multi_index.html rename to pandas/tests/io/formats/data/html/truncate_multi_index.html diff --git a/pandas/tests/io/formats/data/truncate_multi_index_sparse_off.html b/pandas/tests/io/formats/data/html/truncate_multi_index_sparse_off.html similarity index 100% rename from pandas/tests/io/formats/data/truncate_multi_index_sparse_off.html rename to pandas/tests/io/formats/data/html/truncate_multi_index_sparse_off.html diff --git a/pandas/tests/io/formats/data/unicode_1.html b/pandas/tests/io/formats/data/html/unicode_1.html similarity index 100% rename from pandas/tests/io/formats/data/unicode_1.html rename to pandas/tests/io/formats/data/html/unicode_1.html diff --git a/pandas/tests/io/formats/data/unicode_2.html b/pandas/tests/io/formats/data/html/unicode_2.html similarity index 100% rename from pandas/tests/io/formats/data/unicode_2.html rename to pandas/tests/io/formats/data/html/unicode_2.html diff --git a/pandas/tests/io/formats/data/with_classes.html b/pandas/tests/io/formats/data/html/with_classes.html similarity index 100% rename from pandas/tests/io/formats/data/with_classes.html rename to pandas/tests/io/formats/data/html/with_classes.html diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index cd2d9a9227928..ca33185bf79eb 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -29,7 +29,7 @@ def expected_html(datapath, name): str : contents of HTML file. """ filename = '.'.join([name, 'html']) - filepath = datapath('io', 'formats', 'data', filename) + filepath = datapath('io', 'formats', 'data', 'html', filename) with open(filepath, encoding='utf-8') as f: html = f.read() return html.rstrip()