BUG: assign doesnt cast SparseDataFrame to DataFrame
State: closed

The problem here is that a SparseDataFrame that calls assign should cast
to a DataFrame mainly because SparseDataFrames are a special case.

- [x] closes #19163
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Indexing
description: Related to indexing on series/frames, not to indexes themselves
name: Dtype Conversions
description: Unexpected or buggy dtype conversions
name: Sparse
description: Sparse Data Type

Comments:
So I updated the PR locally but...

I feel the real problem is inside of SparseArray. 

If you init a SparseArray with False and pass in an index it will assume the dtype is float64 which coerces False to 0.0.

Why does it assume the dtype is float64? Shouldn't it infer it based on infer_dtype_from or something similar?

Thanks!
> If you init a SparseArray with False and pass in an index it will assume the dtype is float64 which coerces False to 0.0.

Can you give an example?
Sure @TomAugspurger 

```python
In [4]: pd.SparseArray(False, index=[1], fill_value=False)
Out[4]: 
[0.0]
Fill: False
IntIndex
Indices: array([], dtype=int32)
```

The line that coerces it is here:

https://github.com/pandas-dev/pandas/blob/master/pandas/core/sparse/array.py#L198

Versus

```python
In [5]: pd.SparseArray(False, fill_value=False)
Out[5]: 
[False]
Fill: False
IntIndex
Indices: array([], dtype=int32)
```

Hello @hexgnu! Thanks for updating the PR.







Cheers ! There are no PEP8 issues in this Pull Request. :beers: 

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

```diff
@@            Coverage Diff             @@
##           master   #19178      +/-   ##
==========================================
+ Coverage   91.58%   91.59%   +<.01%     
==========================================
  Files         150      150              
  Lines       48807    48806       -1     
==========================================
+ Hits        44702    44703       +1     
+ Misses       4105     4103       -2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.96% <100%> (ø)` | :arrow_up: |
| #single | `41.73% <0%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/19178?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/sparse/array.py](https://codecov.io/gh/pandas-dev/pandas/pull/19178/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL2FycmF5LnB5) | `91.38% <100%> (-0.03%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/19178/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `83.85% <0%> (+0.2%)` | :arrow_up: |

------

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

Alright I think I have found the issue. I added some tests and it seems to chooch. Please review and give me any feedback.

Thanks @TomAugspurger and @jreback 
@TomAugspurger I did add a test in pandas/tests/sparse/test_array.py that tests this directly instead of indirectly.
@jreback @TomAugspurger ping. This is now green after fixing a linting error.

Let me know if you would like me to squash any of these commits.
thanks @hexgnu 
great job on sparse fixes! keep em coming!