Skip to content

Commit 3981755

Browse files
CRPTomAugspurger
authored andcommitted
BUG: Fixed to_html ignoring index_names parameter
closes #16493 Author: Christian Prinoth <[email protected]> Author: Tom Augspurger <[email protected]> Author: Christian Prinoth <[email protected]> Author: Jeff Reback <[email protected]> This patch had conflicts when merged, resolved by Committer: Jeff Reback <[email protected]> Closes #16495 from CRP/bugfix_16493 and squashes the following commits: 567ae69 [Jeff Reback] doc corrections 8429f9a [Tom Augspurger] Fixed lint error 469a0e6 [Christian Prinoth] BUG: fix for bug 16493 20d512f [Christian Prinoth] BUG: fix for bug 16493 6bef829 [Christian Prinoth] BUG: fix for bug 16493 426565e [Christian Prinoth] BUG: fix for bug 16493 a40820d [Christian Prinoth] BUG: fix for bug 16493 (cherry picked from commit e3ee186)
1 parent 4a35ee8 commit 3981755

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

doc/source/whatsnew/v0.20.2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ I/O
6464
- Bug that would force importing of the clipboard routines unnecessarily, potentially causing an import error on startup (:issue:`16288`)
6565
- Bug that raised IndexError HTML-rendering an empty DataFrame (:issue:`15953`)
6666
- Bug in ``pd.read_csv()`` in which tarfile object inputs were raising an error in Python 2.x for the C engine (:issue:`16530`)
67+
- Bug where ``DataFrame.to_html()`` ignored the ``index_names`` parameter (:issue:`16493`)
6768

6869

6970
Plotting

pandas/io/formats/format.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,9 @@ def _column_header():
12891289
self.write_tr(col_row, indent, self.indent_delta, header=True,
12901290
align=align)
12911291

1292-
if self.fmt.has_index_names and self.fmt.index:
1292+
if all((self.fmt.has_index_names,
1293+
self.fmt.index,
1294+
self.fmt.show_index_names)):
12931295
row = ([x if x is not None else ''
12941296
for x in self.frame.index.names] +
12951297
[''] * min(len(self.columns), self.max_cols))

pandas/tests/io/formats/test_to_html.py

+7
Original file line numberDiff line numberDiff line change
@@ -1869,3 +1869,10 @@ def test_to_html_notebook_has_no_style(self):
18691869
df = pd.DataFrame({"A": [1, 2, 3]})
18701870
result = df.to_html()
18711871
assert "thead tr:only-child" not in result
1872+
1873+
def test_to_html_with_index_names_false(self):
1874+
# gh-16493
1875+
df = pd.DataFrame({"A": [1, 2]}, index=pd.Index(['a', 'b'],
1876+
name='myindexname'))
1877+
result = df.to_html(index_names=False)
1878+
assert 'myindexname' not in result

0 commit comments

Comments
 (0)