BUG: output formatting with to_html(), index=False and/or index_names=False (#22579, #22747)
State: closed

- [x] closes #22579
- [x] closes #22747
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Output-Formatting
description: __repr__ of pandas objects, to_string
name: IO HTML
description: read_html, to_html, Styler.apply, Styler.applymap

Comments:
Hello @simonjayhawkins! Thanks for updating the PR.





Cheers ! There are no PEP8 issues in this Pull Request. :beers: 

##### Comment last updated on December 28, 2018 at 15:37 Hours UTC
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22655?src=pr&el=h1) Report
> Merging [#22655](https://codecov.io/gh/pandas-dev/pandas/pull/22655?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/0976e1261781153603064eb67d66630a099edcd7?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/22655/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/22655?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #22655      +/-   ##
==========================================
+ Coverage   92.17%   92.18%   +<.01%     
==========================================
  Files         169      169              
  Lines       50708    50697      -11     
==========================================
- Hits        46740    46734       -6     
+ Misses       3968     3963       -5
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.59% <100%> (ø)` | :arrow_up: |
| #single | `42.36% <0%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/22655?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/formats/html.py](https://codecov.io/gh/pandas-dev/pandas/pull/22655/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvaHRtbC5weQ==) | `91.96% <100%> (+1.27%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22655?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22655?src=pr&el=footer). Last update [0976e12...6b441df](https://codecov.io/gh/pandas-dev/pandas/pull/22655?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22655?src=pr&el=h1) Report
> Merging [#22655](https://codecov.io/gh/pandas-dev/pandas/pull/22655?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/ab55d05e7a12ebbccfd71511d36efa075fcfa0dc?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/22655/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/22655?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #22655      +/-   ##
==========================================
+ Coverage   92.29%   92.29%   +<.01%     
==========================================
  Files         163      163              
  Lines       51948    51956       +8     
==========================================
+ Hits        47945    47953       +8     
  Misses       4003     4003
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.7% <100%> (ø)` | :arrow_up: |
| #single | `42.99% <0%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/22655?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/formats/html.py](https://codecov.io/gh/pandas-dev/pandas/pull/22655/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvaHRtbC5weQ==) | `98.67% <100%> (+0.03%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22655?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22655?src=pr&el=footer). Last update [ab55d05...5b635e4](https://codecov.io/gh/pandas-dev/pandas/pull/22655?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

@WillAyd : `index_names=False` and `index=False` issues can be separated. Since there is an issue on the `index_names=False` with `index=True` codepath, I'll raise this as a separate issue and a separate PR.

We can then move forward on the test methodology.

In order to resolve the alignment issues for this PR,  I'll need to add some additional tests to the basic alignment checks that I've done so far to ensure that the truncation indicators are also aligned correctly after shifting the header.
@WillAyd : looks like I will need to fix #15019 first before i can check the misalignment is corrected on a truncated DataFrame.
@simonjayhawkins please ping when ready for review
@WillAyd If you could take another look that'll be great. Thanks.

> @WillAyd : index_names=False and index=False issues can be separated. Since there is an issue on the index_names=False with index=True codepath, I'll raise this as a separate issue and a separate PR.

This PR is closing both these issues. I was originally planning to raise a separate PR to reduce the scope of this one. Please let me know if you think that will still be necessary after having a quick look.

I'll leave this PR marked as WIP for the moment because of potential merge conflicts with #22726
@WillAyd : Thanks for the review. I've addressed the couple of style issues. just the test complexity to resolve. I'm happy with the current approach but if you're not let me know how to proceed.
@WillAyd I'll make the changes as you have suggested since if the tests are all passing the readability of the test logs is irrelevant. however, while coding the bug fixes the improved readability of the test logs were invaluable.
@WillAyd @jreback comments addressed. ptal.
@jreback @WillAyd with the additional parameterization of the truncation tests, we now have test coverage for multi-indexes with more than 2 rows, missing column index names and truncation with standard row indexes. There is now test coverage in place allowing the refactoring of `row-levels` to class property in this PR for use by `_write_header` and `_write_regular_rows`. I've added a TODO in `_write_hierarchical_rows` to refactor after #22887 is fixed
@WillAyd @jreback Could you please take another look. Thanks. 
I would make a sub-dir of data/html to hold all of this test data (and move the original .html files as well).
@WillAyd over to you
@WillAyd 
Thanks @simonjayhawkins !
thanks @simonjayhawkins !