def stack_sparse_frame(frame):
lengths = [s.sp_index.npoints for _, s in frame.items()]<EOL>nobs = sum(lengths)<EOL>minor_codes = np.repeat(np.arange(len(frame.columns)), lengths)<EOL>inds_to_concat = []<EOL>vals_to_concat = []<EOL>for _, series in frame.items():<EOL><INDENT>if not np.isnan(series.fill_value):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>int_index = series.sp_index.to_int_index()<EOL>inds_to_concat.append(int_index.indices)<EOL>vals_to_concat.append(series.sp_values)<EOL><DEDENT>major_codes = np.concatenate(inds_to_concat)<EOL>stacked_values = np.concatenate(vals_to_concat)<EOL>index = MultiIndex(levels=[frame.index, frame.columns],<EOL>codes=[major_codes, minor_codes],<EOL>verify_integrity=False)<EOL>lp = DataFrame(stacked_values.reshape((nobs, <NUM_LIT:1>)), index=index,<EOL>columns=['<STR_LIT:foo>'])<EOL>return lp.sort_index(level=<NUM_LIT:0>)<EOL>
Only makes sense when fill_value is NaN