BUG: astype fill_value for SparseArray.astype
State: closed

I don't think we have a specific issue for this. This is not a fix / change for https://github.com/pandas-dev/pandas/issues/23125

This fixes strange things like

```python
In [1]: import pandas as pd; import numpy as np

In [2]: a = pd.SparseArray([0, 1])

In [3]: a.astype(bool)
Out[3]:
[0, True]
Fill: 0
IntIndex
Indices: array([1], dtype=int32)
```

restoring the behavior of 0.23.x

Labels:
name: Sparse
description: Sparse Data Type

Comments:
Hello @TomAugspurger! Thanks for updating the PR.

 - There are no PEP8 issues in the file [`pandas/core/arrays/sparse.py`](https://github.com/TomAugspurger/pandas/blob/232921b86d6348a1618857e28609b9675b2cffa2/pandas/core/arrays/sparse.py) !

 - There are no PEP8 issues in the file [`pandas/tests/arrays/sparse/test_array.py`](https://github.com/TomAugspurger/pandas/blob/232921b86d6348a1618857e28609b9675b2cffa2/pandas/tests/arrays/sparse/test_array.py) !



##### Comment last updated on November 07, 2018 at 17:12 Hours UTC
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23547?src=pr&el=h1) Report
> Merging [#23547](https://codecov.io/gh/pandas-dev/pandas/pull/23547?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/a092e91f3c6d77c24518dff8fd829a96d26e5007?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/23547/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/23547?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #23547      +/-   ##
==========================================
+ Coverage   92.23%   92.23%   +<.01%     
==========================================
  Files         161      161              
  Lines       51324    51334      +10     
==========================================
+ Hits        47339    47349      +10     
  Misses       3985     3985
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.62% <100%> (ø)` | :arrow_up: |
| #single | `42.32% <73.68%> (+0.02%)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/23547?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/arrays/sparse.py](https://codecov.io/gh/pandas-dev/pandas/pull/23547/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL3NwYXJzZS5weQ==) | `91.82% <100%> (+0.1%)` | :arrow_up: |

------

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

We wouldn't be able to share with IntervalDtype, since the astype there
needs to look at the
actual values to know whether or not it's going to succeed.

I guess we have something similar on `CategoricalDtype` called
`CategoricalDtype.update_dtype`.
Not the best name in the world, but I suppose we should match it (we won't
be able to share code
though).

On Sun, Nov 11, 2018 at 1:24 PM Jeff Reback <notifications@github.com>
wrote:

> *@jreback* commented on this pull request.
> ------------------------------
>
> In pandas/core/arrays/sparse.py
> <https://github.com/pandas-dev/pandas/pull/23547#discussion_r232501033>:
>
> > @@ -284,6 +284,83 @@ def is_dtype(cls, dtype):
>              return True
>          return isinstance(dtype, np.dtype) or dtype == 'Sparse'
>
> +    def astype(self, dtype):
>
> anything with a subtype? so Categorical and Interval?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/23547#discussion_r232501033>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABQHIve4UpFry1GK6cM6TErGcZfkwJFjks5uuHmAgaJpZM4YS1QX>
> .
>

ok that sounds good