From b9284a2cd87fc305106fd75836dc96d7e00a0210 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 1 Jan 2019 16:35:14 +0000 Subject: [PATCH] BUG: output formatting with to_html(), index=False and/or index_names=False (#22579, #22747) (#22655) --- doc/source/whatsnew/v0.24.0.rst | 2 + pandas/io/formats/html.py | 100 +++++++++++++---- .../{ => html}/datetime64_hourformatter.html | 0 .../{ => html}/datetime64_monthformatter.html | 0 .../data/{ => html}/escape_disabled.html | 0 .../io/formats/data/{ => html}/escaped.html | 0 .../{ => html}/gh12031_expected_output.html | 0 .../{ => html}/gh14882_expected_output_1.html | 0 .../{ => html}/gh14882_expected_output_2.html | 0 .../{ => html}/gh14998_expected_output.html | 0 .../{ => html}/gh15019_expected_output.html | 0 .../{ => html}/gh21625_expected_output.html | 0 .../{ => html}/gh22270_expected_output.html | 0 .../data/html/gh22579_expected_output.html | 76 +++++++++++++ .../{ => html}/gh22783_expected_output.html | 0 .../html/gh22783_named_columns_index.html | 30 +++++ .../{ => html}/gh6131_expected_output.html | 0 .../{ => html}/gh8452_expected_output.html | 0 .../io/formats/data/{ => html}/index_1.html | 0 .../io/formats/data/{ => html}/index_2.html | 0 .../io/formats/data/{ => html}/index_3.html | 0 .../io/formats/data/{ => html}/index_4.html | 0 .../io/formats/data/{ => html}/index_5.html | 0 .../data/{ => html}/index_formatter.html | 0 ...index_named_multi_columns_named_multi.html | 34 ++++++ ...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_named_standard.html | 26 +++++ ..._named_standard_columns_unnamed_multi.html | 30 +++++ ...med_standard_columns_unnamed_standard.html | 26 +++++ .../html/index_none_columns_named_multi.html | 25 +++++ .../index_none_columns_named_standard.html | 21 ++++ .../data/html/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 ++++ .../io/formats/data/{ => html}/justify.html | 0 .../formats/data/{ => html}/multiindex_1.html | 0 .../formats/data/{ => html}/multiindex_2.html | 0 .../{ => html}/multiindex_sparsify_1.html | 0 .../{ => html}/multiindex_sparsify_2.html | 0 ...tiindex_sparsify_false_multi_sparse_1.html | 0 ...tiindex_sparsify_false_multi_sparse_2.html | 0 .../data/{ => html}/render_links_false.html | 0 .../data/{ => html}/render_links_true.html | 0 ...index_named_multi_columns_named_multi.html | 88 +++++++++++++++ ...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 +++++++++++ ...unc_df_index_none_columns_named_multi.html | 66 +++++++++++ ..._df_index_none_columns_named_standard.html | 54 +++++++++ .../trunc_df_index_none_columns_none.html | 39 +++++++ ...c_df_index_none_columns_unnamed_multi.html | 58 ++++++++++ ...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 +++++++++ .../io/formats/data/{ => html}/truncate.html | 0 .../data/{ => html}/truncate_multi_index.html | 0 .../truncate_multi_index_sparse_off.html | 0 .../io/formats/data/{ => html}/unicode_1.html | 0 .../io/formats/data/{ => html}/unicode_2.html | 0 .../formats/data/{ => html}/with_classes.html | 0 pandas/tests/io/formats/test_to_html.py | 103 +++++++++++++++++- 84 files changed, 2287 insertions(+), 24 deletions(-) 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%) create mode 100644 pandas/tests/io/formats/data/html/gh22579_expected_output.html rename pandas/tests/io/formats/data/{ => html}/gh22783_expected_output.html (100%) create mode 100644 pandas/tests/io/formats/data/html/gh22783_named_columns_index.html 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%) create mode 100644 pandas/tests/io/formats/data/html/index_named_multi_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/html/index_named_multi_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/html/index_named_multi_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/html/index_named_multi_columns_unnamed_standard.html create mode 100644 pandas/tests/io/formats/data/html/index_named_standard_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/html/index_named_standard_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/html/index_named_standard_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/html/index_named_standard_columns_unnamed_standard.html create mode 100644 pandas/tests/io/formats/data/html/index_none_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/html/index_none_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/html/index_none_columns_none.html create mode 100644 pandas/tests/io/formats/data/html/index_none_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/html/index_none_columns_unnamed_standard.html create mode 100644 pandas/tests/io/formats/data/html/index_unnamed_multi_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/html/index_unnamed_multi_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/html/index_unnamed_multi_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/html/index_unnamed_multi_columns_unnamed_standard.html create mode 100644 pandas/tests/io/formats/data/html/index_unnamed_standard_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/html/index_unnamed_standard_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/html/index_unnamed_standard_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/html/index_unnamed_standard_columns_unnamed_standard.html 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%) create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_named_multi_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_named_multi_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_named_multi_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_named_multi_columns_unnamed_standard.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_named_standard_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_named_standard_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_named_standard_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_named_standard_columns_unnamed_standard.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_none_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_none_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_none_columns_none.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_none_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_none_columns_unnamed_standard.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_unnamed_multi_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_unnamed_multi_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_unnamed_multi_columns_none.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_unnamed_multi_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_unnamed_multi_columns_unnamed_standard.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_unnamed_standard_columns_named_multi.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_unnamed_standard_columns_named_standard.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_unnamed_standard_columns_none.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_unnamed_standard_columns_unnamed_multi.html create mode 100644 pandas/tests/io/formats/data/html/trunc_df_index_unnamed_standard_columns_unnamed_standard.html 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/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index 8c686db22299b..1fe5e4e6e7087 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1596,6 +1596,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/io/formats/html.py b/pandas/io/formats/html.py index cac0c699d7046..eb11dd461927b 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -43,6 +43,35 @@ def __init__(self, formatter, classes=None, notebook=False, border=None, 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. + # 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 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 @@ -201,7 +230,7 @@ def write_result(self, buf): 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 @@ -267,12 +296,26 @@ def _write_header(self, indent): 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: - row = [] + # 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 = [''] * (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 + # 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 '')) + else: + row.append('') tags = {} j = len(row) @@ -287,18 +330,28 @@ def _write_header(self, indent): self.write_tr(row, indent, self.indent_delta, tags=tags, header=True) else: - if self.fmt.index: - row = [''] * (self.frame.index.nlevels - 1) - row.append(self.columns.name or '') - else: - row = [] + # 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 = [''] * (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 + # 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: + row.append('') row.extend(self.columns) align = self.fmt.justify if truncate_h: - if not self.fmt.index: - row_levels = 0 - 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, @@ -346,9 +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: - row_levels = 0 row = [] for i in range(nrows): @@ -356,18 +406,24 @@ 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: 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)) 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"' @@ -376,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, 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/html/gh22579_expected_output.html b/pandas/tests/io/formats/data/html/gh22579_expected_output.html new file mode 100644 index 0000000000000..425b0f915ed16 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/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/html/gh22783_named_columns_index.html b/pandas/tests/io/formats/data/html/gh22783_named_columns_index.html new file mode 100644 index 0000000000000..55ab290920cc5 --- /dev/null +++ b/pandas/tests/io/formats/data/html/gh22783_named_columns_index.html @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name01...34
1.7640520.400157...2.2408931.867558
-0.9772780.950088...-0.1032190.410599
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/html/index_named_multi_columns_named_multi.html b/pandas/tests/io/formats/data/html/index_named_multi_columns_named_multi.html new file mode 100644 index 0000000000000..817b54d77f8b1 --- /dev/null +++ b/pandas/tests/io/formats/data/html/index_named_multi_columns_named_multi.html @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name.0a
columns.name.1bc
index.name.0index.name.1
ab00
c00
diff --git a/pandas/tests/io/formats/data/html/index_named_multi_columns_named_standard.html b/pandas/tests/io/formats/data/html/index_named_multi_columns_named_standard.html new file mode 100644 index 0000000000000..e85965f14075d --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/index_named_multi_columns_unnamed_multi.html b/pandas/tests/io/formats/data/html/index_named_multi_columns_unnamed_multi.html new file mode 100644 index 0000000000000..7af63e893b12e --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/index_named_multi_columns_unnamed_standard.html b/pandas/tests/io/formats/data/html/index_named_multi_columns_unnamed_standard.html new file mode 100644 index 0000000000000..2f7837864bf88 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/index_named_standard_columns_named_multi.html b/pandas/tests/io/formats/data/html/index_named_standard_columns_named_multi.html new file mode 100644 index 0000000000000..ca9b8bd834a9c --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/index_named_standard_columns_named_standard.html b/pandas/tests/io/formats/data/html/index_named_standard_columns_named_standard.html new file mode 100644 index 0000000000000..6478c99ad85e9 --- /dev/null +++ b/pandas/tests/io/formats/data/html/index_named_standard_columns_named_standard.html @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +
columns.name01
index.name
000
100
diff --git a/pandas/tests/io/formats/data/html/index_named_standard_columns_unnamed_multi.html b/pandas/tests/io/formats/data/html/index_named_standard_columns_unnamed_multi.html new file mode 100644 index 0000000000000..d7660872177dc --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/index_named_standard_columns_unnamed_standard.html b/pandas/tests/io/formats/data/html/index_named_standard_columns_unnamed_standard.html new file mode 100644 index 0000000000000..4810f66018d3b --- /dev/null +++ b/pandas/tests/io/formats/data/html/index_named_standard_columns_unnamed_standard.html @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +
01
index.name
000
100
diff --git a/pandas/tests/io/formats/data/html/index_none_columns_named_multi.html b/pandas/tests/io/formats/data/html/index_none_columns_named_multi.html new file mode 100644 index 0000000000000..e111f55be7d25 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/index_none_columns_named_standard.html b/pandas/tests/io/formats/data/html/index_none_columns_named_standard.html new file mode 100644 index 0000000000000..d3a9ba017b43e --- /dev/null +++ b/pandas/tests/io/formats/data/html/index_none_columns_named_standard.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + +
columns.name01
00
00
diff --git a/pandas/tests/io/formats/data/html/index_none_columns_none.html b/pandas/tests/io/formats/data/html/index_none_columns_none.html new file mode 100644 index 0000000000000..44899858d9519 --- /dev/null +++ b/pandas/tests/io/formats/data/html/index_none_columns_none.html @@ -0,0 +1,12 @@ + + + + + + + + + + + +
00
00
diff --git a/pandas/tests/io/formats/data/html/index_none_columns_unnamed_multi.html b/pandas/tests/io/formats/data/html/index_none_columns_unnamed_multi.html new file mode 100644 index 0000000000000..b21a618328b1b --- /dev/null +++ b/pandas/tests/io/formats/data/html/index_none_columns_unnamed_multi.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + +
a
bc
00
00
diff --git a/pandas/tests/io/formats/data/html/index_none_columns_unnamed_standard.html b/pandas/tests/io/formats/data/html/index_none_columns_unnamed_standard.html new file mode 100644 index 0000000000000..1249fa5605099 --- /dev/null +++ b/pandas/tests/io/formats/data/html/index_none_columns_unnamed_standard.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + +
01
00
00
diff --git a/pandas/tests/io/formats/data/html/index_unnamed_multi_columns_named_multi.html b/pandas/tests/io/formats/data/html/index_unnamed_multi_columns_named_multi.html new file mode 100644 index 0000000000000..95c38c9c8fd28 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/index_unnamed_multi_columns_named_standard.html b/pandas/tests/io/formats/data/html/index_unnamed_multi_columns_named_standard.html new file mode 100644 index 0000000000000..9583a21f55f01 --- /dev/null +++ b/pandas/tests/io/formats/data/html/index_unnamed_multi_columns_named_standard.html @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + +
columns.name01
ab00
c00
diff --git a/pandas/tests/io/formats/data/html/index_unnamed_multi_columns_unnamed_multi.html b/pandas/tests/io/formats/data/html/index_unnamed_multi_columns_unnamed_multi.html new file mode 100644 index 0000000000000..f620259037b60 --- /dev/null +++ b/pandas/tests/io/formats/data/html/index_unnamed_multi_columns_unnamed_multi.html @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
a
bc
ab00
c00
diff --git a/pandas/tests/io/formats/data/html/index_unnamed_multi_columns_unnamed_standard.html b/pandas/tests/io/formats/data/html/index_unnamed_multi_columns_unnamed_standard.html new file mode 100644 index 0000000000000..2ca18c288437b --- /dev/null +++ b/pandas/tests/io/formats/data/html/index_unnamed_multi_columns_unnamed_standard.html @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + +
01
ab00
c00
diff --git a/pandas/tests/io/formats/data/html/index_unnamed_standard_columns_named_multi.html b/pandas/tests/io/formats/data/html/index_unnamed_standard_columns_named_multi.html new file mode 100644 index 0000000000000..ed3360f898afd --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/index_unnamed_standard_columns_named_standard.html b/pandas/tests/io/formats/data/html/index_unnamed_standard_columns_named_standard.html new file mode 100644 index 0000000000000..54da03858a9a4 --- /dev/null +++ b/pandas/tests/io/formats/data/html/index_unnamed_standard_columns_named_standard.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + +
columns.name01
000
100
diff --git a/pandas/tests/io/formats/data/html/index_unnamed_standard_columns_unnamed_multi.html b/pandas/tests/io/formats/data/html/index_unnamed_standard_columns_unnamed_multi.html new file mode 100644 index 0000000000000..b57fafbe0ca40 --- /dev/null +++ b/pandas/tests/io/formats/data/html/index_unnamed_standard_columns_unnamed_multi.html @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
a
bc
000
100
diff --git a/pandas/tests/io/formats/data/html/index_unnamed_standard_columns_unnamed_standard.html b/pandas/tests/io/formats/data/html/index_unnamed_standard_columns_unnamed_standard.html new file mode 100644 index 0000000000000..235ca61a9e63d --- /dev/null +++ b/pandas/tests/io/formats/data/html/index_unnamed_standard_columns_unnamed_standard.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + +
01
000
100
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/html/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 new file mode 100644 index 0000000000000..e66d3c816e67d --- /dev/null +++ b/pandas/tests/io/formats/data/html/trunc_df_index_named_multi_columns_named_multi.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/data/html/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 new file mode 100644 index 0000000000000..536b371145081 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/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 new file mode 100644 index 0000000000000..d472cdecb12c9 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/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 new file mode 100644 index 0000000000000..31c71ca3e59f6 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/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 new file mode 100644 index 0000000000000..779e84f6ee6d1 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/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 new file mode 100644 index 0000000000000..b86454f5fb11f --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/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 new file mode 100644 index 0000000000000..24b776e18bef9 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/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 new file mode 100644 index 0000000000000..a0ca960207ac0 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/trunc_df_index_none_columns_named_multi.html b/pandas/tests/io/formats/data/html/trunc_df_index_none_columns_named_multi.html new file mode 100644 index 0000000000000..6640db4cf8704 --- /dev/null +++ b/pandas/tests/io/formats/data/html/trunc_df_index_none_columns_named_multi.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/html/trunc_df_index_none_columns_named_standard.html b/pandas/tests/io/formats/data/html/trunc_df_index_none_columns_named_standard.html new file mode 100644 index 0000000000000..364a0b98d6548 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/trunc_df_index_none_columns_none.html b/pandas/tests/io/formats/data/html/trunc_df_index_none_columns_none.html new file mode 100644 index 0000000000000..e2af1ba42e940 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/trunc_df_index_none_columns_unnamed_multi.html b/pandas/tests/io/formats/data/html/trunc_df_index_none_columns_unnamed_multi.html new file mode 100644 index 0000000000000..8c9a9e244277b --- /dev/null +++ b/pandas/tests/io/formats/data/html/trunc_df_index_none_columns_unnamed_multi.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/html/trunc_df_index_none_columns_unnamed_standard.html b/pandas/tests/io/formats/data/html/trunc_df_index_none_columns_unnamed_standard.html new file mode 100644 index 0000000000000..b9dcf52619490 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/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 new file mode 100644 index 0000000000000..0590d0dea6669 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/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 new file mode 100644 index 0000000000000..28a2d964675a3 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/trunc_df_index_unnamed_multi_columns_none.html b/pandas/tests/io/formats/data/html/trunc_df_index_unnamed_multi_columns_none.html new file mode 100644 index 0000000000000..387ac51b17634 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/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 new file mode 100644 index 0000000000000..30cd85904be4e --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/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 new file mode 100644 index 0000000000000..81edece220408 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/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 new file mode 100644 index 0000000000000..2acacfed3a6d0 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/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 new file mode 100644 index 0000000000000..c9bacdbd241a6 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/trunc_df_index_unnamed_standard_columns_none.html b/pandas/tests/io/formats/data/html/trunc_df_index_unnamed_standard_columns_none.html new file mode 100644 index 0000000000000..f2696f7d6b46a --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/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 new file mode 100644 index 0000000000000..37e731520c7d9 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/html/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 new file mode 100644 index 0000000000000..3241ff41c5c58 --- /dev/null +++ b/pandas/tests/io/formats/data/html/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/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 6c2d12076a262..eb11433f46c0e 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() @@ -414,6 +414,96 @@ def test_to_html_multiindex_max_cols(self, datapath): expected = expected_html(datapath, 'gh6131_expected_output') assert result == expected + def test_to_html_multi_indexes_index_false(self, datapath): + # GH 22579 + 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 + + @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 + df = DataFrame(np.zeros((2, 2), dtype=int), + index=row_index, columns=column_index) + result = df.to_html(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 = 'index_' + row_type + '_columns_' + column_type + 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 @@ -428,13 +518,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):