BUG: Ensure .astype doesn't use PandasArray
State: closed

On 0.24.0rc1, it's possible to end up with a PandasArray in internals.

```python
In [8]: ser = pd.Series([1, 2])

In [9]: ser.astype(ser.array.dtype)._data.blocks[0]
Out[9]: ExtensionBlock: 2 dtype: int64
```


Labels:
name: Bug
name: Dtype Conversions
description: Unexpected or buggy dtype conversions
name: ExtensionArray
description: Extending pandas with custom dtypes or arrays.

Comments:
Subclasses overriding Block._astype get the sanitized version as well,
which is arguably what we want.

On Mon, Jan 21, 2019 at 3:04 PM Jeff Reback <notifications@github.com>
wrote:

> *@jreback* commented on this pull request.
> ------------------------------
>
> In pandas/core/internals/blocks.py
> <https://github.com/pandas-dev/pandas/pull/24866#discussion_r249578670>:
>
> > @@ -530,6 +530,10 @@ def f(m, v, i):
>
>          return self.split_and_operate(None, f, False)
>
>
>
>      def astype(self, dtype, copy=False, errors='raise', values=None, **kwargs):
>
> +        dtype = pandas_dtype(dtype)
>
>
> i don’t want to put this clause where the existing is?
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/24866#pullrequestreview-194761096>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABQHIqfSCJx3q0PFLshrku91aZL-rkdwks5vFit2gaJpZM4aLZlp>
> .
>

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24866?src=pr&el=h1) Report
> Merging [#24866](https://codecov.io/gh/pandas-dev/pandas/pull/24866?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/a49be7f4ea4773af5b801ebd9504a20e5b40b245?src=pr&el=desc) will **decrease** coverage by `49.5%`.
> The diff coverage is `66.66%`.

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

```diff
@@             Coverage Diff             @@
##           master   #24866       +/-   ##
===========================================
- Coverage   92.39%   42.88%   -49.51%     
===========================================
  Files         166      166               
  Lines       52412    52414        +2     
===========================================
- Hits        48424    22479    -25945     
- Misses       3988    29935    +25947
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `?` | |
| #single | `42.88% <66.66%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24866?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/internals/blocks.py](https://codecov.io/gh/pandas-dev/pandas/pull/24866/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzL2Jsb2Nrcy5weQ==) | `52.25% <66.66%> (-42.01%)` | :arrow_down: |
| [pandas/io/formats/latex.py](https://codecov.io/gh/pandas-dev/pandas/pull/24866/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvbGF0ZXgucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/24866/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/sas/sas\_constants.py](https://codecov.io/gh/pandas-dev/pandas/pull/24866/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfY29uc3RhbnRzLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/plotting.py](https://codecov.io/gh/pandas-dev/pandas/pull/24866/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvcGxvdHRpbmcucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/24866/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvY29udmVydGVyLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/formats/html.py](https://codecov.io/gh/pandas-dev/pandas/pull/24866/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvaHRtbC5weQ==) | `0% <0%> (-99.35%)` | :arrow_down: |
| [pandas/core/groupby/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/24866/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9jYXRlZ29yaWNhbC5weQ==) | `0% <0%> (-95.46%)` | :arrow_down: |
| [pandas/io/sas/sas7bdat.py](https://codecov.io/gh/pandas-dev/pandas/pull/24866/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXM3YmRhdC5weQ==) | `0% <0%> (-91.17%)` | :arrow_down: |
| [pandas/io/sas/sas\_xport.py](https://codecov.io/gh/pandas-dev/pandas/pull/24866/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfeHBvcnQucHk=) | `0% <0%> (-90.15%)` | :arrow_down: |
| ... and [124 more](https://codecov.io/gh/pandas-dev/pandas/pull/24866/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24866?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/24866?src=pr&el=footer). Last update [a49be7f...548377f](https://codecov.io/gh/pandas-dev/pandas/pull/24866?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/24866?src=pr&el=h1) Report
> Merging [#24866](https://codecov.io/gh/pandas-dev/pandas/pull/24866?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/48ea04fe5d3ba9b618152ae83aef703dbbb2c3f4?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #24866      +/-   ##
==========================================
- Coverage   91.98%   91.97%   -0.02%     
==========================================
  Files         175      175              
  Lines       52372    52369       -3     
==========================================
- Hits        48172    48164       -8     
- Misses       4200     4205       +5
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.52% <100%> (-0.01%)` | :arrow_down: |
| #single | `40.69% <50%> (-0.15%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24866?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/internals/blocks.py](https://codecov.io/gh/pandas-dev/pandas/pull/24866/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzL2Jsb2Nrcy5weQ==) | `94.07% <100%> (-0.02%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/24866/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/24866/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.9% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/24866/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `90.61% <0%> (-0.11%)` | :arrow_down: |

------

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

All green.

I'm a bit concerned that this is the wrong place to fix the issue. We could alternatively put this check in `make_block` so that if a PandasArray or PandasDtype is there, the the array / dtype is converted to a NumPy version before proceeding...
Trying to move it to `make_block`.
needs a retest, can you merge master
merged master; lets see
thanks @TomAugspurger