POC: 2D EAs via composition
State: closed

Plenty of kludges and linting errors in here, just want to push it to add composition to the discussion.

Instead of patching existing EAs, this introduces ReshapeableArray which just wraps other EAs, and implements reshape methods.  EAs that _do_ natively support 2D can set a `_allows_2d = True` and avoid being wrapped.

In the process of getting this passing, found a handful of new issues/bugs.  Will try to push fixes for those independently.

Labels:
name: Enhancement
name: ExtensionArray
description: Extending pandas with custom dtypes or arrays.

Comments:
Hello @jbrockmendel! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:

































































There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2019-06-27 15:47:41 UTC
> So high-level, this makes Block.values a ReshapableArray, which is an ExtensionArray implementing the 2-D interface. Then a DataFrame is made up of a collection of Blocks whose values are all reshapable, either by being an ndarray, or an ExtensionArray with _allows_2d = True?

Yes.

> Is this your preferred approach for fixing Block.shape == Block.values.shape going forward?

No, this is my second-best.  First-best would be to require EAs to handle the (1, N) case themselves, so we wouldn't need this extra layer.  But I definitely prefer this to the metaclass approach, which I wasn't able to get working at all (MRO issues)
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/27015?src=pr&el=h1) Report
> Merging [#27015](https://codecov.io/gh/pandas-dev/pandas/pull/27015?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/8ea2d087cda0f40a4e41ce108a32859d51b4d69f?src=pr&el=desc) will **decrease** coverage by `50.09%`.
> The diff coverage is `51.26%`.

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

```diff
@@            Coverage Diff             @@
##           master   #27015      +/-   ##
==========================================
- Coverage   91.99%    41.9%   -50.1%     
==========================================
  Files         180      181       +1     
  Lines       50774    51124     +350     
==========================================
- Hits        46711    21422   -25289     
- Misses       4063    29702   +25639
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `?` | |
| #single | `41.9% <51.26%> (-0.02%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/27015?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexing.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhpbmcucHk=) | `53.64% <ø> (-39.85%)` | :arrow_down: |
| [pandas/core/groupby/ops.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9vcHMucHk=) | `19.67% <0%> (-76.33%)` | :arrow_down: |
| [pandas/core/groupby/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9nZW5lcmljLnB5) | `14.74% <0%> (-74.59%)` | :arrow_down: |
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `38.18% <0%> (-56.03%)` | :arrow_down: |
| [pandas/core/arrays/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2Jhc2UucHk=) | `59.89% <100%> (-39.55%)` | :arrow_down: |
| [pandas/core/dtypes/concat.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2NvbmNhdC5weQ==) | `53.55% <100%> (-43.04%)` | :arrow_down: |
| [pandas/core/arrays/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2NhdGVnb3JpY2FsLnB5) | `42.09% <100%> (-53.84%)` | :arrow_down: |
| [pandas/core/internals/concat.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzL2NvbmNhdC5weQ==) | `72.48% <100%> (-24.01%)` | :arrow_down: |
| [pandas/io/formats/format.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZm9ybWF0LnB5) | `50.63% <100%> (-47.28%)` | :arrow_down: |
| [pandas/core/arrays/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lbGlrZS5weQ==) | `41.49% <100%> (-56.44%)` | :arrow_down: |
| ... and [154 more](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/27015?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/27015?src=pr&el=footer). Last update [8ea2d08...6e4f207](https://codecov.io/gh/pandas-dev/pandas/pull/27015?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/27015?src=pr&el=h1) Report
> Merging [#27015](https://codecov.io/gh/pandas-dev/pandas/pull/27015?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/1452e714bd3484d8da1bc060357e619e9de97c11?src=pr&el=desc) will **decrease** coverage by `50.12%`.
> The diff coverage is `53.89%`.

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

```diff
@@             Coverage Diff             @@
##           master   #27015       +/-   ##
===========================================
- Coverage   92.03%   41.91%   -50.13%     
===========================================
  Files         180      181        +1     
  Lines       50714    51086      +372     
===========================================
- Hits        46675    21412    -25263     
- Misses       4039    29674    +25635
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `?` | |
| #single | `41.91% <53.89%> (+0.04%)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/27015?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexing.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhpbmcucHk=) | `53.64% <ø> (-39.66%)` | :arrow_down: |
| [pandas/core/groupby/ops.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9vcHMucHk=) | `19.67% <0%> (-76.33%)` | :arrow_down: |
| [pandas/core/groupby/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9nZW5lcmljLnB5) | `14.74% <0%> (-74.59%)` | :arrow_down: |
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `38.18% <0%> (-56.03%)` | :arrow_down: |
| [pandas/core/arrays/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2Jhc2UucHk=) | `59.89% <100%> (-39.55%)` | :arrow_down: |
| [pandas/core/dtypes/concat.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2NvbmNhdC5weQ==) | `53.58% <100%> (-43.46%)` | :arrow_down: |
| [pandas/core/arrays/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2NhdGVnb3JpY2FsLnB5) | `42.09% <100%> (-53.84%)` | :arrow_down: |
| [pandas/core/internals/concat.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzL2NvbmNhdC5weQ==) | `73.04% <100%> (-23.81%)` | :arrow_down: |
| [pandas/io/formats/format.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZm9ybWF0LnB5) | `50.63% <100%> (-47.28%)` | :arrow_down: |
| [pandas/core/arrays/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lbGlrZS5weQ==) | `41.36% <100%> (-56.57%)` | :arrow_down: |
| ... and [154 more](https://codecov.io/gh/pandas-dev/pandas/pull/27015/diff?src=pr&el=tree-more) | |

------

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