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

BUG: SparseSeries from dict inconsistency #16905

Closed
kernc opened this issue Jul 13, 2017 · 2 comments · Fixed by #16960
Closed

BUG: SparseSeries from dict inconsistency #16905

kernc opened this issue Jul 13, 2017 · 2 comments · Fixed by #16960
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode Sparse Sparse Data Type
Milestone

Comments

@kernc
Copy link
Contributor

kernc commented Jul 13, 2017

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
@kernc kernc changed the title SparseSeries from dict inconsistency BUG: SparseSeries from dict inconsistency Jul 13, 2017
@jreback
Copy link
Contributor

jreback commented Jul 13, 2017

yep looks like a bug

@jreback jreback added Bug Difficulty Intermediate Reshaping Concat, Merge/Join, Stack/Unstack, Explode Sparse Sparse Data Type labels Jul 13, 2017
@jreback jreback modified the milestones: Next Major Release, 0.21.0 Jul 13, 2017
@metllord
Copy link
Contributor

I think I have a fix for this. I'm testing it now.

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
3 participants