TST: test custom _formatter for ExtensionArray + revert ExtensionArrayFormatter removal
State: closed

xref https://github.com/pandas-dev/pandas/pull/26833#issuecomment-502012046

@simonjayhawkins this would be a test for the `_formatter` functionality (it is passing on master before the removal of ExtensionArrayFormatter

Adds an actual test for EA._formatter + reverts https://github.com/pandas-dev/pandas/pull/26833 until we have a more complete solution for simplifying the formatters that take the EA._formatter into account.

Labels:
name: Output-Formatting
description: __repr__ of pandas objects, to_string
name: ExtensionArray
description: Extending pandas with custom dtypes or arrays.

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26845?src=pr&el=h1) Report
> Merging [#26845](https://codecov.io/gh/pandas-dev/pandas/pull/26845?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/8374a1d2a58245067669cd6424793b134a695971?src=pr&el=desc) will **decrease** coverage by `50.73%`.
> The diff coverage is `n/a`.

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

```diff
@@             Coverage Diff             @@
##           master   #26845       +/-   ##
===========================================
- Coverage   91.86%   41.12%   -50.74%     
===========================================
  Files         179      179               
  Lines       50700    50700               
===========================================
- Hits        46576    20851    -25725     
- Misses       4124    29849    +25725
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `?` | |
| #single | `41.12% <ø> (-0.06%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26845?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/formats/latex.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvbGF0ZXgucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/plotting/\_matplotlib/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19tYXRwbG90bGliL19faW5pdF9fLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/gcs.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2djcy5weQ==) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/sas/sas\_constants.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfY29uc3RhbnRzLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/core/groupby/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9jYXRlZ29yaWNhbC5weQ==) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/plotting.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvcGxvdHRpbmcucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/s3.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3MzLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/formats/html.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvaHRtbC5weQ==) | `0% <0%> (-99.37%)` | :arrow_down: |
| [pandas/io/sas/sas7bdat.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXM3YmRhdC5weQ==) | `0% <0%> (-91.16%)` | :arrow_down: |
| [pandas/io/sas/sas\_xport.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfeHBvcnQucHk=) | `0% <0%> (-90.1%)` | :arrow_down: |
| ... and [132 more](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree-more) | |

------

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

```diff
@@            Coverage Diff             @@
##           master   #26845      +/-   ##
==========================================
- Coverage   91.86%   91.86%   -0.01%     
==========================================
  Files         179      179              
  Lines       50700    50706       +6     
==========================================
+ Hits        46576    46580       +4     
- Misses       4124     4126       +2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.45% <100%> (ø)` | :arrow_up: |
| #single | `41.1% <25%> (-0.08%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26845?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/formats/format.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZm9ybWF0LnB5) | `97.9% <100%> (+0.01%)` | :arrow_up: |
| [pandas/core/indexes/interval.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9pbnRlcnZhbC5weQ==) | `96.44% <100%> (ø)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `88.88% <0%> (-11.12%)` | :arrow_down: |
| [pandas/io/formats/printing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvcHJpbnRpbmcucHk=) | `85.56% <0%> (-0.54%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.88% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `90.84% <0%> (-0.11%)` | :arrow_down: |
| [pandas/core/arrays/sparse.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL3NwYXJzZS5weQ==) | `93.71% <0%> (+0.11%)` | :arrow_up: |
| [pandas/core/arrays/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2NhdGVnb3JpY2FsLnB5) | `95.92% <0%> (+0.12%)` | :arrow_up: |
| [pandas/core/arrays/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL3BlcmlvZC5weQ==) | `98.54% <0%> (+0.24%)` | :arrow_up: |
| [pandas/core/arrays/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/26845/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2Jhc2UucHk=) | `99.43% <0%> (+0.56%)` | :arrow_up: |

------

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

why revert this? it is just causing churn. it was clear that the change was just a step in fixing this. tests are ok.
Did you read my comments in the PR? (https://github.com/pandas-dev/pandas/pull/26833#issuecomment-502012046) Then please give reasons why you would rather break the EA interface instead of temporarily reverting. We can fix issues with formatting in a better way in follow-up PRs. 

Without the revert, the test will fail, so I could only add a xfailed test. 
> Did you read my comments in the PR? ([#26833 (comment)](https://github.com/pandas-dev/pandas/pull/26833#issuecomment-502012046)) Then please give reasons why you would rather break the EA interface instead of temporarily reverting. We can fix issues with formatting in a better way in follow-up PRs.
> 
> Without the revert, the test will fail, so I could only add a xfailed test.

I read your comment. I disagree.
I’d prefer not breaking things. 

> On Jun 14, 2019, at 07:32, Jeff Reback <notifications@github.com> wrote:
> 
> Did you read my comments in the PR? (#26833 (comment)) Then please give reasons why you would rather break the EA interface instead of temporarily reverting. We can fix issues with formatting in a better way in follow-up PRs.
> 
> Without the revert, the test will fail, so I could only add a xfailed test.
> 
> I read your comment. I disagree.
> 
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub, or mute the thread.

> I read your comment. I disagree.

Can you then please give some reasoning? 
how is this breaking an existing test? it did NOT. If you add something, then let's fix it. But reverting is kind of silly here. What to preserve some kind of history? this is just churning for no good reason. 

It was very explicit that this was merged to provide an easier change path. I don't see anything that has changed.

If you want to merge an xfail test, sure.
Jeff, it only broke no tests because we forgot to properly test it. But what I am adding a test for here, has always been the *intention* of the `_formatter` method of the EA interface. And we for sure broke that.
> Jeff, it only broke no tests because we forgot to properly test it. But what I am adding a test for here, has always been the _intention_ of the `_formatter` method of the EA interface. And we for sure broke that.

EA._formatter is completely and utterly broken. Papering this over is not going to help. Let's just move forward. As I said I am happy to merge the test with an xfail. 
Lets no break other libraries relying on the documented behavior.  

> On Jun 14, 2019, at 07:43, Jeff Reback <notifications@github.com> wrote:
> 
> Jeff, it only broke no tests because we forgot to properly test it. But what I am adding a test for here, has always been the intention of the _formatter method of the EA interface. And we for sure broke that.
> 
> EA._formatter is completely and utterly broken. Papering this over is not going to help. Let's just move forward. As I said I am happy to merge the test with an xfail.
> 
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub, or mute the thread.

> EA._formatter is completely and utterly broken.

This method was purposefully introduced recently as part of the EA interface: https://github.com/pandas-dev/pandas/pull/23601 (a PR that you approved, without calling it "utterly broken")
> Lets no break other libraries relying on the documented behavior.

and w/o a test that is useless. If you want to fix it go right ahead. But as I said reverting is just churn. Would rather actually fix this, which has been broken for forever. 

So this will be broken until then
> This method was purposefully introduced recently as part of the EA interface: #23601 (a PR that you approved, without calling it "utterly broken")

That's utterly ridiculous, I approve virtually PRs. 
Actually IIRC I voiced many many arguments on how Index / EA repr's are completely different and you guys pushed it thru.

So if its broken , then please fix it.

merging to avoid this vacuous argument.
Thanks for merging. 

> IIRC I voiced many many arguments on how Index / EA repr's are completely different and you guys pushed it thru.

Yes, we had disagreements about that. But as a final thing, I want to note that this discussion is *not* about the difference between Index vs Series vs EA reprs, but about the simple fact that EAs need a way to control how their scalar values are represented in any of those reprs. That is a basic functionality we had from the beginning of the EA interface (even before we had the discussion about the default repr).