def stack_sparse_frame(frame):
 lengths = [s.sp_index.npoints for (_, s) in compat.iteritems(frame)]
 nobs = sum(lengths)
 minor_labels = np.repeat(np.arange(len(frame.columns)), lengths)
 inds_to_concat = []
 vals_to_concat = []
 for (_, series) in compat.iteritems(frame):
  if (not np.isnan(series.fill_value)):
   raise TypeError('This routine assumes NaN fill value')
  int_index = series.sp_index.to_int_index()
  inds_to_concat.append(int_index.indices)
  vals_to_concat.append(series.sp_values)
 major_labels = np.concatenate(inds_to_concat)
 stacked_values = np.concatenate(vals_to_concat)
 index = MultiIndex(levels=[frame.index, frame.columns], labels=[major_labels, minor_labels], verify_integrity=False)
 lp = DataFrame(stacked_values.reshape((nobs, 1)), index=index, columns=['foo'])
 return lp.sort_index(level=0)

def stack_sparse_frame ( frame ) : lengths = [ s . sp_index . npoints for ( _ , s ) in compat . iteritems ( frame ) ] nobs = sum ( lengths ) minor_labels = np . repeat ( np . arange ( len ( frame . columns ) ) , lengths ) inds_to_concat = [ ] vals_to_concat = [ ] for ( _ , series ) in compat . iteritems ( frame ) : if ( not np . isnan ( series . fill_value ) ) : raise TypeError ( 'This routine assumes NaN fill value' ) int_index = series . sp_index . to_int_index ( ) inds_to_concat . append ( int_index . indices ) vals_to_concat . append ( series . sp_values ) major_labels = np . concatenate ( inds_to_concat ) stacked_values = np . concatenate ( vals_to_concat ) index = MultiIndex ( levels = [ frame . index , frame . columns ] , labels = [ major_labels , minor_labels ] , verify_integrity = False ) lp = DataFrame ( stacked_values . reshape ( ( nobs , 1 ) ) , index = index , columns = [ 'foo' ] ) return lp . sort_index ( level = 0 )
only makes sense when fill_value is nan .