register custom DisplayFormatter for table schema
State: closed

instead of using `_ipython_display_` for custom mime-types

This should solve the issues in #16171, without needing to register/unregister `_ipython_display_`.

In the long run, https://github.com/ipython/ipython/pull/10496 should remove the need for any custom registration, in favor of a simple `_repr_mimebundle_` method.

I think the only thing missing is the UnserializableWarning because IPython does its own catching and displaying of tracebacks when formatters fail. I can copy and modify a little more code out of the base Formatter to preserve that warning, though.

Labels:

Comments:
About the UnserializeableWarning, what's the behavior from the PR when pandas `_repr_table_schema_` fails?

For background, some DataFrames just can't be serialized according to the table schema spec. In these cases, we'd ideally fall back to `_repr_html_`.
> For background, some DataFrames just can't be serialized according to the table schema spec. In these cases, we'd ideally fall back to _repr_html_.

Oh neat, it looks like it falls back to the next formatter. That's perfect.

So we can just get rid of the `UnserializableWarning` altogether then (I added it just for this). I can take care of that if you want.
> About the UnserializeableWarning, what's the behavior from the PR when pandas _repr_table_schema_ fails?

You'll get a traceback (not user-mute-able like a warning) with the failure and other reprs will still display. If that's okay, I'll just remove the warning.
@minrk I did those minor fixes. Thanks for putting this together. Feels much better than monkey patching :)
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16198?src=pr&el=h1) Report
> Merging [#16198](https://codecov.io/gh/pandas-dev/pandas/pull/16198?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/20fda2223d5121be3f8204702b5ce1e6037e5b18?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `94.44%`.

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

```diff
@@            Coverage Diff             @@
##           master   #16198      +/-   ##
==========================================
- Coverage   90.86%   90.86%   -0.01%     
==========================================
  Files         162      162              
  Lines       50871    50867       -4     
==========================================
- Hits        46225    46221       -4     
  Misses       4646     4646
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.65% <94.44%> (-0.01%)` | :arrow_down: |
| #single | `40.31% <5.55%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16198?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/16198?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `91.67% <ø> (+0.03%)` | :arrow_up: |
| [pandas/errors/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/16198?src=pr&el=tree#diff-cGFuZGFzL2Vycm9ycy9fX2luaXRfXy5weQ==) | `100% <ø> (ø)` | :arrow_up: |
| [pandas/core/config\_init.py](https://codecov.io/gh/pandas-dev/pandas/pull/16198?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29uZmlnX2luaXQucHk=) | `94.37% <94.44%> (-0.15%)` | :arrow_down: |
| [pandas/core/common.py](https://codecov.io/gh/pandas-dev/pandas/pull/16198?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tbW9uLnB5) | `90.68% <0%> (-0.35%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16198?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/16198?src=pr&el=footer). Last update [20fda22...760892a](https://codecov.io/gh/pandas-dev/pandas/pull/16198?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/16198?src=pr&el=h1) Report
> Merging [#16198](https://codecov.io/gh/pandas-dev/pandas/pull/16198?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/20fda2223d5121be3f8204702b5ce1e6037e5b18?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `94.44%`.

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

```diff
@@            Coverage Diff             @@
##           master   #16198      +/-   ##
==========================================
- Coverage   90.86%   90.86%   -0.01%     
==========================================
  Files         162      162              
  Lines       50871    50867       -4     
==========================================
- Hits        46225    46221       -4     
  Misses       4646     4646
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.65% <94.44%> (-0.01%)` | :arrow_down: |
| #single | `40.31% <5.55%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16198?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/16198?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `91.67% <ø> (+0.03%)` | :arrow_up: |
| [pandas/errors/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/16198?src=pr&el=tree#diff-cGFuZGFzL2Vycm9ycy9fX2luaXRfXy5weQ==) | `100% <ø> (ø)` | :arrow_up: |
| [pandas/core/config\_init.py](https://codecov.io/gh/pandas-dev/pandas/pull/16198?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29uZmlnX2luaXQucHk=) | `94.37% <94.44%> (-0.15%)` | :arrow_down: |
| [pandas/core/common.py](https://codecov.io/gh/pandas-dev/pandas/pull/16198?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tbW9uLnB5) | `90.68% <0%> (-0.35%)` | :arrow_down: |

------

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

Thanks Min!
Thanks, @TomAugspurger!