Skip to content

Fixed to_html ignoring index_names parameter #16495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.20.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ``DataFrame.to_html`` ignored the ``index_names`` parameter (:issue:`16493`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DataFrame.to_html()



Plotting
Expand Down
4 changes: 3 additions & 1 deletion pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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))
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/io/formats/test_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -1869,3 +1869,9 @@ 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'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add the issue reference as a comment.

name='myindexname'))
result = df.to_html(index_names=False)
assert 'myindexname' not in result