Skip to content

Commit e3ee186

Browse files
CRPjreback
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
1 parent e0a127a commit e3ee186

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
@@ -71,6 +71,7 @@ I/O
7171
- Bug that would force importing of the clipboard routines unnecessarily, potentially causing an import error on startup (:issue:`16288`)
7272
- Bug that raised IndexError HTML-rendering an empty DataFrame (:issue:`15953`)
7373
- Bug in ``pd.read_csv()`` in which tarfile object inputs were raising an error in Python 2.x for the C engine (:issue:`16530`)
74+
- Bug where ``DataFrame.to_html()`` ignored the ``index_names`` parameter (:issue:`16493`)
7475

7576
- Bug in ``HDFStore.select_as_multiple()`` where start/stop arguments were not respected (:issue:`16209`)
7677

pandas/io/formats/format.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,9 @@ def _column_header():
12921292
self.write_tr(col_row, indent, self.indent_delta, header=True,
12931293
align=align)
12941294

1295-
if self.fmt.has_index_names and self.fmt.index:
1295+
if all((self.fmt.has_index_names,
1296+
self.fmt.index,
1297+
self.fmt.show_index_names)):
12961298
row = ([x if x is not None else ''
12971299
for x in self.frame.index.names] +
12981300
[''] * 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)