From a40820dee02d8f37a63611975fc17d7e1c87dc47 Mon Sep 17 00:00:00 2001 From: Christian Prinoth Date: Thu, 25 May 2017 14:59:46 +0200 Subject: [PATCH 1/7] BUG: fix for bug 16493 --- pandas/io/formats/format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 054db769c56dd..4cd3f1d58603d 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1292,7 +1292,7 @@ def _column_header(): self.write_tr(col_row, indent, self.indent_delta, header=True, align=align) - if self.fmt.has_index_names and self.fmt.index: + if self.fmt.has_index_names and self.fmt.index and self.show_index_names: row = ([x if x is not None else '' for x in self.frame.index.names] + [''] * min(len(self.columns), self.max_cols)) From 426565e78c2bd09a78d15d8eab153868fef47649 Mon Sep 17 00:00:00 2001 From: Christian Prinoth Date: Thu, 25 May 2017 17:59:17 +0200 Subject: [PATCH 2/7] BUG: fix for bug 16493 --- doc/source/whatsnew/v0.20.2.txt | 1 + pandas/io/formats/format.py | 2 +- pandas/tests/io/formats/test_to_html.py | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.20.2.txt b/doc/source/whatsnew/v0.20.2.txt index 1f71710d19e44..582482c947319 100644 --- a/doc/source/whatsnew/v0.20.2.txt +++ b/doc/source/whatsnew/v0.20.2.txt @@ -59,6 +59,7 @@ I/O - Bug in pd.read_csv() when comment is passed in space deliminted text files (:issue:`16472`) - Bug that would force importing of the clipboard routines unnecessarily, potentially causing an import error on startup (:issue:`16288`) - Bug that raised IndexError HTML-rendering an empty DataFrame (:issue:`15953`) +- Bug where to_html ignored the index_names parameter (:issue:`16493`) Plotting diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 4cd3f1d58603d..e111a17b28dbe 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1292,7 +1292,7 @@ def _column_header(): self.write_tr(col_row, indent, self.indent_delta, header=True, align=align) - if self.fmt.has_index_names and self.fmt.index and self.show_index_names: + if self.fmt.has_index_names and self.fmt.index and self.fmt.show_index_names: row = ([x if x is not None else '' for x in self.frame.index.names] + [''] * min(len(self.columns), self.max_cols)) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index cde920b1511d2..5ee8d5652ad2a 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -1869,3 +1869,8 @@ def test_to_html_notebook_has_no_style(self): df = pd.DataFrame({"A": [1, 2, 3]}) result = df.to_html() assert "thead tr:only-child" not in result + + def test_to_html_with_index_names_false(self): + df = pd.DataFrame({"A": [1, 2], index=pd.Index(['a', 'b'], name='myindexname'}) + result = df.to_html(index_names=False) + assert 'myindexname' not in result From 6bef82970230a89f1be1dd0546dab938838d334c Mon Sep 17 00:00:00 2001 From: Christian Prinoth Date: Thu, 25 May 2017 18:50:14 +0200 Subject: [PATCH 3/7] BUG: fix for bug 16493 --- doc/source/whatsnew/v0.20.2.txt | 2 +- pandas/tests/io/formats/test_to_html.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.20.2.txt b/doc/source/whatsnew/v0.20.2.txt index 582482c947319..5a5245b7539f4 100644 --- a/doc/source/whatsnew/v0.20.2.txt +++ b/doc/source/whatsnew/v0.20.2.txt @@ -59,7 +59,7 @@ I/O - Bug in pd.read_csv() when comment is passed in space deliminted text files (:issue:`16472`) - Bug that would force importing of the clipboard routines unnecessarily, potentially causing an import error on startup (:issue:`16288`) - Bug that raised IndexError HTML-rendering an empty DataFrame (:issue:`15953`) -- Bug where to_html ignored the index_names parameter (:issue:`16493`) +- Bug where ``DataFrame.to_html`` ignored the ``index_names`` parameter (:issue:`16493`) Plotting diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 5ee8d5652ad2a..c379d299fcb7c 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -1871,6 +1871,6 @@ def test_to_html_notebook_has_no_style(self): assert "thead tr:only-child" not in result def test_to_html_with_index_names_false(self): - df = pd.DataFrame({"A": [1, 2], index=pd.Index(['a', 'b'], name='myindexname'}) + df = pd.DataFrame({"A": [1, 2]}, index=pd.Index(['a', 'b'], name='myindexname')) result = df.to_html(index_names=False) assert 'myindexname' not in result From 20d512f08afe028263b257a2ba32507fc6f41508 Mon Sep 17 00:00:00 2001 From: Christian Prinoth Date: Fri, 26 May 2017 09:15:57 +0200 Subject: [PATCH 4/7] BUG: fix for bug 16493 --- pandas/io/formats/format.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index e111a17b28dbe..d5449b4086974 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1292,7 +1292,9 @@ def _column_header(): self.write_tr(col_row, indent, self.indent_delta, header=True, align=align) - if self.fmt.has_index_names and self.fmt.index and self.fmt.show_index_names: + if all(self.fmt.has_index_names, + self.fmt.index, + self.fmt.show_index_names): row = ([x if x is not None else '' for x in self.frame.index.names] + [''] * min(len(self.columns), self.max_cols)) From 469a0e6000c4e2afa631bd390a08204ff4005b10 Mon Sep 17 00:00:00 2001 From: Christian Prinoth Date: Fri, 26 May 2017 15:14:05 +0200 Subject: [PATCH 5/7] BUG: fix for bug 16493 --- pandas/io/formats/format.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index d5449b4086974..3deaec2dfbbc5 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1292,9 +1292,9 @@ def _column_header(): self.write_tr(col_row, indent, self.indent_delta, header=True, align=align) - if all(self.fmt.has_index_names, + if all((self.fmt.has_index_names, self.fmt.index, - self.fmt.show_index_names): + self.fmt.show_index_names)): row = ([x if x is not None else '' for x in self.frame.index.names] + [''] * min(len(self.columns), self.max_cols)) From 8429f9a292e6a055cea9cc2ffafc120fb911d4a0 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Tue, 30 May 2017 16:33:24 -0500 Subject: [PATCH 6/7] Fixed lint error --- pandas/tests/io/formats/test_to_html.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index c379d299fcb7c..e9f5fabb5d63b 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -1871,6 +1871,7 @@ def test_to_html_notebook_has_no_style(self): assert "thead tr:only-child" not in result def test_to_html_with_index_names_false(self): - df = pd.DataFrame({"A": [1, 2]}, index=pd.Index(['a', 'b'], name='myindexname')) + df = pd.DataFrame({"A": [1, 2]}, index=pd.Index(['a', 'b'], + name='myindexname')) result = df.to_html(index_names=False) assert 'myindexname' not in result From 567ae69690e80ac07955eb8071dd45db758d3de1 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Thu, 1 Jun 2017 06:45:32 -0400 Subject: [PATCH 7/7] doc corrections --- doc/source/whatsnew/v0.20.2.txt | 2 +- pandas/tests/io/formats/test_to_html.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.20.2.txt b/doc/source/whatsnew/v0.20.2.txt index 5a5245b7539f4..7f04a6a12b480 100644 --- a/doc/source/whatsnew/v0.20.2.txt +++ b/doc/source/whatsnew/v0.20.2.txt @@ -59,7 +59,7 @@ I/O - Bug in pd.read_csv() when comment is passed in space deliminted text files (:issue:`16472`) - Bug that would force importing of the clipboard routines unnecessarily, potentially causing an import error on startup (:issue:`16288`) - Bug that raised IndexError HTML-rendering an empty DataFrame (:issue:`15953`) -- Bug where ``DataFrame.to_html`` ignored the ``index_names`` parameter (:issue:`16493`) +- Bug where ``DataFrame.to_html()`` ignored the ``index_names`` parameter (:issue:`16493`) Plotting diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index e9f5fabb5d63b..9f4e532ec2287 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -1871,6 +1871,7 @@ def test_to_html_notebook_has_no_style(self): assert "thead tr:only-child" not in result def test_to_html_with_index_names_false(self): + # gh-16493 df = pd.DataFrame({"A": [1, 2]}, index=pd.Index(['a', 'b'], name='myindexname')) result = df.to_html(index_names=False)