PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/bench/bench_sparse.py

http://github.com/pydata/pandas
Python | 93 lines | 54 code | 29 blank | 10 comment | 3 complexity | 2fb8ad3bab5e6def3b101399494bcd03 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
  1. import sys
  2. import numpy as np
  3. from pandas import *
  4. import pandas.core.sparse as spm
  5. import pandas.compat as compat
  6. reload(spm)
  7. from pandas.core.sparse import *
  8. N = 10000.
  9. arr1 = np.arange(N)
  10. index = Index(np.arange(N))
  11. off = N // 10
  12. arr1[off: 2 * off] = np.NaN
  13. arr1[4 * off: 5 * off] = np.NaN
  14. arr1[8 * off: 9 * off] = np.NaN
  15. arr2 = np.arange(N)
  16. arr2[3 * off // 2: 2 * off + off // 2] = np.NaN
  17. arr2[8 * off + off // 2: 9 * off + off // 2] = np.NaN
  18. s1 = SparseSeries(arr1, index=index)
  19. s2 = SparseSeries(arr2, index=index)
  20. is1 = SparseSeries(arr1, kind='integer', index=index)
  21. is2 = SparseSeries(arr2, kind='integer', index=index)
  22. s1_dense = s1.to_dense()
  23. s2_dense = s2.to_dense()
  24. if 'linux' in sys.platform:
  25. pth = '/home/wesm/code/pandas/example'
  26. else:
  27. pth = '/Users/wesm/code/pandas/example'
  28. dm = DataFrame.load(pth)
  29. sdf = dm.to_sparse()
  30. def new_data_like(sdf):
  31. new_data = {}
  32. for col, series in compat.iteritems(sdf):
  33. new_data[col] = SparseSeries(np.random.randn(len(series.sp_values)),
  34. index=sdf.index,
  35. sparse_index=series.sp_index,
  36. fill_value=series.fill_value)
  37. return SparseDataFrame(new_data)
  38. # data = {}
  39. # for col, ser in dm.iteritems():
  40. # data[col] = SparseSeries(ser)
  41. dwp = Panel.fromDict({'foo': dm})
  42. # sdf = SparseDataFrame(data)
  43. lp = stack_sparse_frame(sdf)
  44. swp = SparsePanel({'A': sdf})
  45. swp = SparsePanel({'A': sdf,
  46. 'B': sdf,
  47. 'C': sdf,
  48. 'D': sdf})
  49. y = sdf
  50. x = SparsePanel({'x1': sdf + new_data_like(sdf) / 10,
  51. 'x2': sdf + new_data_like(sdf) / 10})
  52. dense_y = sdf
  53. dense_x = x.to_dense()
  54. # import hotshot, hotshot.stats
  55. # prof = hotshot.Profile('test.prof')
  56. # benchtime, stones = prof.runcall(ols, y=y, x=x)
  57. # prof.close()
  58. # stats = hotshot.stats.load('test.prof')
  59. dense_model = ols(y=dense_y, x=dense_x)
  60. import pandas.stats.plm as plm
  61. import pandas.stats.interface as face
  62. reload(plm)
  63. reload(face)
  64. # model = face.ols(y=y, x=x)