Skip to content

BUG: SparseSeries from dict inconsistency #16905

Closed
@kernc

Description

@kernc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReshapingConcat, Merge/Join, Stack/Unstack, ExplodeSparseSparse Data Type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions