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

ENH: sparse astype now supports int64 and bool #13900

Closed
wants to merge 1 commit into from

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Aug 4, 2016

SparseXXX now support astype other than float64 dtype. It raises ValueError when its sp_values or fill_value cannot be converted to specified dtype.

s = pd.SparseSeries([1., 0., 2., 0.], fill_value=0)
s.astype(np.int64)
#0    1
#1    0
#2    2
#3    0
# dtype: int64
# BlockIndex
# Block locations: array([0, 2], dtype=int32)
# Block lengths: array([1, 1], dtype=int32)

pd.SparseSeries([1, np.nan, 2, np.nan]).astype(np.int64)
# ValueError: unable to coerce current fill_value nan to int64 dtype

Also, fill_value setter now checks input value dtype and raises ValueError if value cannot be stored to current dtype.

s = pd.SparseSeries([1, 0, 2, 0], fill_value=0, dtype=np.int64)
s.fill_value = 2
s
#0    1
#1    2
#2    2
#3    2
# dtype: int64
# BlockIndex
# Block locations: array([0, 2], dtype=int32)
# Block lengths: array([1, 1], dtype=int32)

s.fill_value = np.nan
# ValueError: unable to set fill_value nan to int64 dtype

@sinhrks sinhrks added Enhancement Dtype Conversions Unexpected or buggy dtype conversions Sparse Sparse Data Type labels Aug 4, 2016
@sinhrks sinhrks added this to the 0.19.0 milestone Aug 4, 2016
@codecov-io
Copy link

codecov-io commented Aug 4, 2016

Current coverage is 85.29% (diff: 100%)

Merging #13900 into master will increase coverage by <.01%

@@             master     #13900   diff @@
==========================================
  Files           139        139          
  Lines         50057      50077    +20   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          42692      42712    +20   
  Misses         7365       7365          
  Partials          0          0          

Powered by Codecov. Last update 45d54d0...1c669ad

@jreback
Copy link
Contributor

jreback commented Aug 4, 2016

lgtm, is this dependent on anything or standalone?

@sinhrks
Copy link
Member Author

sinhrks commented Aug 4, 2016

thx for the review. it's independent.

@jreback jreback closed this in 2beab41 Aug 4, 2016
@jreback
Copy link
Contributor

jreback commented Aug 4, 2016

thanks!

@sinhrks sinhrks deleted the sparse_astype branch August 4, 2016 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Enhancement Sparse Sparse Data Type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants