BUG-25061 fix printing indices with NaNs
State: closed

- [X] closes #25061- [ ] tests added / passed
- [X] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [X] whatsnew entry

The `FloatArrayFormatter` leaves a space in front of the floats it formats (expected behaviour as demonstrated by [this test](https://github.com/pandas-dev/pandas/blob/638ddebaa7da1e569836a5b89593b120dbbf491c/pandas/tests/io/formats/test_format.py#L2395)). To avoid misaligned values when printing indices, `NaN` values must be treated similarly.

Labels:
name: Output-Formatting
description: __repr__ of pandas objects, to_string
name: Categorical
description: Categorical Data Type

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

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

```diff
@@            Coverage Diff             @@
##           master   #25202      +/-   ##
==========================================
- Coverage   92.35%   92.34%   -0.01%     
==========================================
  Files         166      166              
  Lines       52314    52316       +2     
==========================================
+ Hits        48312    48313       +1     
- Misses       4002     4003       +1
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.78% <100%> (ø)` | :arrow_up: |
| #single | `42.84% <50%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25202?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/formats/format.py](https://codecov.io/gh/pandas-dev/pandas/pull/25202/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZm9ybWF0LnB5) | `97.99% <100%> (ø)` | :arrow_up: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/25202/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `87.95% <0%> (-0.1%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25202?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/25202?src=pr&el=footer). Last update [638ddeb...27b42a5](https://codecov.io/gh/pandas-dev/pandas/pull/25202?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/25202?src=pr&el=h1) Report
> Merging [#25202](https://codecov.io/gh/pandas-dev/pandas/pull/25202?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/04df22fbeec782f474bcff20480eded04e0d1d82?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/25202/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/25202?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #25202      +/-   ##
==========================================
+ Coverage   91.89%   91.89%   +<.01%     
==========================================
  Files         166      166              
  Lines       52226    52229       +3     
==========================================
+ Hits        47993    47996       +3     
  Misses       4233     4233
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.44% <100%> (ø)` | :arrow_up: |
| #single | `42.13% <80%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25202?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/formats/format.py](https://codecov.io/gh/pandas-dev/pandas/pull/25202/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZm9ybWF0LnB5) | `97.99% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25202?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/25202?src=pr&el=footer). Last update [04df22f...88cbca9](https://codecov.io/gh/pandas-dev/pandas/pull/25202?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

thanks @JustinZhengBC