@@ -140,7 +140,7 @@ def __new__(cls, data, sparse_index=None, index=None, kind='integer',
140140 values , sparse_index = make_sparse (data , kind = kind ,
141141 fill_value = fill_value )
142142 else :
143- values = data
143+ values = _sanitize_values ( data )
144144 if len (values ) != sparse_index .npoints :
145145 raise AssertionError ("Non array-like type {0} must have"
146146 " the same length as the"
@@ -515,6 +515,33 @@ def _maybe_to_sparse(array):
515515 return array
516516
517517
518+ def _sanitize_values (arr ):
519+ """
520+ return an ndarray for our input,
521+ in a platform independent manner
522+ """
523+
524+ if hasattr (arr , 'values' ):
525+ arr = arr .values
526+ else :
527+
528+ # scalar
529+ if lib .isscalar (arr ):
530+ arr = [arr ]
531+
532+ # ndarray
533+ if isinstance (arr , np .ndarray ):
534+ pass
535+
536+ elif com .is_list_like (arr ) and len (arr ) > 0 :
537+ arr = com ._possibly_convert_platform (arr )
538+
539+ else :
540+ arr = np .asarray (arr )
541+
542+ return arr
543+
544+
518545def make_sparse (arr , kind = 'block' , fill_value = nan ):
519546 """
520547 Convert ndarray to sparse format
@@ -529,13 +556,8 @@ def make_sparse(arr, kind='block', fill_value=nan):
529556 -------
530557 (sparse_values, index) : (ndarray, SparseIndex)
531558 """
532- if hasattr (arr , 'values' ):
533- arr = arr .values
534- else :
535- if lib .isscalar (arr ):
536- arr = [arr ]
537- arr = np .asarray (arr )
538559
560+ arr = _sanitize_values (arr )
539561 length = len (arr )
540562
541563 if np .isnan (fill_value ):
0 commit comments