PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/pandas/tests/test_tseries.py

https://github.com/ara818/pandas
Python | 132 lines | 96 code | 33 blank | 3 comment | 1 complexity | 21414f9ad801570fd3c5752d27229104 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. import unittest
  2. import numpy as np
  3. from pandas import Index
  4. from pandas.util.testing import assert_almost_equal
  5. import pandas.util.testing as common
  6. import pandas._tseries as lib
  7. class TestTseriesUtil(unittest.TestCase):
  8. def test_combineFunc(self):
  9. pass
  10. def test_reindex(self):
  11. pass
  12. def test_isnull(self):
  13. pass
  14. def test_groupby(self):
  15. pass
  16. def test_groupby_withnull(self):
  17. pass
  18. def test_merge_indexer(self):
  19. old = Index([1, 5, 10])
  20. new = Index(range(12))
  21. filler = lib.merge_indexer_object(new, old.indexMap)
  22. expect_filler = [-1, 0, -1, -1, -1, 1, -1, -1, -1, -1, 2, -1]
  23. self.assert_(np.array_equal(filler, expect_filler))
  24. # corner case
  25. old = Index([1, 4])
  26. new = Index(range(5, 10))
  27. filler = lib.merge_indexer_object(new, old.indexMap)
  28. expect_filler = [-1, -1, -1, -1, -1]
  29. self.assert_(np.array_equal(filler, expect_filler))
  30. def test_backfill(self):
  31. old = Index([1, 5, 10])
  32. new = Index(range(12))
  33. filler = lib.backfill_object(old, new, old.indexMap, new.indexMap)
  34. expect_filler = [0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, -1]
  35. self.assert_(np.array_equal(filler, expect_filler))
  36. # corner case
  37. old = Index([1, 4])
  38. new = Index(range(5, 10))
  39. filler = lib.backfill_object(old, new, old.indexMap, new.indexMap)
  40. expect_filler = [-1, -1, -1, -1, -1]
  41. self.assert_(np.array_equal(filler, expect_filler))
  42. def test_pad(self):
  43. old = Index([1, 5, 10])
  44. new = Index(range(12))
  45. filler = lib.pad_object(old, new, old.indexMap, new.indexMap)
  46. expect_filler = [-1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2]
  47. self.assert_(np.array_equal(filler, expect_filler))
  48. # corner case
  49. old = Index([5, 10])
  50. new = Index(range(5))
  51. filler = lib.pad_object(old, new, old.indexMap, new.indexMap)
  52. expect_filler = [-1, -1, -1, -1, -1]
  53. self.assert_(np.array_equal(filler, expect_filler))
  54. def test_inner_join_indexer():
  55. a = np.array([1, 2, 3, 4, 5], dtype=np.int64)
  56. b = np.array([0, 3, 5, 7, 9], dtype=np.int64)
  57. index, ares, bres = lib.inner_join_indexer_int64(a, b)
  58. index_exp = np.array([3, 5], dtype=np.int64)
  59. assert_almost_equal(index, index_exp)
  60. aexp = np.array([2, 4])
  61. bexp = np.array([1, 2])
  62. assert_almost_equal(ares, aexp)
  63. assert_almost_equal(bres, bexp)
  64. def test_outer_join_indexer():
  65. a = np.array([1, 2, 3, 4, 5], dtype=np.int64)
  66. b = np.array([0, 3, 5, 7, 9], dtype=np.int64)
  67. index, ares, bres = lib.outer_join_indexer_int64(a, b)
  68. index_exp = np.array([0, 1, 2, 3, 4, 5, 7, 9], dtype=np.int64)
  69. assert_almost_equal(index, index_exp)
  70. aexp = np.array([-1, 0, 1, 2, 3, 4, -1, -1], dtype=np.int32)
  71. bexp = np.array([0, -1, -1, 1, -1, 2, 3, 4])
  72. assert_almost_equal(ares, aexp)
  73. assert_almost_equal(bres, bexp)
  74. def test_is_lexsorted():
  75. failure = [
  76. np.array([3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  77. 3, 3,
  78. 3, 3,
  79. 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  80. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
  81. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82. 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  83. 0, 0, 0, 0, 0, 0, 0, 0, 0]),
  84. np.array([30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16,
  85. 15, 14,
  86. 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 30, 29, 28,
  87. 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11,
  88. 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 30, 29, 28, 27, 26, 25,
  89. 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8,
  90. 7, 6, 5, 4, 3, 2, 1, 0, 30, 29, 28, 27, 26, 25, 24, 23, 22,
  91. 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5,
  92. 4, 3, 2, 1, 0])]
  93. assert(not lib.is_lexsorted(failure))
  94. class TestMoments(unittest.TestCase):
  95. pass
  96. if __name__ == '__main__':
  97. import nose
  98. nose.runmodule(argv=[__file__,'-vvs','-x','--pdb', '--pdb-failure'],
  99. exit=False)