SparseSeries.unstack() raises error · Issue #16614 · pandas-dev/pandas (original) (raw)
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