BUG: Fix/test SparseSeries/SparseDataFrame stack/unstack
State: closed

 - [X] fixes #15045, closes #16614
 - [X] tests added / passed
 - [X] passes ``git diff upstream/master --name-only -- '*.py' | flake8 --diff``
 - [X] whatsnew entry


Labels:
name: Bug
name: Sparse
description: Sparse Data Type

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

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

```diff
@@            Coverage Diff             @@
##           master   #16616      +/-   ##
==========================================
- Coverage   91.26%   91.24%   -0.02%     
==========================================
  Files         163      163              
  Lines       49776    49761      -15     
==========================================
- Hits        45426    45405      -21     
- Misses       4350     4356       +6
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.04% <94.44%> (ø)` | :arrow_up: |
| #single | `40.33% <42.59%> (-0.02%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16616?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/16616?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `95.29% <100%> (+0.02%)` | :arrow_up: |
| [pandas/core/reshape/reshape.py](https://codecov.io/gh/pandas-dev/pandas/pull/16616?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9yZXNoYXBlLnB5) | `99.27% <100%> (-0.02%)` | :arrow_down: |
| [pandas/core/internals.py](https://codecov.io/gh/pandas-dev/pandas/pull/16616?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzLnB5) | `94.37% <92.3%> (+0.08%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/16616?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/accessor.py](https://codecov.io/gh/pandas-dev/pandas/pull/16616?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYWNjZXNzb3IucHk=) | `93.65% <0%> (-6.35%)` | :arrow_down: |
| [pandas/core/tools/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/16616?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvdG9vbHMvZGF0ZXRpbWVzLnB5) | `83.79% <0%> (-1.42%)` | :arrow_down: |
| [pandas/core/indexes/interval.py](https://codecov.io/gh/pandas-dev/pandas/pull/16616?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9pbnRlcnZhbC5weQ==) | `92.85% <0%> (-0.72%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/16616?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.73% <0%> (-0.15%)` | :arrow_down: |
| [pandas/core/indexes/multi.py](https://codecov.io/gh/pandas-dev/pandas/pull/16616?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9tdWx0aS5weQ==) | `96.9% <0%> (ø)` | :arrow_up: |
| [pandas/io/excel.py](https://codecov.io/gh/pandas-dev/pandas/pull/16616?src=pr&el=tree#diff-cGFuZGFzL2lvL2V4Y2VsLnB5) | `80.37% <0%> (ø)` | :arrow_up: |
| ... and [16 more](https://codecov.io/gh/pandas-dev/pandas/pull/16616?src=pr&el=tree-more) | |

------

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

can you rebase / update according to comments
is this comment addressed: https://github.com/pandas-dev/pandas/issues/15045#issuecomment-270276532 (ok to raise / push off to another issue as well).
actually can you add a mini reshaping section to sparse.rst and put a pointer in the whatsnew?
> is this comment addressed: #15045 (comment) 

It is _not_ addressed (nor touched). Stacking Series acts as if the fill value is NaN.

> actually can you add a mini reshaping section to sparse.rst

Added. What would you have me put into it?
this generally looks ok, can you rebase and i'll give a once over again.
You sure the `sparse.reshaping` docs section is OK? I was leaning towards removing it as methods on sparse objects should generally produce equivalent results to methods on their super counterparts, with any exceptions in fact being bugs.
> You sure the sparse.reshaping docs section is OK? I was leaning towards removing it as methods on sparse objects should generally produce equivalent results to methods on their super counterparts, with any exceptions in fact being bugs.

uh, ok to remove. I hadn't really reviewed this much recently.
Rebased.
Hmm, the appveyor failure looks entirely unrelated https://ci.appveyor.com/project/pandas-dev/pandas/build/1.0.4825/job/4kpjb91d5bhe0ier#L1215

@jreback have you seen that before?
> entirely unrelated

My god, that code! Thank god it broke!
@TomAugspurger yeah let's make an issue for that 'unrelated code'. no idea what's going on there.
thanks @kernc always appreciate the nice PRs!