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

Conversation

CRP
Copy link
Contributor

@CRP CRP commented May 25, 2017

@TomAugspurger
Copy link
Contributor

Thanks. Could you add a test to verify the output is correct? Something simple like

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

You should probably also do some checking that there blank rows aren't put in either.
It can go in pandas/tests/io/formats/test_to_html.py

Also need a release not in doc/source/whatsnew/v0.20.2.txt. Thanks!

@TomAugspurger TomAugspurger added IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string labels May 25, 2017
@TomAugspurger TomAugspurger modified the milestones: won't fix, 0.20.2 May 25, 2017
@TomAugspurger TomAugspurger changed the title BUG: fix for bug 16493 Fixed to_html ignoring index_names parameter May 25, 2017
@TomAugspurger
Copy link
Contributor

Oh, you'll also need to use self.fmt.show_index_names (need the .fmt in there). For reference, most (all?) of the common DataFrame formatting arguments are bundled into a DataFrameFormatter, which is then passed as the first argument to HTMLFormatter.

@CRP
Copy link
Contributor Author

CRP commented May 25, 2017 via email

Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

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

Sorry, looks like it's saved as show_index_names on DataFrameFormatter, not index_names.

FYI you can test it locally with pytest pandas/tests/io/formats/test_to_html.py -k test_to_html_with_index_names_false. It also looks like that line is too long: https://travis-ci.org/pandas-dev/pandas/jobs/236007626#L2829

@@ -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`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Change to_html to

``DataFrame.to_html``

and put index_names in double backticks

@CRP
Copy link
Contributor Author

CRP commented May 25, 2017 via email

@TomAugspurger
Copy link
Contributor

Your image didn't show up, so I don't know what lines you're referring to.

You shouldn't have to change any parameter names. I must have been confused though. The current version is correct (the line might be too long though. Try flake8 pandas/io/formats/format.py to make sure)

@codecov
Copy link

codecov bot commented May 26, 2017

Codecov Report

Merging #16495 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #16495   +/-   ##
=======================================
  Coverage   90.43%   90.43%           
=======================================
  Files         161      161           
  Lines       51045    51045           
=======================================
  Hits        46161    46161           
  Misses       4884     4884
Flag Coverage Δ
#multiple 88.27% <100%> (ø) ⬆️
#single 40.16% <0%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/io/formats/format.py 96.02% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e41fe7f...20d512f. Read the comment docs.

@codecov
Copy link

codecov bot commented May 26, 2017

Codecov Report

Merging #16495 into master will increase coverage by 0.36%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #16495      +/-   ##
==========================================
+ Coverage   90.43%   90.79%   +0.36%     
==========================================
  Files         161      161              
  Lines       51045    51063      +18     
==========================================
+ Hits        46161    46365     +204     
+ Misses       4884     4698     -186
Flag Coverage Δ
#multiple 88.63% <100%> (+0.36%) ⬆️
#single 40.15% <0%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/io/formats/format.py 96.02% <100%> (ø) ⬆️
pandas/plotting/_converter.py 63.23% <0%> (-1.82%) ⬇️
pandas/core/categorical.py 95.5% <0%> (-0.42%) ⬇️
pandas/core/frame.py 97.66% <0%> (-0.03%) ⬇️
pandas/core/reshape/pivot.py 95.08% <0%> (ø) ⬆️
pandas/core/resample.py 96.09% <0%> (+0.01%) ⬆️
pandas/core/generic.py 92.26% <0%> (+0.09%) ⬆️
pandas/core/series.py 94.9% <0%> (+0.18%) ⬆️
pandas/util/testing.py 80.98% <0%> (+0.19%) ⬆️
pandas/io/parsers.py 95.66% <0%> (+0.32%) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e41fe7f...567ae69. Read the comment docs.

@CRP
Copy link
Contributor Author

CRP commented May 26, 2017 via email

@TomAugspurger
Copy link
Contributor

TomAugspurger commented May 26, 2017 via email

@CRP
Copy link
Contributor Author

CRP commented May 26, 2017 via email

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

lgtm. minor comment.

@@ -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.

@@ -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()

@TomAugspurger
Copy link
Contributor

@CRP make sure to pull this branch before pushing those fixes. I pushed a commit fixing a small lint error.

@CRP
Copy link
Contributor Author

CRP commented Jun 1, 2017 via email

@jreback
Copy link
Contributor

jreback commented Jun 1, 2017

thanks!

TomAugspurger pushed a commit to TomAugspurger/pandas that referenced this pull request Jun 1, 2017
closes pandas-dev#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 pandas-dev#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)
TomAugspurger pushed a commit that referenced this pull request Jun 4, 2017
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)
Kiv pushed a commit to Kiv/pandas that referenced this pull request Jun 11, 2017
closes pandas-dev#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 pandas-dev#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
stangirala pushed a commit to stangirala/pandas that referenced this pull request Jun 11, 2017
closes pandas-dev#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 pandas-dev#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

to_html(index_names=False) still renders a row with index names
3 participants