ENH: sparse astype now supports int64 and bool #13900

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants
Member

sinhrks commented Aug 4, 2016 edited

  • split from #13849
  • tests added / passed
  • passes git diff upstream/master | flake8 --diff
  • whatsnew entry

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 ENH: sparse astype now supports int64 and bool
1c669ad

sinhrks added this to the 0.19.0 milestone Aug 4, 2016

sinhrks referenced this pull request Aug 4, 2016

Merged

ENH: Sparse int64 and bool dtype support enhancement #13849

4 of 4 tasks complete

codecov-io commented Aug 4, 2016 edited

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

Contributor

jreback commented Aug 4, 2016

lgtm, is this dependent on anything or standalone?

Member

sinhrks commented Aug 4, 2016

thx for the review. it's independent.

jreback closed this in 2beab41 Aug 4, 2016

Contributor

jreback commented Aug 4, 2016

thanks!

sinhrks deleted the sinhrks:sparse_astype branch Aug 4, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment