BUG: SparseSeries from dict inconsistency · Issue #16905 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

Two (somewhat related) issues:

pd.Series({1: 1}) 1 1 dtype: int64

pd.SparseSeries({1: 1})


AttributeError: 'dict' object has no attribute 'index'

pd.Series({1: 1}, index=[0, 1, 2]) 0 NaN 1 1.0 2 NaN dtype: float64

pd.SparseSeries({1: 1.}, index=[0, 1, 2]) 0 1.0 1
2
dtype: float64 BlockIndex Block locations: array([0], dtype=int32) Block lengths: array([1], dtype=int32)

Problem description

SparseSeries initialization from dict acts too differently from Series'.

Expected Output

pd.SparseSeries({1: 1}) 1 1.0 dtype: float64 BlockIndex Block locations: array([0], dtype=int32) Block lengths: array([1], dtype=int32)

pd.SparseSeries({1: 1.}, index=[0, 1, 2]) 0 NaN 1 1.0 2 NaN dtype: float64 BlockIndex Block locations: array([1], dtype=int32) Block lengths: array([1], dtype=int32)

Output of pd.show_versions()

pandas 0.21.0.dev+223.ga9421af1a