Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SparseSeries.unstack() raises error #16614

Closed
kernc opened this issue Jun 6, 2017 · 1 comment · Fixed by #16616
Closed

SparseSeries.unstack() raises error #16614

kernc opened this issue Jun 6, 2017 · 1 comment · Fixed by #16616
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode Sparse Sparse Data Type
Milestone

Comments

@kernc
Copy link
Contributor

kernc commented Jun 6, 2017

Code Sample, a copy-pastable example if possible

>>> s = pd.Series([1, 2], index=pd.MultiIndex.from_tuples([(0, 0), (1, 2)]))
>>> s
0  0    1
1  2    2
dtype: int64

>>> s.unstack()
     0    2
0  1.0  NaN
1  NaN  2.0

>>> s.to_sparse()
0  0    1
1  2    2
dtype: int64
BlockIndex
Block locations: array([0], dtype=int32)
Block lengths: array([2], dtype=int32

>>> s.to_sparse().unstack()
---------------------------------------------------------------------------
TypeError: expected dimension <= 1 data

Problem description

Unstacking a SparseSeries — i.e. one with a two-level index that should neatly expand into a SparseDataFrame — doesn't work, errors.

Expected Output

>>> s.to_sparse().unstack()
     0    2
0  1.0  NaN
1  NaN  2.0

>>> s.to_sparse().unstack().__class__
pandas.core.sparse.frame.SparseDataFrame

Output of pd.show_versions()

0.21.0.dev+91.g2aafce4
@jreback jreback added Bug Difficulty Advanced Reshaping Concat, Merge/Join, Stack/Unstack, Explode Sparse Sparse Data Type labels Jun 6, 2017
@jreback jreback added this to the Next Major Release milestone Jun 6, 2017
@jreback
Copy link
Contributor

jreback commented Jun 6, 2017

hmm thought we had an issue for this. but yes this should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode Sparse Sparse Data Type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants