BUG: multi-type SparseDataFrame fixes and improvements
State: closed

- [X] 1 tests added / passed
- [X] passes `git diff upstream/master | flake8 --diff`
- [x] whatsnew entry

Types were incorrectly determined when slicing SparseDataFrames with
multiple dtypes (such as float and object) into SparseSeries.

``` python
import pandas as pd
sdf = pd.SparseDataFrame([[1, 2, 'a'], [4, 5, 'b']])
sdf.iloc[[0]]  # OK
sdf.iloc[0]  # ValueError: could not convert string to float: 'a'
```

No existing issue covers this.


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

Comments:
## [Current coverage](https://codecov.io/gh/pydata/pandas/pull/13917?src=pr) is 85.30% (diff: 100%)

> Merging [#13917](https://codecov.io/gh/pydata/pandas/pull/13917?src=pr) into [master](https://codecov.io/gh/pydata/pandas/branch/master?src=pr) will not change coverage

``` diff
@@             master     #13917   diff @@
==========================================
  Files           139        139          
  Lines         50157      50157          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
  Hits          42785      42785          
  Misses         7372       7372          
  Partials          0          0          
```

> Powered by [Codecov](https://codecov.io?src=pr). Last update [b7abef4...8c7d1ea](https://codecov.io/gh/pydata/pandas/compare/b7abef4949fb1ba7fd1004feba4f47ace7004282...8c7d1ea7660bbf1e9351239abf39ac6c7a30a216?src=pr)

@sinhrks 

as sparse mainly supports `float64`, adding more tests for mixed dtype is appreciated (maybe in the same file as separate class).

I used numpy's find_common_type instead of that local function, this changed a test (`test_block_internals.py`), see if that numpy behaviour is desired. 

Another (maybe non-minor) change is the default parameter in `sparse/array.py`, but that didn't seem to really break anything. 

I also added some new tests as suggested, but don't feel confident in adding the proposed pandas alternative to the numpy find_common_type - my knowledge of pandas dtypes isn't really great. It would likely be similar to `_interleaved_dtype` in `core/internals.py` right?

can u also add tests to check normal `SparseArray` and its dtypes (related to the default change)?

current default (`float64`) is because it doesn't fully support `int` and `bool`, should be solved by #13849.

It turns out this PR works without the default argument change, I was too hasty to change it. Your PR fixes that better, so I reverted the change. 

Common type discovery moved to `types/cast.py:_find_common_type`. I did notice, however, that `types/common.py:_lcd_dtypes` exists (seems to only work with numpy dtypes, but differently than `np.find_common_type`), but changing either implementation to the other broke some things, so I left it as it is. 

yep, need to fix this.

@sstanovnik can you create a new issue for this.

```
[jreback-~/pandas] grin _lcd_dtype pandas
pandas/core/frame.py:
   47 :                                  _lcd_dtypes,
 3705 :                 new_dtype = _lcd_dtypes(this_dtype, other_dtype)
pandas/core/internals.py:
 4438 :     def _lcd_dtype(l):
 4473 :         lcd = _lcd_dtype(counts[IntBlock])
 4489 :         return _lcd_dtype(counts[FloatBlock] + counts[SparseBlock])
pandas/types/common.py:
  389 : def _lcd_dtypes(a_dtype, b_dtype):
```

Opened issue. Moved the tests, added new tests. Found and processed #10364.

lgtm. @sinhrks ?

Thanks for your patience. 

ha! thanks for yours

lgtm, thx @sstanovnik ! `find_common_type` is needed for #13849 also :)

thanks!